设为首页收藏本站

八达网

 找回密码
 注册
查看: 140|回复: 4
打印 上一主题 下一主题

哈哈哈 终于独立完成2道C++题目了 看来我还是很有潜质\的

[复制链接]

101

主题

2

好友

5万

积分

光明执政官

[SvS]Heroes

战队
[SvS]
联赛ID
PY_Shmily
种族
Protoss

2010水友赛冠军 2009年度八达十大杰出青年

跳转到指定楼层
1
发表于 2008-5-15 15:15 |只看该作者 |倒序浏览
第一个上传作业 忽忽


#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达保存一下代码

31

主题

1

好友

3万

积分

版主

Rank: 7Rank: 7Rank: 7

战队
=CHZ=
联赛ID
Leo_Kira
种族
Zerg
2
发表于 2008-5-15 15:16 |只看该作者
恩 不错 比哥在大学时学的好
回复

使用道具 举报

2

主题

0

好友

6062

积分

大象

3
发表于 2008-5-15 16:22 |只看该作者
lz还需要加油啊
回复

使用道具 举报

41

主题

1

好友

7712

积分

大象

4
发表于 2008-5-15 16:28 |只看该作者
强大的一比啊,请楼猪教我面像对象吧
回复

使用道具 举报

0

主题

0

好友

1万

积分

航母

远离菠菜 珍爱生命

5
发表于 2008-5-15 16:50 |只看该作者
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|八达网    

GMT+8, 2026-3-31 13:01

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部