Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain each step of how this C + + code below executes. - - - - - - - - - - - - -

Explain each step of how this C++ code below executes.
---------------------
GradeCalculator.h
---------------------
#ifndef _GRADECALCULATOR
#define _GRADECALCULATOR
#include
#include
class GradeCalculator {
private:
std::map gradeMap;
double totalPoints;
int numClasses;
char minGrade;
char maxGrade;
double gpa;
public:
GradeCalculator();
void collectGrades();
void calculateResults();
void displayResults();
};
#endif
-------------------
GradeCalculator.cpp
-------------------
#include "GradeCalculator.h"
#include
GradeCalculator::GradeCalculator() : totalPoints(0.0), numClasses(3), minGrade('A'), maxGrade('C'), gpa(0.0){
gradeMap ={{'A',4.00},{'B',3.00},{'C',2.00}};
}
void GradeCalculator::collectGrades(){
std::string score;
std::cout << "How many scores are you going to enter: "<< numClasses << std::endl;
for (int i =1; i <= numClasses; i++){
std::cout << "What is class "<< i <<" score: ";
std::cin >> score;
char grade = score[0];
totalPoints += gradeMap[grade];
if (grade < minGrade){
minGrade = grade;
}
if (grade > maxGrade){
maxGrade = grade;
}
}
}
void GradeCalculator::calculateResults(){
gpa = totalPoints / numClasses;
}
void GradeCalculator::displayResults(){
std::cout << "Minimum: "<< minGrade << std::endl;
std::cout << "Maximum: "<< maxGrade << std::endl;
std::cout << "Your GPA is: "<< gpa << std::endl;
}
---------------------
Source.cpp
---------------------
#include
#include "GradeCalculator.h"
int main(){
GradeCalculator gc;
gc.collectGrades();
gc.calculateResults();
gc.displayResults();
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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

Students also viewed these Databases questions

Question

What is unusual about Pythons design of compound statements?

Answered: 1 week ago

Question

Methods of Delivery Guidelines for

Answered: 1 week ago