diff options
| author | IsabellaMon <[email protected]> | 2021-11-02 23:59:09 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-02 23:59:09 -0700 |
| commit | 355af746d195cc34dec4c343dab2e4b2cf17d460 (patch) | |
| tree | 43aceecaf6ac169005dd877cb8a0e661721ed714 /M5L5.txt | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab5-isabellamon-master.tar.xz cst116-lab5-isabellamon-master.zip | |
M5L5
Diffstat (limited to 'M5L5.txt')
| -rw-r--r-- | M5L5.txt | 469 |
1 files changed, 469 insertions, 0 deletions
diff --git a/M5L5.txt b/M5L5.txt new file mode 100644 index 0000000..18bed33 --- /dev/null +++ b/M5L5.txt @@ -0,0 +1,469 @@ +CST116
+Module 5: Lab 5
+
+9a
+10.5 Learn by Doing Exercises
+p 247
+10 pts #1
+Submit: code & run
+
+CODE:
+
+ #include <iostream>
+ using namespace std;
+ const int NUM_GRADES = 5;
+ const int NUM_STUS = 10;
+
+ int main()
+ {
+ float score[NUM_STUS]{ 0.0 };
+ char letter[NUM_GRADES]{ 'A', 'B', 'C', 'D', 'F'};
+ int a = 0, b = 0, c = 0, d = 0, f = 0;
+ float total = 0;
+ float avg = 0;
+
+ for (int i = 0; i < NUM_STUS; i++)
+ {
+ cout << "Enter student #" << i + 1 << "'s score : ";
+ cin >> score[i];
+
+ if (score[i] >= 92)
+ {
+ cout << letter[0] << ": " << score[i] << " % \n" << endl;
+ a = a + 1;
+ }
+ else if (score[i] < 92 && score[i] >= 84)
+ {
+ cout << letter[1] << ": " << score[i] << "% \n" << endl;
+ b = b + 1;
+ }
+ else if (score[i] < 84 && score[i] >= 75)
+ {
+ cout << letter[2] << ": " << score[i] << "% \n" << endl;
+ c = c + 1;
+ }
+ else if (score[i] < 75 && score[i] >= 65)
+ {
+ cout << letter[3] << ": " << score[i] << "% \n" << endl;
+ d = d + 1;
+ }
+ else
+ {
+ cout << letter[4] << ": " << score[i] << "% \n" << endl;
+ f = f + 1;
+ }
+ }
+
+
+ for (int i = 0; i < NUM_STUS; i++)
+ {
+ total += score[i];
+
+ }
+ avg = total / NUM_STUS;
+ cout << "\n\t\t* CLASS STATS *\n" << endl;
+
+ cout << "\t" << a << " students scored A's \n" << endl;
+ cout << "\t" << b << " students scored B's \n" << endl;
+ cout << "\t" << c << " students scored C's \n" << endl;
+ cout << "\t" << d << " students scored D's \n" << endl;
+ cout << "\t" << f << " students scored F's \n" << endl;
+ cout << "\tThe class average score is " << avg << "% \n" << endl;
+
+
+ return 0;
+
+ }
+
+RUN:
+
+ Enter student #1's score : 97
+ A: 97 %
+
+ Enter student #2's score : 94
+ A: 94 %
+
+ Enter student #3's score : 22
+ F: 22%
+
+ Enter student #4's score : 52
+ F: 52%
+
+ Enter student #5's score : 63
+ F: 63%
+
+ Enter student #6's score : 84
+ B: 84%
+
+ Enter student #7's score : 75
+ C: 75%
+
+ Enter student #8's score : 69
+ D: 69%
+
+ Enter student #9's score : 65
+ D: 65%
+
+ Enter student #10's score : 98
+ A: 98 %
+
+ * CLASS STATS *
+
+ 3 students scored A's
+
+ 1 students scored B's
+
+ 1 students scored C's
+
+ 2 students scored D's
+
+ 3 students scored F's
+
+ The class average score is 71.9%
+
+
+9b
+10.6 Learn by Doing Exercises
+p 253
+Break into functions
+10 pts #1
+Submit: code & run
+
+CODE:
+
+ #include <iostream>
+ using namespace std;
+ const int NUM_GRADES = 5;
+ const int NUM_STUS = 10;
+
+ void GetScore(float score[10], char letter[5], int& a, int& b, int& c, int& d, int& f);
+ void GetAvg(float score[10], char letter[5], float& avg, float& total);
+ void Display(float score[10], char letter[5], float& avg, int& a, int& b, int& c, int& d, int& f);
+
+ int main()
+ {
+ float score[NUM_STUS]{ 0.0 };
+ char letter[NUM_GRADES]{ 'A', 'B', 'C', 'D', 'F' };
+ int a = 0, b = 0, c = 0, d = 0, f = 0;
+ float total = 0;
+ float avg = 0;
+
+ GetScore(score, letter, a, b, c, d, f);
+ GetAvg(score, letter, avg, total);
+ Display(score, letter, avg, a, b, c, d, f);
+
+ return 0;
+ }
+
+ void GetScore(float score[10], char letter[5], int& a, int& b, int& c, int& d, int& f)
+ {
+
+
+ for (int i = 0; i < NUM_STUS; i++)
+ {
+ cout << "Enter student #" << i + 1 << "'s score : ";
+ cin >> score[i];
+
+ if (score[i] >= 92)
+ {
+ cout << letter[0] << ": " << score[i] << " % \n" << endl;
+ a = a + 1;
+ }
+ else if (score[i] < 92 && score[i] >= 84)
+ {
+ cout << letter[1] << ": " << score[i] << "% \n" << endl;
+ b = b + 1;
+ }
+ else if (score[i] < 84 && score[i] >= 75)
+ {
+ cout << letter[2] << ": " << score[i] << "% \n" << endl;
+ c = c + 1;
+ }
+ else if (score[i] < 75 && score[i] >= 65)
+ {
+ cout << letter[3] << ": " << score[i] << "% \n" << endl;
+ d = d + 1;
+ }
+ else
+ {
+ cout << letter[4] << ": " << score[i] << "% \n" << endl;
+ f = f + 1;
+ }
+ }
+ }
+
+ void GetAvg(float score[10], char letter[5], float& avg, float& total)
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ total += score[i];
+
+ }
+ avg = total / 10;
+ }
+
+ void Display(float score[10], char letter[5], float& avg, int& a, int& b, int& c, int& d, int& f)
+ {
+ cout << "\n\t\t* CLASS STATS *\n" << endl;
+
+ cout << "\t" << a << " students scored A's \n" << endl;
+ cout << "\t" << b << " students scored B's \n" << endl;
+ cout << "\t" << c << " students scored C's \n" << endl;
+ cout << "\t" << d << " students scored D's \n" << endl;
+ cout << "\t" << f << " students scored F's \n" << endl;
+ cout << "\tThe class average score is " << avg << "% \n" << endl;
+ }
+
+
+RUN:
+
+ Enter student #1's score : 78
+ C: 78%
+
+ Enter student #2's score : 48
+ F: 48%
+
+ Enter student #3's score : 100
+ A: 100 %
+
+ Enter student #4's score : 65
+ D: 65%
+
+ Enter student #5's score : 98
+ A: 98 %
+
+ Enter student #6's score : 45
+ F: 45%
+
+ Enter student #7's score : 25
+ F: 25%
+
+ Enter student #8's score : 65
+ D: 65%
+
+ Enter student #9's score : 45
+ F: 45%
+
+ Enter student #10's score : 65
+ D: 65%
+
+
+ * CLASS STATS *
+
+ 2 students scored A's
+
+ 0 students scored B's
+
+ 1 students scored C's
+
+ 3 students scored D's
+
+ 4 students scored F's
+
+ The class average score is 63.4%
+
+
+
+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:
+
+(Header.h file)**********************************
+ #pragma once
+
+ #include "Functions.cpp"
+
+ #include <iostream>
+ using namespace std;
+ const int NUM_GRADES = 5;
+ const int NUM_STUS = 10;
+
+ void GetScore(float score[10], char letter[5], int& a, int& b, int& c, int& d, int& f);
+ void GetAvg(float score[10], char letter[5], float& avg, float& total);
+ void Display(float score[10], char letter[5], float& avg, int& a, int& b, int& c, int& d, int& f);
+
+(Functions.cpp file)**********************************
+ #include "Header.h"
+
+ void GetScore(float score[10], char letter[5], int& a, int& b, int& c, int& d, int& f)
+ {
+
+
+ for (int i = 0; i < NUM_STUS; i++)
+ {
+ cout << "Enter student #" << i + 1 << "'s score : ";
+ cin >> score[i];
+
+ if (score[i] >= 92)
+ {
+ cout << letter[0] << ": " << score[i] << " % \n" << endl;
+ a = a + 1;
+ }
+ else if (score[i] < 92 && score[i] >= 84)
+ {
+ cout << letter[1] << ": " << score[i] << "% \n" << endl;
+ b = b + 1;
+ }
+ else if (score[i] < 84 && score[i] >= 75)
+ {
+ cout << letter[2] << ": " << score[i] << "% \n" << endl;
+ c = c + 1;
+ }
+ else if (score[i] < 75 && score[i] >= 65)
+ {
+ cout << letter[3] << ": " << score[i] << "% \n" << endl;
+ d = d + 1;
+ }
+ else
+ {
+ cout << letter[4] << ": " << score[i] << "% \n" << endl;
+ f = f + 1;
+ }
+ }
+ }
+
+ void GetAvg(float score[10], char letter[5], float& avg, float& total)
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ total += score[i];
+
+ }
+ avg = total / 10;
+ }
+
+ void Display(float score[10], char letter[5], float& avg, int& a, int& b, int& c, int& d, int& f)
+ {
+ cout << "\n\t\t* CLASS STATS *\n" << endl;
+
+ cout << "\t" << a << " students scored A's \n" << endl;
+ cout << "\t" << b << " students scored B's \n" << endl;
+ cout << "\t" << c << " students scored C's \n" << endl;
+ cout << "\t" << d << " students scored D's \n" << endl;
+ cout << "\t" << f << " students scored F's \n" << endl;
+ cout << "\tThe class average score is " << avg << "% \n" << endl;
+ }
+
+(Main file)**********************************
+ #include "Header.h"
+ #include "Functions.cpp"
+
+
+ int main()
+ {
+ float score[NUM_STUS]{ 0.0 };
+ char letter[NUM_GRADES]{ 'A', 'B', 'C', 'D', 'F' };
+ int a = 0, b = 0, c = 0, d = 0, f = 0;
+ float total = 0;
+ float avg = 0;
+
+ GetScore(score, letter, a, b, c, d, f);
+ GetAvg(score, letter, avg, total);
+ Display(score, letter, avg, a, b, c, d, f);
+
+ return 0;
+ }
+
+
+RUN:
+
+ Enter student #1's score : 98
+ A: 98 %
+
+ Enter student #2's score : 95
+ A: 95 %
+
+ Enter student #3's score : 96
+ A: 96 %
+
+ Enter student #4's score : 78
+ C: 78%
+
+ Enter student #5's score : 85
+ B: 85%
+
+ Enter student #6's score : 84
+ B: 84%
+
+ Enter student #7's score : 83
+ C: 83%
+
+ Enter student #8's score : 100
+ A: 100 %
+
+ Enter student #9's score : 90
+ B: 90%
+
+ Enter student #10's score : 23
+ F: 23%
+
+
+ * CLASS STATS *
+
+ 4 students scored A's
+
+ 3 students scored B's
+
+ 2 students scored C's
+
+ 0 students scored D's
+
+ 1 students scored F's
+
+ The class average score is 83.2%
+
+
+
+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
+Total: 40 pts
+
+CODE:
+
+(Header.h file)**********************************
+ #pragma once
+
+ #include "Functions.cpp"
+ #include <iostream>
+ #include <cstring>
+ using namespace std;
+ int compare();
+
+(Functions.cpp file)**********************************
+ #include "Header.h"
+
+ int compare()
+ {
+ char string_1[] = "Frank";
+ char string_2[] = "Franklyn";
+
+ if (strncmp(string_1, string_2, 6) == 0)
+ cout << "Same";
+ else
+ cout << "Different";
+
+ }
+
+(Main file)**********************************
+ #include "Header.h"
+ #include "Functions.cpp"
+
+ int main()
+ {
+ compare();
+
+ return 0;
+ }
+
+RUN:
+
+ Different
\ No newline at end of file |