diff options
| author | Benjamin Schroeder <[email protected]> | 2021-11-01 20:18:49 -0700 |
|---|---|---|
| committer | Benjamin Schroeder <[email protected]> | 2021-11-01 20:18:49 -0700 |
| commit | cc563cdb0b020fa615d82a81410a346a72f8f7e3 (patch) | |
| tree | 09284b5cec30f16246670c4b3505729b11f38a5d | |
| parent | Added exercises 10.7 and 10.8#7 and updated the txt file of the RUNS (diff) | |
| download | archived-cst116-lab5-bensprogramma-cc563cdb0b020fa615d82a81410a346a72f8f7e3.tar.xz archived-cst116-lab5-bensprogramma-cc563cdb0b020fa615d82a81410a346a72f8f7e3.zip | |
update 11/1/21
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5_10.5-10.6_Schroeder.cpp | 2 | ||||
| -rw-r--r-- | RUN_CST1162021_Scores_Schroeder.txt | 179 |
2 files changed, 173 insertions, 8 deletions
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5_10.5-10.6_Schroeder.cpp b/CST116F2021-Lab5/CST116F2021-Lab5_10.5-10.6_Schroeder.cpp index 14dc7d7..9e8d481 100644 --- a/CST116F2021-Lab5/CST116F2021-Lab5_10.5-10.6_Schroeder.cpp +++ b/CST116F2021-Lab5/CST116F2021-Lab5_10.5-10.6_Schroeder.cpp @@ -58,7 +58,7 @@ // // cout <<"Contents of the 'Full Name Array': "<< Full; //} - +// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Exercise 10.8 #7 diff --git a/RUN_CST1162021_Scores_Schroeder.txt b/RUN_CST1162021_Scores_Schroeder.txt index 7808f7e..a81d334 100644 --- a/RUN_CST1162021_Scores_Schroeder.txt +++ b/RUN_CST1162021_Scores_Schroeder.txt @@ -1,8 +1,120 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -Lab5 Exercises 10.5, 10.6, 10.7, and 10.8#7 Benjamin Schroeder - +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +Lab5 Exercises 10.5, 10.6, 10.7, and 10.8#7 Benjamin Schroeder -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Exercise 10.6 and 10.7 +//HEADER FILE "Scores.h" ///////////////////////////////////////////////////////////////////// +#pragma once + +#include <iostream> +using namespace std; + +const int NUM_SCORES = 1; +const int NUM_STUDENT = 10; + +void ReadScores(float[]); +void LetterG(char[], float[], int[]); +void average(float[]); +void displayG(float[], char[], int[]); + +//FUNCTIONS FILE "ScoresFunctions.cpp" /////////////////////////////////////////////////////////// + +#include "Scores.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"; +} + +///// main() FILE ////////////////////////////////////////////////////////////// + +#include "Scores.h" + +int main() +{ + 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); +} + + /////// Run from Exercises 10.5-10.6 Learn By Doing Enter percent score of student: @@ -44,11 +156,42 @@ To automatically close the console when debugging stops, enable Tools->Options-> Press any key to close this window . . . - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Exercise 10.7 Learn By Doing + + +int main() +{ + 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; +} + ////// RUN from Exercise 10.7 Learn By Doing - Enter your first name: Benjamin Enter your last name: Schroeder Contents of the 'Full Name Array': Schroeder, Benjamin @@ -59,8 +202,28 @@ C:\Users\Lenovo\Source\Repos\cst116-lab5-BensProgramma\x64\Debug\CST116F2021-Lab 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 . . . - +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//Exercise 10.8 #7 + +#include<iostream> +using namespace std; + +char string_1[] = "Frank"; +char string_2[] = "Franklyn"; + +int main() +{ + + int compare = strncmp(string_1, string_2, 6); + cout << "Comparing the first 6 chars of strings: '" << string_1 << "' and '" << string_2 << "'"; + if (compare == 0) + cout << "\nSame\n"; + else if (compare < 0) + cout << "\nDifferent\n"; +} + + ////// Run from Exercise 10.8 #7 Comparing the first 6 chars of strings: 'Frank' and 'Franklyn' @@ -69,3 +232,5 @@ Different C:\Users\Lenovo\Source\Repos\cst116-lab5-BensProgramma\x64\Debug\CST116F2021-Lab5.exe (process 21936) 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 . . . + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file |