四川特产水果:帮我用C语言编个程序吧?!!!非常的感谢!!

来源:百度文库 编辑:高考问答 时间:2024/04/29 04:11:27
高手能帮忙编一下吗?!!会一题也行.

一 .编写一段程序,有一个汽车类vehicle,它具有一个需传递参数的构造函数,类中的数据成员:车轮个数weight放在保护段中,小车类car是它的私有派生类,其中包含载人数passenger_load,卡车类truck是vehicle的私有派生类,其中包含载人数passenger_load和载数量payload.每个类都有相关数据的输出函数.

二 .编造一个建筑物数据管理程序,建筑物为基类,有层数,房间数和总的使用面积等数据,派生出住宅和办公楼.住宅类有卧室,阳台,浴室数量,办公楼有电话数量等数据,各个类都要有基本操作的成员函数.
错了,是C++

独ぜ来→往 别耍我咯.虽然我不是高手,但也能大概看的懂啊!!

#include "iostream"
#include "stdio.h"
#include "ctime"

using namespace std;

void start();
void build();
void Bing();
void Gong();
void Kuang();
void Xiu();
void Exit();
void AI();
void AI_Bing();
void AI_Gong();
void AI_Kuang();
void AI_Xiu();

int life_me=1000;
int life_it=1000;
int bing_me=0;
int bing_it=0;
int money_me=100;
int money_it=100;

main()
{

while(life_me>0,life_it>0)
{
start();
build();
AI();
}
if(life_me<=0)
{
cout<<"你输了!"<<endl;
}
else if(life_it<=0)
{
cout<<"你赢了!"<<endl;
}
clock_t delay=5*CLOCKS_PER_SEC;
clock_t start=clock();
while(clock()-start<delay)
;
cin.get();
}

void start()
{
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"life:"<<life_me;
cout<<" money:"<<money_me;
cout<<" life_it:"<<life_it;
cout<<" money_it:"<<money_it<<endl;
cout<<"兵力:"<<bing_me;
cout<<" 兵力_it:"<<bing_it<<endl;
}

void build()
{
int choose;
cout<<"1 建兵 2进攻 3采矿 4维修 5退出";
cin>>choose;
switch(choose)
{
case 1:
{
Bing();
break;
}
case 2:
{
Gong();
break;
}
case 3:
{
Kuang();
break;
}
case 4:
{
Xiu();
break;
}
case 5:
{
Exit();
break;
}
default:
{
cout<<"超出范围!";
}

}
}

void Bing()
{
cout<<"建兵!";
if(money_me>=10)
{

bing_me=bing_me+10;
money_me=money_me-10;
}
else
{
cout<<"金钱不足";
}
}

void Gong()
{
cout<<"进攻!";

A: int y=1;
if(y<1||y>3)
{
goto A;
}
else
{

life_it=life_it-(bing_me);
bing_me=bing_me-bing_it;
if(bing_me<=0)
{
bing_me=0;
}
bing_it=bing_it-(bing_me/2);
if(bing_it<=0)
{
bing_it=0;
}
}

}

void Kuang()
{
money_me=money_me+10;
cout<<"采矿!";
}

void Xiu()
{
life_me=life_me+money_me;
money_me=0;
}

void Exit()
{
life_me=0;
life_it=0;
}

void AI()
{
int choose_it;
if(money_it<=50)
AI_Kuang();
else if(life_it<=500)
AI_Xiu();

else if((bing_me-bing_it)>=30)
AI_Bing();
else if(bing_it==0)
AI_Bing();
else
AI_Gong();

}

void AI_Bing()
{
if(money_it>=10)
{

bing_it=bing_it+10;
money_it=money_it-10;
}
else
{
cout<<"金钱不足";
}
}

void AI_Gong()
{
bing_me=bing_me-(bing_it/2);
if(bing_me<=0)
{
bing_me=0;
}

life_me=life_me-(bing_it);
bing_it=bing_it-bing_me;
if(bing_it<=0)
{
bing_it=0;
}
}

void AI_Kuang()
{
money_it=money_it+10;
}

void AI_Xiu()
{
life_it=life_it+money_it;
money_it=0;
}

楼上的好卖力