Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include Take the following c++ code and make the necessary changes to make a fully functional gpa calculator. The user must be asked how

#include #include

Take the following c++ code and make the necessary changes to make a fully functional gpa calculator. The user must be asked how many students and then for each student how many courses and then the user must be given the option to enter the grades in letters such as 'A' 'B' 'C' 'D' 'F' or in gradepoints such as 4.0, 3.0,2.0, 1.0 and 0.0.

Try to only make changes that are needed to ensure the program works.

struct student { unsigned short numCourse; int* hours; float* gradepoints; char* grades; float gpa; }; float Gpa(const char grades[], const int hours[], int arrLength); float Gpa(const char grades[], const int hours[], int arrLength) { float gpa = 0; float gradePoints; int totalHours = 0; for (int i = 0; i < arrLength; i++) { gradePoints = GradePoints(grades[i]); gpa += (gradePoints * hours[i]); totalHours += hours[i]; } gpa = gpa / totalHours; return gpa; }

float Gpa(const float gradePoints[], const int hours[], int arrLength); float GradePoints(char grade); float GradePoints(char grade) { float gradePoints; switch (grade) { case 'A': gradePoints = 4.0; break; case 'B': gradePoints = 3.0; break; case 'C': gradePoints = 2.0; break; case 'D': gradePoints = 1.0; break; case 'F': gradePoints = 0.0; break; default: gradePoints = 0.0; }

return gradePoints; }

using namespace std; int main() { int numStudents; cout << "Please enter the number of students: "; cin >> numStudents;

student* students = new student[numStudents];

for (int i = 0; i < numStudents; i++) { cout << "Please enter the number of courses: "; cin >> students[i].numCourse; students[i].hours = new int[students[i].numCourse]; students[i].gradepoints = new float[students[i].numCourse]; students[i].grades = new char[students[i].numCourse]; students[i].gpa = new float[students[i].numCourse];

for (int j = 0; j < students[i].numCourse; j++) { cout << "Please enter the grade for course " << j + 1 << ": "; cin >> students[i].grades[j]; cout << "Please enter the hours for course " << j + 1 << ": "; cin >> students[i].hours[j]; students[i].gradepoints[j] = GradePoints(students[i].grades[j]);

}

students[i].gpa[i] = Gpa(students[i].gradepoints, students[i].hours, students[i].numCourse); } for (int i = 0; i < numStudents; i++) { delete[] students[i].hours; delete[] students[i].gradepoints; delete[] students[i].grades; delete[] students[i].gpa; } delete[] students;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Answer the question, What is human resource management?

Answered: 1 week ago

Question

Identify three types of physicians and their roles in health care.

Answered: 1 week ago

Question

Compare the types of managed care organizations (MCOs).

Answered: 1 week ago