C++编程求助,有题求编

来源:百度知道 编辑:UC知道 时间:2024/06/24 05:30:11
下面是题目要求

1、试建立一个类Sale用于描述销售活动,具体要求如下:

l 私有数据成员

int sid: 商品编号。

float price: 商品价格。

int quantity: 该商品库存数量。

l 公有成员函数

(1) 缺省构造函数:初始化数据成员为0或NULL值。

(2) 带参构造函数:用参数初始化数据成员。

(3) void List( ): 输出本对象的数据信息。

(4) void Modify(… ): 用给定的参数修改数据成员的值。(自己定义参数)

(5) int Sell(int n):卖出本商品n件。先比较quantity和n值,若quantity ≥n,计算应付金额total(n>10优惠10%,n>30优惠20%)。修改该商品库存数量quantity,输出商品编号、价格、购买数量与应付金额,并返回1。否则,显示提示信息“库存数量不够”和quantity值并返回0。

2、试建立一个类Worker用于描述职工对象,具体要求如下:

l 私有数据成员

int id: 职工号。

float wage: 工资。

char level: 技术等级 (A—一等,B—二等,C—三等,NULL—无级,其它为无效)

l 公有成员函数

(1) 缺省构造函数:初始化数据成员为0或NULL值。

(2) 带参构造函数:用参数初始化数据成员 (需判断参数是否有效)。

(3) 输出函数void List( ):输出本职工的各项信息。

(4) 修改函数void Set( ):从键盘输入新的职工号、工资和等级数据,修改相应数据成员的值。接受输入前屏幕上显示提示输入哪些信息。

(5) 升级函数void Up( ): 为职工增加工

那么多题一股脑塞这来了。。。。

帮你做了第一题。。。
#include <iostream>
using namespace std;

class Sale
{
private:
int sid;
float price;
int quantity;
public:
Sale()
{
sid=0;
price=0;
quantity=0;
}
Sale(int sid,float price,int quantity)
{
this->sid=sid;
this->price=price;
this->quantity=quantity;
}

void List()
{
cout<<"商品编号为:"<<sid<<endl;
cout<<"商品价格为:"<<price<<endl;
cout<<"商品库存为:"<<quantity<<endl;
}

void Modify(int sid,float price,int quantity)
{
this->sid=sid;
this->price=price;
this->quantity=quantity;
}

int Sell(int n)
{
float total;//总价
int remain;//剩余库存

if(quantity>=n)
{
if(n>10 && n<=30)
{
total=p