请解决这个问题,这个问题来自面向对象的编程 [英] Please solve this question , which is from object oriented programming

查看:85
本文介绍了请解决这个问题,这个问题来自面向对象的编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义一个抽象类利润,其中包含文本描述,雇主名称,提供可用利润数量的方法以及纯粹的虚拟方法getGain计算利润的实际收益。



定义从利润中继承的以下类:

•ChargedProfit用单一收入值和结果成本表示利润(利润的收益是减去两个值),

•TaxedProfit代表具有单一收入值和税收百分比的利润(利润收益是按百分比减少的收入),

•MultiProfit代表利润,重复获得单一收入价值(利润收益是收入价值的乘积)。



覆盖,对于以上各项类,虚方法getGain,使其返回给定类的Profit的实际增益。实现所有构造函数,析构函数,getter,setter和异常,使类的功能完整,以及运行下面提供的

代码所需的所有其他方法和异常。



定义收入,包括年份数,最大收益和收到的利润的动态列表。



实施以下内容该类的公共方法:

•一个能够将任意类型的新利润添加到列表第一个位置的收入列表中(控制最大增益,OverflowError应该是如果可以超过最大增益则抛出,

•一个能够将任意类型的新利润添加到列表最后位置的收入列表中(控制最大增益)也是如此),

•一个能够从收入中移除最后一笔利润的人(如果列表为空则抛出EmptyError异常),

•一个能够使用rem从列表中获得所有利润,

•一种方法,返回收入中所有利润的汇总收益。



超载索引operator([]),使Revenue可以直接访问列表中特定位置的任务(如果不存在则抛出IndexError异常)。超载左移操作员(<<>)打印收入数据和所有利润的详细信息。添加所有其他成员,这些成员需要

才能使类的功能完整或者需要运行下面的代码。



写一个测试所有类功能的程序,特别是应该启用以下代码:

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:

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





我尝试过的事情:



i试过这个。它属于继承类。其中我需要连接头文件和.cpp文件与项目。

会有两个头文件和两个.cpp文件并连接到peoject,其中包含main.cpp



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

推荐答案

定义一个抽象类利用文本描述,雇主名称,提供可用利润数量的方法和纯粹的虚拟方法获得利润,获得利润的实际收益。



以下是基类的声明:
"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 :
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.


您需要访问一些学习C ++ 等教程可以解决您的作业问题。



提示:安装Visual Studio并编写清晰的代码。将实现中的标题中的声明分隔为cpp文件。使用描述性名称。



祝你好运。
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.


这篇关于请解决这个问题,这个问题来自面向对象的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆