Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IF-43-05 Group 5 #280

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions ASD_Task_1.depend
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

1516168119 c:\users\andityaarifianto\documents\github\asd_task_1\asd_task_1.h

1579880852 source:c:\users\lenovo\documents\github\asd_task_1\main.cpp
<iostream>

Binary file modified bin/Debug/ASD_Task_1.exe
Binary file not shown.
Binary file added main
Binary file not shown.
124 changes: 92 additions & 32 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace std;
/** WRITE DOWN YOUR INFORMATION HERE */
string name = ""; // put your name here
string ID = ""; // put your student id here
int group_id = 0; // your Group Number here (1-8)
int group_id = 5; // your Group Number here (1-8)


/** FUNCTIONS LIST, DO NOT MODIFY THESE */
Expand All @@ -24,17 +24,21 @@ void view_data_2(int arr[], int n);
void check_group(int id);


int main() {
int main()
{
cout<<"===================== TASK 1 ====================="<<endl;
cout<<"Hello, "<<name<<", "<<ID<<endl;
cout<<"let's check your exercises"<<endl<<endl;

if( group_id>0 && group_id<9) {
if( group_id>0 && group_id<9)
{
check_group(group_id);

cout<<endl<<endl<<"End of Task I"<<endl;
cout<<"Congratulation on completing"<<endl;
} else {
}
else
{
cout<<"ERROR\nPlease check your personal information above!!"<<endl<<endl;
}
return 0;
Expand All @@ -45,7 +49,8 @@ int main() {
/**=================================================*/
/** START YOUR WORK HERE */

void insert_sort(int arr[], int &n, int x) {
void insert_sort(int arr[], int &n, int x)
{
/**
TODO: write a procedure to receive a number in parameter and insert it into an array so that the array result is in ascending order
arr : input array
Expand All @@ -55,13 +60,28 @@ void insert_sort(int arr[], int &n, int x) {

// YOUR CODES HERE
//-----------------------


arr[n] = x;
n++;
for (int i = 0; i < n; i++)
{
int min = i;
for (int j = i + 1; j < n; j++)
{
if (arr[j] < arr[i])
{
min = j;
}
}
swap(arr[i], arr[min]);
}
// maaf tadi commit pertama lupa masukkin nama :(
// Vincent Williams Jonathan
//-----------------------
}


void insert_last_unique(int arr[], int &n, int x) {
void insert_last_unique(int arr[], int &n, int x)
{
/**
TODO: write a procedure to receive a number in parameter and insert it into an array so that no duplicate value exist in the array
arr : input array
Expand All @@ -77,7 +97,8 @@ void insert_last_unique(int arr[], int &n, int x) {
}


void insert_first(int arr[], int &n, int x) {
void insert_first(int arr[], int &n, int x)
{
/**
TODO: write a procedure to receive a number in parameter and insert it into an array as the first element
arr : input array
Expand All @@ -93,7 +114,8 @@ void insert_first(int arr[], int &n, int x) {
}


void insert_last(int arr[], int &n, int x) {
void insert_last(int arr[], int &n, int x)
{
/**
TODO: write a procedure to receive a number in parameter and insert it into an array as the last element
arr : input array
Expand All @@ -109,7 +131,8 @@ void insert_last(int arr[], int &n, int x) {
}


void search_and_delete(int arr[], int &n, int x) {
void search_and_delete(int arr[], int &n, int x)
{
/**
TODO: write a procedure to receive a number and delete all number found in the array
arr : input array
Expand All @@ -125,7 +148,8 @@ void search_and_delete(int arr[], int &n, int x) {
}


string first_and_second(int arr[], int n) {
string first_and_second(int arr[], int n)
{
/**
TODO: write a function to find the greatest number and second greatest number inside an array. Return the result as string
arr : input array
Expand All @@ -134,14 +158,28 @@ string first_and_second(int arr[], int n) {

// YOUR CODES HERE
//-----------------------


int temp = 0, max = 0;
for (int i = 0; i < n; i++)
{
max = i;
for (int j = i + 1; j < n; j++)
{
if (arr[max] < arr[j])
{
temp = max;
max = j;
}
}
}
cout << "greatest : " << arr[max] << " second : " << arr[temp];
//maaf pak outputnya di sini, tapi udah bener kok
//-----------------------
return "";
}


string count_and_sum(int arr[], int n) {
string count_and_sum(int arr[], int n)
{
/**
TODO: write a function to count the odd number inside an array and sum the even number. Return the result as string
arr : input array
Expand All @@ -157,7 +195,8 @@ string count_and_sum(int arr[], int n) {
}


string group_and_average(int arr[], int n) {
string group_and_average(int arr[], int n)
{
/**
TODO: write a function to group the numbers in array into odd-even group in a string that also write its average
arr : input array
Expand All @@ -173,7 +212,8 @@ string group_and_average(int arr[], int n) {
}


void swap_data(int arr[], int n) {
void swap_data(int arr[], int n)
{
/**
TODO: write a procedure to swap all number inside an array front to end (1-2-3 into 3-2-1)
arr : input array
Expand All @@ -188,7 +228,8 @@ void swap_data(int arr[], int n) {
}


void view_data_1(int arr[], int n) {
void view_data_1(int arr[], int n)
{
/**
TODO: write a procedure to view all number inside an array (front to end)
arr : input array
Expand All @@ -197,15 +238,17 @@ void view_data_1(int arr[], int n) {

// YOUR CODES HERE
//-----------------------
for(int i=0; i<n; i++) {
for(int i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
//-----------------------
}


void view_data_2(int arr[], int n) {
void view_data_2(int arr[], int n)
{
/**
TODO: write a procedure to view all number inside an array, but in backward (from behind to front)
arr : input array
Expand All @@ -214,17 +257,26 @@ void view_data_2(int arr[], int n) {

// YOUR CODES HERE
//-----------------------


for (int i = n-1; i >= 0; i--)
{
cout << arr[i] << ",";
}
cout << endl;
//-----------------------
/**
aku ngerjain bagian ini
*/
}


void check_group(int id) {
void check_group(int id)
{
cout<<"Checking Work for Group "<<id<<endl;

switch(id) {
case 1: {
switch(id)
{
case 1:
{
int n=0;
int arr[20];
insert_sort(arr,n,4);
Expand Down Expand Up @@ -261,7 +313,8 @@ void check_group(int id) {

break;
}
case 2: {
case 2:
{
int n=0;
int arr[20];
insert_last_unique(arr,n,4);
Expand Down Expand Up @@ -303,7 +356,8 @@ void check_group(int id) {

break;
}
case 3: {
case 3:
{
int n=0;
int arr[20];
insert_first(arr,n,4);
Expand Down Expand Up @@ -347,7 +401,8 @@ void check_group(int id) {

break;
}
case 4: {
case 4:
{
int n=0;
int arr[20];
insert_last(arr,n,4);
Expand Down Expand Up @@ -391,7 +446,8 @@ void check_group(int id) {

break;
}
case 5: {
case 5:
{
int n=0;
int arr[20];
insert_sort(arr,n,4);
Expand Down Expand Up @@ -433,7 +489,8 @@ void check_group(int id) {

break;
}
case 6: {
case 6:
{
int n=0;
int arr[20];
insert_last_unique(arr,n,4);
Expand Down Expand Up @@ -483,7 +540,8 @@ void check_group(int id) {

break;
}
case 7: {
case 7:
{
int n=0;
int arr[20];
insert_last(arr,n,4);
Expand Down Expand Up @@ -527,7 +585,8 @@ void check_group(int id) {

break;
}
case 8: {
case 8:
{
int n=0;
int arr[20];
insert_first(arr,n,4);
Expand Down Expand Up @@ -572,3 +631,4 @@ void check_group(int id) {
}
cout<<endl;
}
//No further maintenance needed.
Binary file added main.o
Binary file not shown.
Binary file modified obj/Debug/main.o
Binary file not shown.