Question: hi, i want the program written in c++, =========================== Define a class called Toy with private members name , and cost of type double. The

hi, i want the program written in c++,

===========================

Define a class called Toy with private members name, and cost of type double. The class has the public members set(), a parameterized constructor with default values for the data members, and a destructor. The class includes a static data member totalCost of type double to calculate the total cost of all toys, and a static function getTotalCost().

Define a class called Child with private members name. The class has the public members set(), a parameterized constructor with default values for the data members, and a destructor. The class includes a static data member count of type int to count total number of children, and a static function getCount().

Implement all member functions of both classes.

Use the following driver produces the given sample of input / output:

int main()

{

double avg;

Child firstChild;

Child secondChild;

Child thirdChild;

firstChild.set("Ali", 1);

secondChild.set("Mariam", 2);

thirdChild.set("Omar", 1);

cout << "The total cost of all toys is: " << Toy::getTotalCost() << endl;

cout << "The total number of children is: " << Child::getCount() << endl;

avg = Toy::getTotalCost() / Child::getCount();

cout << "Average money spent on toys is: " << avg << endl << endl;

return 0;

}

Sample input / output:

Enter the name and cost of toy number: 1 for Ali: Teday 90

Enter the name and cost of toy number: 1 for Mariam: Fulla 120

Enter the name and cost of toy number: 2 for Mariam: Barbay 220

Enter the name and cost of toy number: 1 for Omar: Crash 45

The total cost of all toys is: 475

The total number of children is: 3

Average money spent on toys is: 158.333

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!