//This file contains all of the functions in the project. Code by Jordan Harris-Toovy, November 2021 #include "Main_header.h" //10.6 LBD-Ex #1 void get_scores(float storage[]) { for (int idx = 0; idx < NUM_SCORES; idx++) { while (storage[idx] <= 0) { cout << "Enter score #" << idx + 1 << " of " << NUM_SCORES << ": "; cin >> storage[idx]; if (storage[idx] < 0) { cout << "\nError: Score cannot be negative\n"; } } } } void grade_scores(float score[], char grade[]) { for (int idx = 0; idx < NUM_SCORES; idx++) { if (score[idx] >= 92.0F) { grade[idx] = 'A'; } else if (score[idx] >= 84.0F) { grade[idx] = 'B'; } else if (score[idx] >= 75.0F) { grade[idx] = 'C'; } else if (score[idx] >= 65.0F) { grade[idx] = 'D'; } else { grade[idx] = 'F'; } } } void total_grades(char grades[], int grade_total[]) { for (int idx = 0; idx < NUM_SCORES; idx++) { switch (grades[idx]) { case 'A': grade_total[0]++; break; case 'B': grade_total[1]++; break; case 'C': grade_total[2]++; break; case 'D': grade_total[3]++; break; case 'F': grade_total[4]++; break; default: break; } } } float average_scores(float scores[]) { float total = 0.0F; for (int idx = 0; idx < NUM_SCORES; idx++) { total += scores[idx]; } return (total / NUM_SCORES); } void display_info(float& avg, int total_grades[], char grades[], float scores[]) { cout << endl << "The average score is: " << avg << endl << "The number of assigned grades are as follows: "; cout << "A - " << total_grades[0] << ", B - " << total_grades[1] << ", C - " << total_grades[2] << ", D - " << total_grades[3] << ", F - " << total_grades[4] << endl; cout << "The individual scores are as follows: " << endl; for (int idx = 0; idx < NUM_SCORES; idx++) { cout << "Student " << idx + 1 << " scored " << scores[idx] << " (" << grades[idx] << ")\n"; } } //10.7 LBD-Ex #2 void getName(char name[], int nameMode = 0) { if (nameMode == 0) { cout << "Please enter your first name: "; cin >> name; } else if (nameMode == 1) { cout << "Please enter your last name: "; cin >> name; } else { cout << "\nERROR: INVALID getName MODE\n" << endl; } } int getStringSize(char string[]) { int idx = 0; while (string[idx] != '\0') { idx++; } return idx; } //10.8 Ex #7 void get_string(char user_string[], int mode) { if (mode == 0) { cout << "Please enter a string (alphanumeric and +-,.): "; } else { cout << "Please enter another string: "; } cin >> user_string; //BUG: some characters, such as the space character, will act as delimiters, causing cin to pickup two strings instantly. } bool string_compair_N(char str1[], char str2[], int num_cmp) { bool result = true; for (int idx = 0; idx < num_cmp; idx++) { if (str1[idx] != str2[idx]) { result = false; } } return result; }