9a 10.5 Learn by Doing Exercises p 247 10 pts #1 Submit: code & run #include using namespace std; const int NUMSTUDENTS = 10; const int NUMGRA = 5; int main() { float scoreArray[NUMSTUDENTS] = { 0.0 }; string gradeArray[NUMSTUDENTS]; int numGradeArray[NUMGRA] = { 0 }; float avg = 0.0; for (int i = 0; i < NUMSTUDENTS; i++) { cout << "Enter score " << i + 1 << ": " << endl; cin >> scoreArray[i]; avg += scoreArray[i]; } for (int n = 0; n < NUMSTUDENTS; n++) { if (scoreArray[n] >= 92) { gradeArray[n] = "A"; numGradeArray[0] += 1; } else if (scoreArray[n] >= 84) { gradeArray[n] = "B"; numGradeArray[1] += 1; } else if (scoreArray[n] >= 75) { gradeArray[n] = "C"; numGradeArray[2] += 1; } else if (scoreArray[n] >= 65) { gradeArray[n] = "D"; numGradeArray[3] += 1; } else { gradeArray[n] = "F"; numGradeArray[4] += 1; } } for (int x = 0; x < 10; x++) { cout << scoreArray[x] << " = " << gradeArray[x] << endl; } cout << "Average is: " << avg / 10 << endl; cout << "The amount of people that got an A, B, C, D, and F in order are listed below: " << endl; for (int y = 0; y < 5; y++) { cout << numGradeArray[y] << endl; } } OUTPUT: Enter score 1: 65 Enter score 2: 87 Enter score 3: 98 Enter score 4: 98 Enter score 5: 98 Enter score 6: 23 Enter score 7: 12 Enter score 8: 65 Enter score 9: 78 Enter score 10: 89 65 = D 87 = B 98 = A 98 = A 98 = A 23 = F 12 = F 65 = D 78 = C 89 = B Average is: 71.3 The amount of people that got an A, B, C, D, and F in order are listed below: 3 2 1 2 2 C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 13084) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . . -------------------------------------------------------------------------------------------------------------- 9b 10.6 Learn by Doing Exercises p 253 Break into 3 files: the main() file, the functions .cpp file and the .h file. 10 pts #1 Submit: code & runs File 1: (Containing Main) // LAB5 - ANSARI.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "CommonInfo.h" int main() { float scoreArray[NUMSTUDENTS] = { 0.0 }; string gradeArray[NUMSTUDENTS]; int numGradeArray[NUMGRA] = { 0 }; float avg = 0.0; readInput(scoreArray, avg); calcGrade(scoreArray, gradeArray, numGradeArray); printInfo(scoreArray, gradeArray, numGradeArray, avg); } File 2: (Containing Functions) #include "CommonInfo.h" void readInput(float arr1[], float& avg) { for (int i = 0; i < NUMSTUDENTS; i++) { cout << "Enter score " << i + 1 << ": " << endl; cin >> arr1[i]; avg += arr1[i]; } } void calcGrade(float arr1[], string arr2[], int arr3[]) { for (int n = 0; n < NUMSTUDENTS; n++) { if (arr1[n] >= 92) { arr2[n] = "A"; arr3[0] += 1; } else if (arr1[n] >= 84) { arr2[n] = "B"; arr3[1] += 1; } else if (arr1[n] >= 75) { arr2[n] = "C"; arr3[2] += 1; } else if (arr1[n] >= 65) { arr2[n] = "D"; arr3[3] += 1; } else { arr2[n] = "F"; arr3[4] += 1; } } } void printInfo(float arr1[], string arr2[], int arr3[], float& avg) { for (int x = 0; x < 10; x++) { cout << arr1[x] << " = " << arr2[x] << endl; } cout << "Students that got an A: " << arr3[0] << endl; cout << "Students that got an B: " << arr3[1] << endl; cout << "Students that got an C: " << arr3[2] << endl; cout << "Students that got an D: " << arr3[3] << endl; cout << "Students that got an F: " << arr3[4] << endl; cout << "Average is: " << avg / 10; } File 3: (containing Header file) #include using namespace std; const int NUMSTUDENTS = 10; const int NUMGRA = 5; void readInput(float[], float& avg); void calcGrade(float[], string[], int[]); void printInfo(float[], string[], int[], float& avg); OUTPUT: Enter score 1: 12 Enter score 2: 23 Enter score 3: 4 Enter score 4: 56 Enter score 5: 76 Enter score 6: 587 Enter score 7: 89 Enter score 8: 67 Enter score 9: 90 Enter score 10: 57 12 = F 23 = F 4 = F 56 = F 76 = C 587 = A 89 = B 67 = D 90 = B 57 = F Students that got an A: 1 Students that got an B: 2 Students that got an C: 1 Students that got an D: 1 Students that got an F: 5 Average is: 106.1 C:\Users\ansar\source\repos\LAB5 - Ansari - FIXED\Debug\LAB5 - Ansari - FIXED.exe (process 19884) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . . ------------------------------------------------------------------------------------------------------------------- 10a 10.7 Learn by Doing Exercises p 260 Break into at least 3 files as in 9b. 10 pts #2 Submit: code & runs CODE: FILE 1 (Main): // CST116F2021-Lab5.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "Header.h" int main() { //std::cout << "Hello World!\n"; char lastName[30]{}; char firstName[30]{}; char fullName[60]{}; printResults(lastName, firstName, fullName); } FILE 2(Function) #include "Header.h" void printResults(char lastName[30], char firstName[30], char fullName[60]) { cout << "Enter Last name: "; cin.getline(lastName, 30); cout << endl; cout << "Enter first name: "; cin.getline(firstName, 30); int x = 0; while (firstName[x] != '\0') { fullName[x] = firstName[x]; x++; } //cout << x; fullName[x] = ','; x++; fullName[x] = ' '; x++; int y = 0; while (lastName[y] != '\0') { fullName[x] = lastName[y]; y++; x++; } cout << fullName; } FILE 3(Header file) #include using namespace std; void printResults(char lastName[30], char firstName[30], char fullName[60]); OUTPUT: Enter Last name: Ansari Enter first name: Rayyan Rayyan, Ansari C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 2456) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . . --------------------------------------------------------------------------------------- 10b 10.8 Exercises p 273 Break into at least 3 files as in 9b. 10 pts #7 Write a full program to do this. Submit: code & runs NOTE: For this question, the books says chech the first 6 characters of string one. Since "Frank" is only 5, I am assuming they want the 6th character to be checked as the carrige return. Hence why when Frank is compared to Franklyn, it comes as false because the program compares Frank(\0) to Frankl FILE 1 (MAIN) #include "CommonInfo.h" int main() { char string1[] = {"Frank"}; char string2[] = { "Franklyn" }; if (checkIfEqual(string1, string2)) { cout << "Same"; } else { cout << "Different"; } } FILE 2 (Functions) #include "CommonInfo.h" bool checkIfEqual(char string1[], char string2[]) { for (int x = 0; x < 6; x++) { if (string1[x] != string2[x]) { return false; } } return true; } FILE 3(Header) #include using namespace std; const int NUMSTUDENTS = 10; const int NUMGRA = 5; bool checkIfEqual(char string1[], char string2[]); OUTPUT: Different C:\Users\ansar\source\repos\LAB5 - Ansari - FIXED\Debug\LAB5 - Ansari - FIXED.exe (process 18420) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .