diff options
| author | JerichoBingham <[email protected]> | 2021-11-02 22:41:11 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-02 22:41:11 -0700 |
| commit | 2516f6904fd07e9d97b442268a45b3d680e19c0d (patch) | |
| tree | e18a1e732900f7bd084aa028feef1b67a3aa19d2 | |
| parent | Create Lab 5 main (diff) | |
| download | cst116-lab5-jerichobingham-master.tar.xz cst116-lab5-jerichobingham-master.zip | |
| -rw-r--r-- | Lab 5 finished code | 449 |
1 files changed, 449 insertions, 0 deletions
diff --git a/Lab 5 finished code b/Lab 5 finished code new file mode 100644 index 0000000..2335d4a --- /dev/null +++ b/Lab 5 finished code @@ -0,0 +1,449 @@ +#include <iostream> + +using namespace std; + +using std::endl; + +int main() + +{ + + int A = 0, B = 0, C = 0, D = 0, F = 0; + + int score[10]; + + char letters[5] = { 'A', 'B', 'C', 'D', 'F' }; + + int grade[5] = { 92, 84, 75, 68, 0 }; + + cout << "\n ************************************************* \n"; + + for (int i = 0; i < 10; i++) + + { + + cout << "\n Enter the test score " << i+1 << ": "; + + cin >> score[i]; + + } + + cout << "\n ************************************************* \n"; + + int total = 0; + + for (int i = 0; i < 10; i++) { + + total += score[i]; + + } + + int average = total / 10; + + for (int i = 0; i < 10; i++) + + { + + if (score[i] >= 92) + + A += 1; + + if (score[i] >= 84) + + B += 1; + + if (score[i] >= 75) + + C += 1; + + if (score[i] >= 65) + + D += 1; + + if (score[i] < 65) + + F += 1; + + + + } + + int counter = 0; + + for (int i = 0; i < counter ; i++) + + { + + for (int x = 0; x < 10; x++) + + { + + if (score[i] >= grade[x]) + + { + + score[i] = letters[x]; + + x = 10; + + } + + } + + } + + cout << "\n\nThe average of the scores is: " << average << endl; + + cout << "\n\n *************************************************"; + + cout << "\n\n Here are the grades and the letter grades: "; + + for (int i = 0; i < 10; i++) + + cout << score[i] << "\t\t\t" << letters[i] << endl; + + cout << "\n The number of each letter grade: " + + << "\n The number of A's: " << A + + << "\n The number of B's: " << B + + << "\n The number of C's: " << C + + << "\n The number of D's: " << D + + << "\n The number of F's: " << F; + + cout << "\n\n *************************************************"; + + return 0; + +} + +Main: + +#include "Header.h" + +int main() + +{ + + Input(); + + Math(); + + Output(); + + return 0; + +} + +Functions: + +#include "Header.h" + +#include <iostream> + +using namespace std; + +using std::endl; + +int A = 0, B = 0, C = 0, D = 0, F = 0; + +int total = 0; + +int average = total / 10; + +int score[10]; + +char letters[5] = { 'A', 'B', 'C', 'D', 'F' }; + +int grade[5] = { 92, 84, 75, 68, 0 }; + +void Input() + +{ + + cout << "\n ************************************************* \n"; + + for (int i = 0; i < 10; i++) + + { + + cout << "\n Enter the test score " << i + 1 << ": "; + + cin >> score[i]; + + } + + cout << "\n ************************************************* \n"; + +} + +void Math() + +{ + + int total = 0; + + for (int i = 0; i < 10; i++) { + + total += score[i]; + + } + + int average = total / 10; + + for (int i = 0; i < 10; i++) + + { + + if (score[i] >= 92) + + A += 1; + + if (score[i] >= 84 && score[i] < 92) + + B += 1; + + if (score[i] >= 75 && score[i] < 84) + + C += 1; + + if (score[i] >= 65 && score[i] < 75) + + D += 1; + + if (score[i] < 65) + + F += 1; + + } + + int counter = 0; + + for (int i = 0; i < counter; i++) + + { + + for (int x = 0; x < 10; x++) + + { + + if (score[i] >= grade[x]) + + { + + score[i] = letters[x]; + + x = 10; + + } + + } + + } + +} + +void Output() + +{ + + cout << "\n\nThe average of the scores is: " << average << endl; + + cout << "\n\n *************************************************"; + + cout << "\n\n Here are the grades and the letter grades: \n"; + + for (int i = 0; i < 10; i++) + + cout << score[i] << "\t\t\t" << letters[i] << endl; + + cout << "\n The number of each letter grade: " + + << "\n The number of A's: " << A + + << "\n The number of B's: " << B + + << "\n The number of C's: " << C + + << "\n The number of D's: " << D + + << "\n The number of F's: " << F; + + cout << "\n\n *************************************************"; + +} + +Header: + +#ifndef HEADER_H + +#define HEADER_H + +void Input(); + +void Math(); + +void Output(); + +#endif + + Main.cpp: + +#include "Header.h" + +int main() + +{ + +Math(); + +return 0; + +} + + + +Functions.cpp: + +using namespace std; + +char string_1[] = "Frank"; + +char string_2[] = "Franklyn"; + +void Math() + +{ + +cout << "\n\n ******************************"; + +for (int i = 0; i < 6; i++) + +{ + +if (string_1[i] = string_2[i]) + +string_1[i] = string_2[i]; + +if (string_1[i] != string_2[i]) + +string_1[i] != string_2[i]; + +} + +if (string_1 == string_2) + +cout << "\n Same" + +else + +cout << "\n Different"; + +cout << "\n\n ******************************"; + +} + + + +Intfuctions.h: + +#ifndef HEADER_H + +#define HEADER_H + +void Math(); + +#endif + + Main: + +#include "intfunctions.h" + +#include <iostream> + +using namespace std; + +int main() + +{ + +char first[8]; + +char last[8]; + +char format[18]; + +cout << "Enter first name: "; + +cin >> first; + +cout << "Enter last name: "; + +cin >> last; + +fun(first, last, format); + +cout << format; + +return 0; + +} + +Functions: + +#include "intfunctions.h" + +#include <iostream> + +#include<string.h> + +char first[8]; + +char last[8]; + +char format[18]; + +void fun(char first[], char last[], char format[]) + +{ + +int i, j = 0; + +for (i = 0; i < strlen(last); i++) + +{ + +format[j++] = last[i]; + +} + +format[j++] = ','; + +format[j++] = ' '; + +for (i = 0; i < strlen(first); i++) + +{ + +format[j++] = first[i]; + +} + +format[j++] = ' '; + +} + +Header: + +#ifndef intfunctions_h + +#define intfunctions_h + +void fun(char first[], char last[], char format[]); + +#endif + + |