SUBMISSION+HAN+CHENG

Enter your submission for both Challenges here. Make sure you label your solutions clearly.

Challenge 1: code format="cpp" //Challenge 1 by Lee Han Cheng 3O211 using namespace std;
 * 1) include

int main { int Tables[10];//array int i;//loop counter int max, min;//1. and 2. int total=0, avg;//3. int choice; int n, nAppear=0;//4.

for (i=0;i<10;i++) { //get array number cout << "Enter element " << i << ": \n"; cin >> Tables[i]; }

//init max and min max = Tables[0]; min = Tables[0];

for (i=0;i<10;i++) { //check if larger than max or smaller than min if (Tables[i] < min) { min = Tables[i]; } else if (Tables[i] > max) { max = Tables[i]; }       //get total for the average part total += Tables[i]; }

//find average avg = total/10;

//give user choice to choose cout << "Please enter 1--Find max\n2--Find min\n3--Find average\n"; cout << "4--Find the number of time a number appears in the array\n"; cout << "5--Reverse the order of an array\n";

//get thier choice of display cin >> choice;

//execute according to different choices switch (choice) { case 1: cout << "Max value: " << max << endl; break; case 2: cout << "Min value: " << min << endl; break; case 3: cout << "Average: " << avg << endl; break; case 4: cout << "Enter the number: \n"; cin >> n;               for (i=0;i<10;i++) { if (n == Tables[i]) { nAppear++; //number of times number appear increases //if the number appears in the array }               }                cout << "Number " << n << " appears " << nAppear << " times. \n"; break; case 5: cout << "The reversed order is: \t"; for (i=9;i>=0;i--) {//decrease counter to get array from the back cout << Tables[i] << " "; }               cout << endl; break; default: cout << "Invalid number\n"; }

//end system("Pause"); return 0; } code

Challenge 2:

code format="cpp" //Challenge 2 by Lee Han Cheng from 3O211 using namespace std;
 * 1) include

char toUpper(char ch) { int intTemp; char charTemp;

if (int(ch)>=65 && int(ch)<=90) {//if uppercase return return ch; }

intTemp = int(ch)-32;//lowercase to upper according to ASCII charTemp = char(intTemp);//change back to char type

return charTemp; }

int main { char Allocations[5] = {'z','v','E','a','b'}; int i;//loop counter char temp;//storage for bubble sort bool swapped;//check whether all swapped correctly

//convert to upper using the toUpper function for (i=0;i<5;i++) { Allocations[i] = toUpper(Allocations[i]); }

//bubble sort do { swapped = false; for (i=0;i<4;i++) { if (Allocations[i]>Allocations[i+1]) {//not in alphabetical order //swap temp = Allocations[i]; Allocations[i] = Allocations[i+1]; Allocations[i+1] = temp; //loop continues swapped = true; }       }    } while (swapped);//ends when all in alphabetical order

//print out cout << "Letters after arranged in alphabetical order and in uppercase:\t";

for (i=0;i<5;i++) { cout << Allocations[i] << " "; }

//end cout << endl;

system("Pause"); return 0;

} code