Click here to Skip to main content
15,910,358 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Define an abstract class Profit with a text description, a name of an employer, a method providing the number of Profits available and the pure virtual method getGain computing the real gain of a profit.

Define the following classes inherited from the Profit:
• ChargedProfit representing the profit with a single income value and a cost of outcomes (the gain of the profit is the subtraction of the two values),
• TaxedProfit representing the Profit with a single income value and a percent of taxes (the gain of the profit is the income reduced by the percentage),
• MultiProfit representing the Profit with a single income value gained repeatedly (the gain of the profit is the multiplication of the income value).

Override, for each of the above classes, the virtual method getGain, making it to return the real gain of a Profit of the given class. Implement all the constructors, destructors, getters, setters and exceptions which make the functionality of the classes complete, and all the other methods and exceptions necessary to run the
code provided below.

Define the class Revenue with a year number, a maximal gains and a dynamic list of the profits received.

Implement the following public methods of the class:
• a one enabling to add a new profit of an arbitrary type to the revenue list on the first position of the list (with the control of the maximal gain, OverflowError should be thrown if the maximal gain could be exceeded),
• a one enabling to add a new profit of an arbitrary type to the revenue list on the last position of the list (with the control of the maximal gain, too),
• a one enabling to remove the last profit from the revenue (throwing the EmptyError exception if the list is empty),
• a one enabling to remove all the profits from the list,
• a method returning the summary gain of all the profits in the revenue.

Overload the indexing operator ([]) for the Revenue to have a direct access to the task on the particular position in the list (throwing the IndexError exception if it doesn't exist). Overload the shift-left operator (<<) printing the data of the revenue and the details of all the profits. Add all the other members which are
necessary to make the functionality of the class complete or are required to run the code below.

Write a program which tests all the class capabilities, in particular the following code should be enabled:
C++
Revenue calc(2014, 10000); //max=10000
cout << Profit::count(); //0
try {
 calc.addFirst(new ChargeProfit("sale", "Allegro", 8000, 6000)); //8000-6000
 calc.addFirst(new TaxedProfit("wages", "Boss", 9000, 18)); //18% of taxes
 calc.addLast(new MultiProfit("tutoring", "Johny", 100, 6)); //6x100
 calc.addLast(new TaxedProfit("project", "UE", 3000, 30)); //30% of taxes
} catch(Revenue::OverflowError &e) {
 cout << e.what(); //gain for 'project' is too large
}
cout << calc;
//Revenue 2014, maximal gain: 10000.00, total gain: 9980.00:
//1. wages (Boss), gain: 7380.00
//2. sale (Allegro), gain: 2000.00
//3. tutoring (Johny), gain: 600.00
cout << Profit::count(); //3
cout << calc.summaryGain() << endl; //9980.00
calc.removeLast();
cout << Profit::count(); //2
cout << calc.summaryGain() << endl; //9380.00
try {
 cout << calc[1].getGain() << endl; //7380.00
 cout << calc[4].getGain() << endl; //IndexError exception
} catch(Revenue::IndexError &e) {
 cout << e.what(); //item no. 4 not found
}
calc.clear();
cout << Profit::count(); //0


What I have tried:

i tried this. it is belongs to inherieted class. in which i need to connect header file and .cpp file with project.
there would be two header file and two .cpp file and connected to peoject which contain main.cpp
Posted
Updated 10-Feb-19 7:14am
v2
Comments
Rick York 9-Feb-19 21:33pm    
I see no reason that two header files and two sources files are required. The Profit class and its derivatives can all be in one header and the implementation of all of the classes could be in one .cpp file if you want to do it that way.

You need to try a little harder. This is very basic C++ stuff that is being asked and you should be able to do all of it if you hope to progress at all. If you don't hope to progress why should anyone else waste their time?

"Define an abstract class Profit with a text description, a name of an employer, a method providing the number of Profits available and the pure virtual method getGain computing the real gain of a profit."

Here is the declaration of the base class :
C++
class Profit
{
public:
    std::string  m_description;
    std::string  m_employer;

public:
    static int count();
    double     getGain() = 0;   // derivations must implement this
};
I will leave the rest of it to you because YOU need to do this. You will learn nothing if someone else does it for you.

Note that this declaration is not complete. There is no constructor defined so you will need to add that. You should be able to figure out what it looks like by how the constructors for the derived classes look and you can see those by looking at the code requirement you posted.
 
Share this answer
 
v3
You need to visit some tutorials like Learn C++ to solve your homeworks.

Tip: install Visual Studio and write clear code. Separate declaration in the header in implementation into cpp files. Use describtive names.

Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900