- UID
- 28208
- 帖子
- 18803
- 积分
- 56605
- 阅读权限
- 90
- 注册时间
- 2006-9-4
- 最后登录
- 2015-6-1
- 在线时间
- 12541 小时
- 战队
- [SvS]
- 联赛ID
- PY_Shmily
- 种族
- Protoss
- 战队
- [SvS]
- 联赛ID
- PY_Shmily
- 种族
- Protoss
|
第一个上传作业 忽忽
#include<iostream>
using namespace std;
class Rectangle
{
protected:
int Length,Width;
public:
Rectangle(int x=0,int y=0)
{
Length=x;
Width=y;
}
int GetLength()
{
return Length;
}
int GetWidth()
{
return Width;
}
void Area(int area=0)
{
area=Length*Width;
cout<<"面积为"<<area<<endl;
}
void display()
{
cout<<Length<<","<<Width;
}
};
class Cuboid:public Rectangle
{
protected:
int Height;
int Volume;
public:
Cuboid(int x=0,int y=0,int z=0):Rectangle(x,y)
{
Height=z;
}
int GetHeight()
{
return Height;
}
int Vol()
{
Volume=Length*Width*Height;
return Volume;
}
void Show()
{
cout<<"高为"<<Height<<"长和宽为";
Rectangle::display();
cout<<"的长方体体积为"<<Vol()<<endl;
}
};
void main()
{
Cuboid cub(10,20,30);
cub.Show();
}
#include<iostream>
using namespace std;
class Vehicle
{
protected:
int wheels;
int weight;
public:
Vehicle(int x=0,int y=0)
{
wheels=x;
weight=y;
}
int Getwheels()
{
return wheels;
}
int Getweight()
{
return weight;
}
void display()
{
cout<<"车轮数为"<<wheels<<"汽车重量为"<<weight;
}
};
class car:public Vehicle
{
private:
int passengers_load;
public:
car(int x=0,int y=0,int z=0):Vehicle(x,y)
{
passengers_load=z;
}
int Getpassengers_load()
{
return passengers_load;
}
void dispaly()
{
cout<<"小汽车";
Vehicle::display();
cout<<"载客数为"<<passengers_load<<endl;
}
};
class Truck:public Vehicle
{
private:
int weight_load;
public:
Truck(int x=0,int y=0,int r=0):Vehicle(x,y)
{
weight_load=r;
}
int Getweight_load()
{
return weight_load;
}
void dispaly()
{
cout<<"卡车";
Vehicle::display();
cout<<"载重量为"<<weight_load<<endl;
}
};
void main()
{
car c(3,4,5);
c.dispaly();
}
顺便借8达保存一下代码 |
|