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

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;
}

发布了9 篇原创文章 · 获赞 17 · 访问量 884

猜你喜欢

转载自blog.csdn.net/qq_41956187/article/details/105567637