diff options
| author | [email protected] <[email protected]> | 2021-11-02 18:52:39 -0700 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2021-11-02 18:52:39 -0700 |
| commit | 2b7a662422db204d724a09987c4556d2170b3d81 (patch) | |
| tree | 81d60ad342145bbd38b5f6e8c6acc35d37be90df | |
| parent | Lab 5 answers V1 (diff) | |
| download | cst116-lab5-rayyanansari03-2b7a662422db204d724a09987c4556d2170b3d81.tar.xz cst116-lab5-rayyanansari03-2b7a662422db204d724a09987c4556d2170b3d81.zip | |
Answers V2 Lab 5
| -rw-r--r-- | LAB5-Ansari-Answers.txt | 187 |
1 files changed, 185 insertions, 2 deletions
diff --git a/LAB5-Ansari-Answers.txt b/LAB5-Ansari-Answers.txt index 30a5672..7c58b53 100644 --- a/LAB5-Ansari-Answers.txt +++ b/LAB5-Ansari-Answers.txt @@ -1,5 +1,8 @@ -// LAB5 - ANSARI.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +9a +10.5 Learn by Doing Exercises +p 247 +10 pts #1 +Submit: code & run #include <iostream> using namespace std; @@ -125,4 +128,184 @@ To automatically close the console when debugging stops, enable Tools->Options-> 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 <iostream> +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 . . . + +------------------------------------------------------------------------------------------------------------------- + + + + |