Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain each step of how this C + + code below executes. What does each line of code do ? - - - - -

Explain each step of how this C++ code below executes. What does each line of code do?
---------------------
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 Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions