有几道C++的编程题,帮忙做一下,急!!好的追加分

来源:百度知道 编辑:UC知道 时间:2024/06/01 03:26:05
我是初学者,这几道题是应付考试的,尽量用初学者语言,明天就考试了,一共四道题,帮忙快点。
1、定义一个矩形类,长、宽为类的私有成员,从键盘输入长、宽的值,输出矩形的周长和面积。
2、职工类有编号,姓名、工资等成员,编程输出3个职工的信息,总工资和平均工资。
3、教室类有私有成员编号,姓名、生日类,有私有成员年、月、日。
4、从键盘输入十个数据,将其写入到磁盘文件f1.dat,再从f1.dat中,读入数据在显示器上显示出来。

第一题
#include <iostream>
using namespace std;

class rectangle
{
private:
double length;
double width;
public:
void setLength(double l){ length = l; }
void setWidth(double w){ width = w; }
double getGirth(){ return ( length+width )*2; }
double getArea(){ return length*width; }
};

int main()
{
double ll,ww;
rectangle rr;
cout<<"input the length:";
cin>>ll;
cout<<"input the width:";
cin>>ww;
rr.setLength( ll );
rr.setWidth( ww );
cout<<"the girth is:"<<rr.getGirth()<<endl;
cout<<"the area is:"<<rr.getArea()<<endl;
return 1;
}
第二题:
#include <iostream>
using namespace std;

class worker
{
public:
int num;
char *name;
double salary;

worker(int a , char *b