C++作业题,高手进来啊!!!悬赏100分

[复制链接]
查看11 | 回复2 | 2009-6-8 16:32:31 | 显示全部楼层 |阅读模式
完整题目是:建立一个多边形 base class,然后建立基于base class的两个子class,分别为正方形和等边三角形class,在两个子class中分别建立两个函数实现周长和面积的分别计算。在main函数中进行打印输出到界面
编程要点:1,
Class的概念2,
Function 的概念3,
在base class 中使用虚函数Virutal的概念4,
在class中使用构造,析构函数的使用。#include



Class CPolygon {

protected:

int width, height;

public:

void set_values (int a, int b) { width=a; height=b;}

};



class CRectangle: public CPolygon {

public:

int area (void){ return (width * height); }

};



class CTriangle: public CPolygon {

public:

int area (void){ return (width * height / 2); }

};



int main () {

CRectangle rect;

CTriangle trgl;

rect.set_values (4,5);

trgl.set_values (4,5);

cout#include using namespace std;#include "aa.h"int main () { CRectangle rect; CTriangle trgl; rect.set_values (4,5); trgl.set_values (5,5); cout << rect.area() << endl; cout << trgl.area() << endl; cout << rect.perimeter() << endl; cout << trgl...
回复

使用道具 举报

千问 | 2009-6-8 16:32:31 | 显示全部楼层
做一个头文件polygon.h写入下面的代码#pragma once#include using namespace std;class CPolygon{protected: int width,height;public: CPolygon(int a=1,int b=1):width(...
回复

使用道具 举报

千问 | 2009-6-8 16:32:31 | 显示全部楼层
#includeusing namespace std;class polygon{public: polygon(int h=0,int w=0):height(h),width(w){} ~polygon(){cout<<"This is destructor function."<<endl;} virt...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行