Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. Gradebook, For your test you should test more than one class gradebook. For example make gradebook for all your courses you currently have. CPP

C++. Gradebook, For your test you should test more than one class gradebook. For example make gradebook for all your courses you currently have.

CPP file:

#include

#include "Gradebook.h"

using namespace std;

using GradeBook10_3 = Gradebook<10, 3>;

int GradeBook10_3::TotalNumGradebooks{ 0 };

int main()

{

array< array, 10> grades

{

{{88, 90, 92},

{39, 55, 67},

{69, 49, 85},

{70, 72, 77},

{80, 81, 88},

{91, 93, 90},

{83, 89, 79},

{90, 74, 77},

{85, 67, 70},

{55, 45, 35}}

};

GradeBook10_3 myGradebook("VGP102 C++ Programming I", grades);

myGradebook.displayMessage();

myGradebook.processGrades();

Gradebook<10, 3> copyGradebook(myGradebook);

copyGradebook.processGrades();

std::cout << "TotalNumGradebooks=" <<

GradeBook10_3::TotalNumGradebooks << std::endl;

return 0;

}

header file:

#pragma once

// using 2 dimensional array to store student test grades.

#include

#include

#include

#include

// Gradebook class definition

template

class Gradebook

{

public:

static int TotalNumGradebooks;

using StudentGrades = std::array;

using CourseGrades = std::array;

// constructors

Gradebook(std::string const& name,

CourseGrades const& gradeArray)

: courseName(name), grades(gradeArray)

{

++TotalNumGradebooks;

}

Gradebook() = delete; // default constructor is not available

Gradebook(Gradebook const& book): // copy constructor

courseName(book.getCourseName()),

grades(book.getGrades())

{

++TotalNumGradebooks;

}

~Gradebook()

{

--TotalNumGradebooks;

std::cout << "A gradebook destroyed. TotalNumGradebooks="

<< TotalNumGradebooks << std::endl;

}

void setCourseName(std::string const& name)

{

courseName = name;

}

std::string const& getCourseName() const

{

return courseName;

}

CourseGrades const& getGrades() const

{

return grades;

}

void displayMessage() const

{

std::cout << "Welcome to theg rad book for " << getCourseName() << "! ";

}

void processGrades() const

{

outputGrades(); // output grades array

std::cout << " Lowest grade in th gradebook is " << getMinimum()

<< " Highetst grade in the gradebook is " << getMaximum() << std::endl;

outputBarChart();

}

int getMinimum() const

{

int lowGrade{ 100 };

for (auto const& studentgrades : grades)

{

for (auto const& grade : studentgrades)

{

if (grade < lowGrade)

lowGrade = grade;

}

}

return lowGrade;

}

int getMaximum() const

{

int highGrade{ 0 };

for (auto const& studentgrades : grades)

{

for (auto const& grade : studentgrades)

{

if (grade > highGrade)

highGrade = grade;

}

}

return highGrade;

}

void outputBarChart() const

{

std::cout << " Overall grade distribution: ";

const size_t frequencySize{ 11 };

std::array frequency{}; // initialize to 0s

for (auto const& student : grades)

{

for (auto const& test : student)

++frequency[test / 10];

}

// print the bar chart:

for (size_t count{ 0 }; count < frequencySize; ++count)

{

// first output label for each bar

if (0 == count)

std::cout << " 0-9: ";

else if (10 == count)

std::cout << " 100: ";

else

std::cout << count * 10 << "-" << (count * 10) + 9 << ": ";

//print bar of astrisks

for (unsigned int stars{ 0 }; stars < frequency[count]; ++stars)

std::cout << "*";

std::cout << std::endl;

}

}

// output the content of the grade array

void outputGrades() const

{

}

// determine average grade for a particular student

double getAverageGradePerStudent(int studentIndex) const

{

return 0.;

}

// determine average grade for a particular test

double getAverageGradePerTest(int testIndex) const

{

return 0.;

}

// sorts each student tests in the increasing order

void sortStudentTests()

{

}

// sorts the outer array based on student's average. This means the first student array

// should correspond to student with highest average on his/her tests.

void sortGradeBook()

{

}

private:

std::string courseName;

CourseGrades grades; // 2D array

};

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions