Question
It gives me error when I'm trying to compile and run it especially at AddGrade < < undefined reference. Please revise my source code!! thank
It gives me error when I'm trying to compile and run it especially at AddGrade << undefined reference. Please revise my source code!! thank you!! If there's anything wrong with it, please correct it as well!!(this is a GPA analyzing program)
#include
using namespace std;
// Function prototypes void ProgramGreeting(); void AddGrade(int*&, int&); void PrintAllGrades(int*, int); char Grade2Lttr(int); void ComputeAllGrades(int*, int);
int main() { int* grades = nullptr; // pointer to dynamic array of grades int numGrades = 0; // number of grades currently in the array int choice; // user's menu choice
ProgramGreeting();
do { // Display the user's menu cout << "Main Menu. " << "1. Add Grade. " << "2. Display All Grades. " << "3. Process All Grades. " << "4. Quit Program. " << "Enter your choice: "; cin >> choice;
// Process the user's choice switch (choice) { case 1: AddGrade(grades, numGrades); break; case 2: PrintAllGrades(grades, numGrades); break; case 3: ComputeAllGrades(grades, numGrades); break; case 4: // Exit the program cout << "Thank you and we will See you again!!" << endl; break; default: // Invalid input, reprompt cout << "Invalid input. Please enter a number between 1 and 4." << endl; cin.clear(); cin.ignore(10000, ' '); } } while (choice != 4);
// Free the memory space allocated for the grades array delete[] grades;
return 0; }
// Specification C1 - Program Greeting Function void ProgramGreeting() { cout << "welcome!!" << endl << "My name is jeffery thao." << endl << "February 23, 2023. " << endl; }
// Specification C2 - Print Scores void Print_All_Grades(int* grades, int numGrades) { cout << "Grades you entered so far:" << endl; for (int i = 0; i < numGrades; i++) { cout << "Score " << i + 1 << ": " << grades[i] << " (" << Grade2Lttr(grades[i]) << ")" << endl; } }
// Specification C3 - Letter Grades char Grade2Lttr(int grade) { if (grade >= 90) { return 'A'; } else if (grade >= 80) { return 'B'; } else if (grade >= 70) { return 'C'; } else if (grade >= 60) { return 'D'; } else if (grade >= 0) { return 'F'; } else { return 'X'; // invalid grade } }
// Specification C4 - Compute GPA void ComputeAllGrades(int* grades, int numGrades) { if (numGrades == 0) { cout << "Grade has not been entered." << endl; return; }
int totalScore = 0; for (int i = 0; i < numGrades; i++) { totalScore += grades[i]; } }
// Specification B1 - Dynamic Array class StudentGrades { public: StudentGrades(); ~StudentGrades(); void AddGrade(int grade); void PrintAllGrades(); void ComputeAllGrades(); private: int* grades; int size; int capacity; };
StudentGrades::StudentGrades() { grades = new int[1]; size = 0; capacity = 1; }
StudentGrades::~StudentGrades() { delete[] grades; }
//Specification B2 void StudentGrades::AddGrade(int grade) { if (size == capacity) { int* pTmp = new int[capacity * 2]; for (int i = 0; i < capacity; i++) { pTmp[i] = grades[i]; } delete[] grades; grades = pTmp; capacity *= 2; } grades[size++] = grade; }
// Specification B3 - Menu Input Validation void validateMenuInput(int& choice) { do { cout << "Enter You Choice: "; cin >> choice; if (cin.fail() || choice < 1 || choice > 4) { cin.clear(); cin.ignore(numeric_limits
// Specification B4 - Highlight Failing Grades class FancyText { public: static const string RED; static const string RESET; static string color(const string& text, const string& color); };
const string FancyText::RED = "\033[1;31m"; const string FancyText::RESET = "\033[0m";
string FancyText::color(const string& text, const string& color) { return color + text + RESET; }
// Specification A4 - Unit Test void UnitTest() { // Test score to letter grade conversion if (Grade2Lttr(95) == 'A' && Grade2Lttr(85) == 'B' && Grade2Lttr(75) == 'C' && Grade2Lttr(65) == 'D' && Grade2Lttr(55) == 'F' && Grade2Lttr(105) == 'X' && Grade2Lttr(-5) == 'X') { cout << "It passed the Unit Test for score to letter grade conversion." << endl; } else { cout << "It failed the Unit Test for score to letter grade conversion." << endl; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started