Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ only please complete the following program by coding the class named Course and a global function named calcClassAverage. calcClassAverage Function Requirements Your global function

C++ only please

complete the following program by coding the class named Course and a global function named calcClassAverage.

calcClassAverage Function Requirements

  • Your global function named calcClassAverage receives iterators to the beginning and end of a range of Student objects
  • This function calculates the average mark of Student objects in the range.

Course Class Requirements

Your Course class includes the following members:

  • an STL container that holds Student objects
  • a boolean that holds true if the average mark for the current instance has been calculated; false otherwise
  • the average mark of all students registered in the course.

  • an overload for += operator that:

    • Adds a Student object received as a parameter to the current instance and returns a reference to the current instance only if the paid tuition by the student is more than $2500
    • If the paid tuition of the parameter is less than or equal to $2500, this operator should not change the current instance and must generate an exception of type string with the message as shown in the sample output below.
      • Remember to update main to handle the exception.
  • an overload for [] operator that:

    • Takes as input the name of a student as the search pattern
    • Returns the address of the student object that matches the name search pattern
    • Use iterators to search for the student
    • If no such student object exists, this function returns nullptr
  • a display function that:

    • receives the address of one of the global functions that displays the requested information (byProgramType or byMarks) and calls it for each student. If the received address is not valid, this function terminates the program with code 15.
    • calculates (if necessary; see next paragraph) and displays the class average.
    • if the class average has not been calculated yet, before printing anything, this function calculates it using the global function calcClassAverage via two threads. For this purpose, the display function divides the container elements into two consecutive halves where each thread processes one half. The result calculated by each thread is returned to the main thread through a shared state implemented using async() function template as the provider object. Then, the calculated value is saved in the appropriate data member, and the state of the current object is updated.

Other Requirements

  • Upgrade the main function of the program to use a smart pointer.
enum class ProgramType { Electrical, Mechanical, Chemical, Civil }; struct Student { std::string name; unsigned tuition; // amount in $ double mark; ProgramType pType; }; void byProgramType(std::ostream& os, const Student& student) { os << " By Program Type <---> "; switch (student.pType) { case ProgramType::Electrical: os << "Electrical"; break; case ProgramType::Mechanical: os << "Mechanical"; break; case ProgramType::Chemical: os << "Chemical"; break; case ProgramType::Civil: os << "Civil"; break; } } void byMark(std::ostream& os, const Student& student) { os << " By Mark <---> "; os << student.mark; } int main() { Student student[] { {"Biden Trump", 2000, 95, ProgramType::Civil}, {"Trudeau A. O'Tool", 2000, 96, ProgramType::Mechanical }, {"Bush Clinton", 3000, 85, ProgramType::Electrical }, {"Regan Carter", 5000, 47, ProgramType::Chemical}, {"Blair Tatcher ", 2800, 53, ProgramType::Civil} }; Course* course = new Course(); for (const auto& i : students) *course += i; course->display(byProgramType); course->display(byMark); std::cout << "========== Mark of Bush Clinton is: " << (*course)["Bush Clinton"]->mark << std::endl; std::cout << "========== End of Program ...." << std::endl; delete course; } 

The output produced by this program using your solution should be:

Tuition Paid (Biden) is less than 2500 Tuition Paid (Trudeau) is less than 2500 By Program Type <---> Electrical By Program Type <---> Chemical By Program Type <---> Civil ========== Class Average this year: 67.5 ========== By Mark <---> 85 By Mark <---> 47 By Mark <---> 53 ========== Class Average this year: 67.5 ========== ========== Mark of Bush Clinton is: 85 ========== End of Program .... 

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 Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions