From 765036c8d2c6acf6c9ce205d7c1bed2a597907a8 Mon Sep 17 00:00:00 2001 From: BensProgramma <91996773+BensProgramma@users.noreply.github.com> Date: Tue, 2 Nov 2021 16:02:41 -0700 Subject: These are the files to be graded --- CST116F2021-Lab5/Lab5ExercisesFunctions.cpp | 154 ++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 CST116F2021-Lab5/Lab5ExercisesFunctions.cpp (limited to 'CST116F2021-Lab5/Lab5ExercisesFunctions.cpp') diff --git a/CST116F2021-Lab5/Lab5ExercisesFunctions.cpp b/CST116F2021-Lab5/Lab5ExercisesFunctions.cpp new file mode 100644 index 0000000..038bc16 --- /dev/null +++ b/CST116F2021-Lab5/Lab5ExercisesFunctions.cpp @@ -0,0 +1,154 @@ +// These are all of the functions used in Lab5 ( Exercises 10.5&10.6(as 10.6) , 10.7, 10.8_7 ) +#include "Lab5Exercises.h" + + +void ReadScores(float testScore[]) +{ + cout << "Enter percent score of student: \n"; + + for (int i = 0; i < NUM_STUDENT; i++) // starting at 0, array numbered 0 to 9 + { + cout << " \t# " << i + 1 << " of " << NUM_STUDENT << " students:\t"; + cin >> testScore[i]; + } +} +void LetterG(char letterGrade[], float testScore[], int gradeCounts[]) +{ + + + for (int i = 0; i < NUM_STUDENT; i++) + { + if (testScore[i] >= 92.0) + { + letterGrade[i] = 'A'; + gradeCounts[0] = gradeCounts[0] + 1; + } + + else if (testScore[i] >= 84.0 && testScore[i] < 92.0) + { + letterGrade[i] = 'B'; + gradeCounts[1] = gradeCounts[1] + 1; + } + + else if (testScore[i] >= 75.0 && testScore[i] < 84.0) + { + letterGrade[i] = 'C'; + gradeCounts[2] = gradeCounts[2] + 1; + } + + else if (testScore[i] >= 65.0 && testScore[i] < 75.0) + { + letterGrade[i] = 'D'; + gradeCounts[3] = gradeCounts[3] + 1; + } + + else if (testScore[i] < 65.0) + { + letterGrade[i] = 'F'; + gradeCounts[4] = gradeCounts[4] + 1; + } + } +} + +void average(float testScore[]) +{ + float average = 0.0; + float total = 0.0; + for (int i = 0; i < NUM_STUDENT; i++) + { + total = total + testScore[i]; + } + + average = total / NUM_STUDENT; + cout << "\n\n\tClass Average: " << average << "%\n\n"; + return; +} +void displayG(float testScore[], char letterGrade[], int gradeCounts[]) +{ + for (int i = 0; i < NUM_STUDENT; i++) + { + cout << " Student # " << i + 1 << ",\tScore: " << testScore[i] << ", Letter Grade: " << letterGrade[i] << "\n"; + } + + cout << "\n\tThere were " << gradeCounts[0] << " A's\n"; + cout << "\tThere were " << gradeCounts[1] << " B's\n"; + cout << "\tThere were " << gradeCounts[2] << " C's\n"; + cout << "\tThere were " << gradeCounts[3] << " D's\n"; + cout << "\tThere were " << gradeCounts[4] << " F's\n"; + +} + + + +void TenSix() + // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // p247 10.5 and 10.6 Learn by doing exercises + + { + int gradeCounts[5]{ 0 }; + float testScore[NUM_STUDENT]{ 0.0 }; + char letterGrade[NUM_STUDENT]{ 'A' }; + + + ReadScores(testScore); + LetterG(letterGrade, testScore, gradeCounts); + cout << "\n\n"; + displayG(testScore, letterGrade, gradeCounts); + average(testScore); + + } + + void TenSeven() + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // p260 10.7 Learn by doing exercise + { + char First[41]{}; + char Last[41]{}; + char Full[81]{}; + + cout << "Enter your first name: "; + cin.ignore(cin.rdbuf()->in_avail()); + cin.getline(First, 41); + cin.clear(); + cin.ignore(cin.rdbuf()->in_avail()); + + + cout << "Enter your last name: "; + cin.ignore(cin.rdbuf()->in_avail()); + cin.getline(Last, 41); + cin.clear(); + cin.ignore(cin.rdbuf()->in_avail()); + + for (int i = 0; i < strlen(Last); i++) + Full[i] = Last[i]; + Full[strlen(Last)] = ','; + Full[strlen(Last) + 1] = ' '; + for (int j = 0; j < strlen(First); j++) + Full[strlen(Last) + 2 + j] = First[j]; + + cout << "Contents of the 'Full Name Array': " << Full<< "\n\n"; + } + + + void TenEight_Seven() + { + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Exercise 10.8 #7 p273 + + char string_1[] = "Frank"; + char string_2[] = "Franklyn"; + + + int differnt = 0; + + for (int i = 0; i < 6; i++) + if (string_1[i] != string_2[i]) + differnt = differnt + 1; + if (differnt > 0) + cout << "Different\n"; + else + cout << "Same\n"; + + } + + -- cgit v1.2.3