C++新手请教一个问题,谢谢。
今天在联系的时候写了这么个东西,但是一直有错误不知道是怎么回事。请帮忙看看,谢谢。
# include <iostream>
# include <string>
using namespace std;
class Building { //基本信息
public:
float LCS;
float FJS;
float ZMJ;
};
class Home : public Building {
public:
int WSS;
int KTS;
int WSJS;
int CFS;
void add1(float lcs,float fjs, float zmj, int wss, int kts, int wsjs, int cfs);
};
void Home::add1(float lcs, float fjs, float zmj,int wss, int kts, int wsjs, int cfs) {
LCS =lcs;
FJS =fjs;
ZMJ=zmj;
WSS=wss;
KTS=kts;
WSJS=wsjs;
CFS=cfs;
cout<<"住宅楼:"<<endl;
cout<<" 楼层数:"<<lcs<<" "<<"层"<<endl;
cout<<" 房间数:"<<fjs<<" "<<"间"<<endl;
cout<<" 楼房总面积:"<<zmj<<" "<<"平方米"<<endl;
cout<<"其中:\n";
cout<<" 卧室数:"<<wss<<" "<<"间"<<endl;
cout<<" 客厅数:"<<kts<<" "<<"间"<<endl;
cout<<" 卫生间数数:"<<wsjs<<" "<<"间"<<endl;
cout<<" 厨房数:"<<cfs<<" "<<"间"<<endl<<endl<<endl;
}
class Office:public Building {
public:
int BGSS;
int HYSS;
void add2(float lcs, float fjs, float zmj, int bgss,int hyss);
};
void Office::add2(float lcs, float fjs, float zmj, int bgss,int hyss){
LCS =lcs;
FJS =fjs;
ZMJ=zmj;
BGSS=bgss;
HYSS=hyss;
cout<<"办公室:"<<endl;
cout<<" 楼层数:"<<lcs<<" "<<"层"<<endl;
cout<<" 房间数:"<<fjs<<" "<<"间"<<endl;
cout<<" 楼房总面积:"<<zmj<<" "<<"平方米"<<endl;
cout<<"其中:"<<endl;
cout<<" 办公室数:"<<bgss<<" "<<"间"<<endl;
cout<<" 会议室数:"<<hyss<<" "<<"间"<<endl<<endl<<endl;
class Hospital:public Building {
public:
int BFS;
int Shoushu;
void add3(float lcs, float fjs, float zmj, int bfs,int shoushu);
};
void Hospital::add3(float lcs, float fjs, float zmj, int bfs,int shoushu) {
//存入对象数组中
LCS =lcs;
FJS =fjs;
ZMJ =zmj;
BFS=bfs;
Shoushu=shoushu;
cout<<"医院:"<<endl;
cout<<" 楼层数:"<<lcs<<" "<<"层"<<endl;
cout<<" 房间数:"<<fjs<<" "<<"间"<<endl;
cout<<" 楼房总面积:"<<zmj<<" "<<"平方米"<<endl;
cout<<"其中:"<<endl;
cout<<" 病房数:"<<bfs<<" "<<"间"<<endl;
cout<<" 手术室数:"<<shoushu<<" "<<"间"<<endl;
}
int main ()
{
Home h;
Hospital ho;
Office off;
h.add1(1,2,3,4,5,6,7);
ho.add3(1,2,2,3,5);
off.add2(1,2,4,5,2);
return 0;
}