我这个C++程序有什么错误,大家帮我看看.....
题目是•定义抽象类Shape–成员变量:行数–成员函数:显示(display)–成员函数:设置行数(setline)•定义Shape的派生类–Tr...
题目是 •定义抽象类Shape
–成员变量:行数
–成员函数:显示(display)
–成员函数:设置行数(setline)
•定义Shape的派生类
–Triangular:可以向屏幕输出三角形星阵
–Rectangular:可以向屏幕输出方形星阵
–Parallelogram:可以向屏幕输出平行四边形星阵
•main函数定义如下:
Shape* S;
S=new Triangular(); S->setline(5);
S->display(); delete S;
S=new Rectangular(); S->setline(6);
S->display(); delete S;
S=new Parallelogram(); S->setline(7);
S->display(); delete S; •要求:完成上述所有类的定义,并使程序按预期输出
我的代码是
#include "stdafx.h"
#include<iostream>
using namespace std;
class Shape
{
public:
virtual void display() const{;}
virtual void setline(int &n) const{;}
int line;
}
class Triangular: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
class Rectangular: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
class Parallelogram: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
void Triangular:: display()
{ int t,l,h;
for(h=1;h<=line;h++){
for(t=0;t<line-h;t++){
cout<<' ';
}
for(l=1;l<=2*h-1;l++){
cout<<'*';
}
cout<<endl;
}
}
void Rectangular::display(){
int g;
for(g=0;g<line;g++){
cout<<"****************"<<endl;
}
}
void Parallelogram::display( ){
int f,e;
for(f=1;f<line;f++){
for(e=1;e<=line-f;e++){
cout<<' ';
}
cout<<"****************"<<endl;
}
}
int main()
{
Shape* S;
S=new Triangular(); S->setline(5);
S->display(); delete S;
S=new Rectangular(); S->setline(6);
S->display(); delete S;
S=new Parallelogram(); S->setline(7);
S->display(); delete S;
} 展开
–成员变量:行数
–成员函数:显示(display)
–成员函数:设置行数(setline)
•定义Shape的派生类
–Triangular:可以向屏幕输出三角形星阵
–Rectangular:可以向屏幕输出方形星阵
–Parallelogram:可以向屏幕输出平行四边形星阵
•main函数定义如下:
Shape* S;
S=new Triangular(); S->setline(5);
S->display(); delete S;
S=new Rectangular(); S->setline(6);
S->display(); delete S;
S=new Parallelogram(); S->setline(7);
S->display(); delete S; •要求:完成上述所有类的定义,并使程序按预期输出
我的代码是
#include "stdafx.h"
#include<iostream>
using namespace std;
class Shape
{
public:
virtual void display() const{;}
virtual void setline(int &n) const{;}
int line;
}
class Triangular: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
class Rectangular: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
class Parallelogram: public Shape
{
public:
virtual void display();
virtual void setline(int &n){line=n;}
}
void Triangular:: display()
{ int t,l,h;
for(h=1;h<=line;h++){
for(t=0;t<line-h;t++){
cout<<' ';
}
for(l=1;l<=2*h-1;l++){
cout<<'*';
}
cout<<endl;
}
}
void Rectangular::display(){
int g;
for(g=0;g<line;g++){
cout<<"****************"<<endl;
}
}
void Parallelogram::display( ){
int f,e;
for(f=1;f<line;f++){
for(e=1;e<=line-f;e++){
cout<<' ';
}
cout<<"****************"<<endl;
}
}
int main()
{
Shape* S;
S=new Triangular(); S->setline(5);
S->display(); delete S;
S=new Rectangular(); S->setline(6);
S->display(); delete S;
S=new Parallelogram(); S->setline(7);
S->display(); delete S;
} 展开
2个回答
2012-05-08
展开全部
问一下 你这是抽象类么?你的纯虚函数呢??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询