C++ 面向对象编程作业(三)

https://blog.slightwind.cn/

5-5-4简易工资管理

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
class Employee
{
	protected:
		string name;   //姓名
		int working_years;   //工龄
	public:
		Employee(string nm="unnamed",int wy=0);
		string Getname();
		double ComputePay();    //求工龄工资,就是:工龄*35
		void SetWorkyears(int wy);
};
Employee::Employee(string nm,int wy){
    name=nm;
    working_years=wy;
}
string Employee::Getname(){
     return name;
}
double Employee::ComputePay(){
    return working_years*35;
}
void Employee::SetWorkyears(int wy){
    working_years=wy;
}

class Worker:public Employee
{
private:
    double pay_per_hour;  //每小时工资额
	int work_time;             //当月工作时数
public:
    Worker(string nm,int wy,int wt);
    double count_pay();             //计算工资,按上面说明的计算规则
	void SetWorktime(int wt);    //设置当月工作时数
	void Setpay_per_hour(int x);  //设置每小时工资额
};

Worker::Worker(string nm,int wy,int wt)
{
    name=nm;
    working_years=wy;
    work_time=wt;
}
double Worker::count_pay(){
    return pay_per_hour*work_time+ComputePay();
}
void Worker::SetWorktime(int wt){
    work_time=wt;
}
void Worker::Setpay_per_hour(int x){
    pay_per_hour=x;
}


class SalesPerson:public Employee
{
private:
    double pay_per_hour;   //每小时工资额
	double saleroom;       //当月售出商品金额
	int work_time;         //当月工作时数
public:
    SalesPerson(string nm,int wy,int wt,double sr);
    double count_pay();           //计算工资,按上面说明的计算规则
	void SetWorktime(int wt);     //设置当月工作时数
	void Setpay_per_hour(int x);  //设置每小时工资额
	void Setsalesroom(double sr); //设置当月售出商品金额
};

SalesPerson::SalesPerson(string nm,int wy,int wt,double sr)
{
    name=nm;
    working_years=wy;
    work_time=wt;
    saleroom=sr;
}
double SalesPerson::count_pay(){
    return pay_per_hour*work_time+saleroom*0.01+ComputePay();
}
void SalesPerson::SetWorktime(int wt){
    work_time=wt;
}
void SalesPerson::Setpay_per_hour(int x){
    pay_per_hour=x;
}
void SalesPerson::Setsalesroom(double sr){
    saleroom=sr;
}

class Manager:public Employee
{
private:
    /* data */
public:
    Manager(string nm,int wy);
    double count_pay();    //计算工资,按上面说明的计算规则
};

Manager::Manager(string nm,int wy)
{
    name=nm;
    working_years=wy;
}
double Manager::count_pay(){
    return 1000+ComputePay();
}

int main()
{
	Worker work("zhangqiang",3,200);
	work.Setpay_per_hour(50);
	cout<<"工资="<<work.count_pay()<<endl;
	work.SetWorktime(180);
	work.SetWorkyears(10);
	work.Setpay_per_hour(30);
	cout<<work.Getname()<<"  "<<work.count_pay()<<endl;


	SalesPerson sales("wangjun",5,300000,25);



	sales.SetWorktime(40);
	sales.Setpay_per_hour(80);
	sales.Setsalesroom(450000);
	cout<<sales.Getname()<<"  "<<sales.count_pay()<<endl;



	Manager mana("sunchao",20);
	cout<<mana.Getname()<<"  "<<mana.count_pay()<<endl;
	return 0;
}

5.2+ 长方体计算

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
class square
{
protected:
    float length;  
    float width;  
public:
    square(float l=0,float w=0);
    float area();  //计算面积
    void disp();  //显式结果(矩形的面积)
};
square::square(float l,float w){
    length=l;
    width=w;
}
float square::area(){
    return length*width;
}
void square::disp(){
    cout<<area();
}

class longSquare:public square
{
private:
    float height; //长方体的高
public:
    longSquare(float l,float w,float h);
    float calv();  //计算长方体的体积
    void disp();  //显式结果(底面积以及长方体的体积)
};

longSquare::longSquare(float l,float w,float h)
{
    length=l;
    width=w;
    height=h;
}
float longSquare::calv(){
    return height*area();
}
void longSquare::disp(){
    cout<<area()<<" "<<calv()<<endl;
}
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    longSquare Square(a,b,c);
    Square.disp();
    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风好衣轻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值