Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Create a Homework class with fields for the class name, the assignment (for e

ID: 3546239 • Letter: A

Question

a. Create a Homework class with fields for the class name, the assignment (for example, "read chapter 11"), and the number of minutes predicted it will take to complete the assignment. Include functions to set the values for the  Homework fields, to provide output, and to overload the + operator to add Homework objects'  minutes. The result of the addition is a summary Homework object.


b. Create a function template that adds two values and returns their sum.


c. Write a main () function that tests the function template with integer, double, and Homework objects.



Example:

Create a Homework class with fields for the class name, the assignment (for example, "read chapter 11"), and the number of minutes predicted it will take to complete the assignment. Include functions to set the values for the Homework fields, to provide output, and to overload the + operator to add Homework objects' minutes. The result of the addition is a summary Homework object. Create a function template that adds two values and returns their sum. Write a main () function that tests the function template with integer, double, and Homework objects. Example:

Explanation / Answer

Hope this helps

#include <iostream>

#include <string>

using namespace std;

//Class Homework

class Homework{

        //...Member function for class Homework...

//Private data for class Homework

private:

        //Local and private variable

        string className;

        string assignment;

        int numOfminutes;

//Public data for class Homework     

public:

        Homework();//Constructor

        void setClassName( string );//Mutator for set class name

        string getClassName();//Accessor to get class name

        void setAssignment( string );//Mutator for set assignment

        string getAssignment();//accessor to get assignment

        void set_numOfminutes( int );

        int get_numOfminutes( );

        Homework operator+(Homework);//overloading operator + to add the minutes required by multiple Homework object

};

//Template function that return sum of the two parameters

T AddTwoValues(T value1 , T value2 ){

return value1 + value2;

}

//Overloading operator+

Homework Homework :: operator+ (Homework hw){

        Homework hw_result = *this;

        hw_result.numOfminutes += hw.numOfminutes;

        return hw_result;

}

//Constructor

//Initialize the variable for string & int

Homework :: Homework(){

        className = "";

        assignment = "";

        numOfminutes = 0;

}

//Mutator

void Homework :: setClassName( string theClassName ){

        className = theClassName;

        numOfminutes = 0;

}

//Accessor

string Homework :: getClassName(){

        return className;

}

//Mutator

void Homework :: setAssignment( string theAssignment ){

        assignment = theAssignment;

}

//Accesor

string Homework :: getAssignment(){

        return assignment;

}

void Homework :: set_numOfminutes( int theminutes ){

        numOfminutes = theminutes;

}

int Homework :: get_numOfminutes(){

        return numOfminutes;

}

int main(){

        //Set multiple Homework object

        Homework thehomework1 , thehomework2;

        thehomework1.setClassName( "PSDC Batch 18 CE");

        thehomework1.setAssignment( "Read Chapter 11" );

        thehomework1.set_numOfminutes( 150 );

       

        thehomework2.setClassName( "Inti Batch 1 CS" );

        thehomework2.setAssignment( "Read Chapter 22" );

        thehomework2.set_numOfminutes( 280 );

        Homework homework3 = thehomework1 + thehomework2;

        cout << "Name for first class : " << thehomework1.getClassName() << endl

               << "Assignment title      : " << thehomework1.getAssignment() << endl << endl

               << "Number of minutes that will take to complete assignment : " << thehomework1.get_numOfminutes() << endl << endl

               << "Name for second class : " << thehomework2.getClassName() << endl

               << "Assignment title      : " << thehomework2.getAssignment() << endl << endl

               << "Number of minutes that will take to complete assignment : " << thehomework2.get_numOfminutes() << endl << endl ;

        cout << "Summary of time for the assignments that required [integer] : "

               << AddTwoValues( 30 , 40 )//with integer arguments & Homework obj

               << "minutes" << endl;  

        cout << "Summary of time for the assignments that required [double] : "

               << AddTwoValues( 30.28 , 49.18 )//with double arguments & Homework obj

               << "minutes" << endl;

        //cout << "The result of addition : " << homework3 << endl;

        system( "pause" );//Pause window

        return 0;//Terminate the program

}

#include <iostream>

#include <string>

using namespace std;

//Class Homework

class Homework{

        //...Member function for class Homework...

//Private data for class Homework

private:

        //Local and private variable

        string className;

        string assignment;

        int numOfminutes;

//Public data for class Homework     

public:

        Homework();//Constructor

        void setClassName( string );//Mutator for set class name

        string getClassName();//Accessor to get class name

        void setAssignment( string );//Mutator for set assignment

        string getAssignment();//accessor to get assignment

        void set_numOfminutes( int );

        int get_numOfminutes( );

        Homework operator+(Homework);//overloading operator + to add the minutes required by multiple Homework object

};

//Template function that return sum of the two parameters

T AddTwoValues(T value1 , T value2 ){

return value1 + value2;

}

//Overloading operator+

Homework Homework :: operator+ (Homework hw){

        Homework hw_result = *this;

        hw_result.numOfminutes += hw.numOfminutes;

        return hw_result;

}

//Constructor

//Initialize the variable for string & int

Homework :: Homework(){

        className = "";

        assignment = "";

        numOfminutes = 0;

}

//Mutator

void Homework :: setClassName( string theClassName ){

        className = theClassName;

        numOfminutes = 0;

}

//Accessor

string Homework :: getClassName(){

        return className;

}

//Mutator

void Homework :: setAssignment( string theAssignment ){

        assignment = theAssignment;

}

//Accesor

string Homework :: getAssignment(){

        return assignment;

}

void Homework :: set_numOfminutes( int theminutes ){

        numOfminutes = theminutes;

}

int Homework :: get_numOfminutes(){

        return numOfminutes;

}

int main(){

        //Set multiple Homework object

        Homework thehomework1 , thehomework2;

        thehomework1.setClassName( "PSDC Batch 18 CE");

        thehomework1.setAssignment( "Read Chapter 11" );

        thehomework1.set_numOfminutes( 150 );

       

        thehomework2.setClassName( "Inti Batch 1 CS" );

        thehomework2.setAssignment( "Read Chapter 22" );

        thehomework2.set_numOfminutes( 280 );

        Homework homework3 = thehomework1 + thehomework2;

        cout << "Name for first class : " << thehomework1.getClassName() << endl

               << "Assignment title      : " << thehomework1.getAssignment() << endl << endl

               << "Number of minutes that will take to complete assignment : " << thehomework1.get_numOfminutes() << endl << endl

               << "Name for second class : " << thehomework2.getClassName() << endl

               << "Assignment title      : " << thehomework2.getAssignment() << endl << endl

               << "Number of minutes that will take to complete assignment : " << thehomework2.get_numOfminutes() << endl << endl ;

        cout << "Summary of time for the assignments that required [integer] : "

               << AddTwoValues( 30 , 40 )//with integer arguments & Homework obj

               << "minutes" << endl;  

        cout << "Summary of time for the assignments that required [double] : "

               << AddTwoValues( 30.28 , 49.18 )//with double arguments & Homework obj

               << "minutes" << endl;

        //cout << "The result of addition : " << homework3 << endl;

        system( "pause" );//Pause window

        return 0;//Terminate the program

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote