0
点赞
收藏
分享

微信扫一扫

UJN_C++_1403 【C++对象和类】teacher类

Separes 2022-03-25 阅读 25
c++
//
Problem C: 【C++对象和类】teacher类
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 614  Solved: 509
[Submit][Status][Web Board]
Description
定义teacher类,私有数据成员包括:jobNO(工号 字符串),Name(姓名 字符串)和基本工资(base_pay),补贴(allowance), 保险金(insurance),工资总和,实发工资,均为double型,成员函数包括:

(1)构造函数2个,一个含2个参数,分别为工号,姓名,其他值都默认为0;另一个含工号、姓名和基本工资、补贴、保险金,工资总和与实发工资的值默认为0

(2)计算应发工资和实发工资的函数,函数名统一用salary。

工资总和=基本工资+补贴; 实发工资=工资总和—保险金

(3)显示教师信息函数,各信息之间用空格隔开,函数名统一用display

(4)输入教师基本工资、补贴、保险金的函数,函数名统一用input

要求在main函数中创建2个教师对象,第1个对象需要用input函数输入基本工资、补贴、保险金,第2个教师对象由参数给出基本工资、补贴、保险金,然后计算出2个教师的工资总和及实发工资,最后输出这2个教师的信息。main函数部分代码如下:

int main()

{

teacher t1("111", "Mary"),t2("222","Alex",4256.78,1234.56, 895.17) ;

 

….            // 请补充 其他代码

 

return0;

}

Input
输入基本工资、补贴、保险金的金额,用空格分开

Output
输出教师的信息,按工号、姓名、基本工资、补贴、保险金、工资总和、实发工资,每一个数据之间用空格隔开,每个教师的信息占一行。

Sample Input
6589.45 1549.21 985.47
Sample Output
111 Mary 6589.45 1549.21 985.47 8138.66 7153.19
222 Alex 4256.78 1234.56 895.17 5491.34 4596.17

// 	1403 Problem  C	【C++对象和类】teacher类
#include<bits/stdc++.h>
using namespace std;

class teacher
{
    private:
        string id,name;
        double a,b,c,sum,d;
    public:
        teacher( string s1,string s2 )
            { id=s1; name=s2; a=b=c=d=sum=0; }
        teacher( string s1,string s2,double x,double y,double z )
            { id=s1; name=s2; a=x; b=y; c=z; d=sum=0; }
					
					// double
        void in() { double x,y,z; cin>>x>>y>>z; a=x; b=y; c=z; }
        void sum_f() { sum=a+b; d=sum-c; }
        void out()
        {
            cout<<id<<' '<<name<<' '<<fixed<<setprecision(2)<<a<<' '<<b<<' '<<c<<' '<<sum<<' '<<d<<endl;  
        }
};

int main()
{
    teacher t1( "111","Mary" ),t2( "222","Alex",4256.78,1234.56, 895.17 );

    t1.in();
    t1.sum_f(); t1.out();
    t2.sum_f(); t2.out();

    return 0;
}

举报

相关推荐

0 条评论