求大神帮忙啊,一道c++作业

2024-11-02 19:27:14
推荐回答(1个)
回答1:

#include"iostream.h"
#include"windows.h"
#include"conio.h"
class Point
{
private:
int x;
int y;
public:
void setPoint(int a,int b)
{
x=a;
y=b;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
};
class CRectangle:public Point
{
private:
int length;
int width;
public:
void showRectangle(int c,int d)
{
int i,j;
length=c;
width=d;
cout<<"┏";
for(i=1;i<30;i++)
cout<<"━";
cout<<"→"<<"x";
for(i=1;i {
cout< cout<<"┃";
}
cout< if(getY()!=0)
{
if(getX()!=0)
cout<<"┃";
for(i=1;i cout<<" ";
cout<<"┏";
for(i=1;i cout<<"━";
cout<<"┓";
cout< }
for(i=1;i {
cout<<"┃";
for(j=1;j cout<<" ";
if(getX()!=0)
cout<<"┃";
for(j=1;j cout<<" ";
cout<<"┃"< }
if(getX()!=0)
cout<<"┃";
for(i=1;i cout<<" ";
cout<<"┗";
for(i=1;i cout<<"━";
cout<<"┛";
cout< for(i=1;i<10;i++)
{
cout<<"┃";
cout< }
cout<<"↓"< }
void Move(int *a,int *b)
{
cout<<"请输入想修改的左上角的坐标x:";
cin>>*a;
while(*a<0)
{
cout<<"请输入一个正值:";
cin>>*a;
}
cout<<"请输入想修改的左上角的坐标y:";
cin>>*b;
while(*b<0)
{
cout<<"请输入一个正值:";
cin>>*b;
}
setPoint(*a,*b);
}
void Size(int *c,int *d)
{
cout<<"请输入想修改的矩形的长:";
cin>>*c;
while(*c<0)
{
cout<<"请输入一个正值:";
cin>>*c;
}
cout<<"请输入想修改的矩形的宽:";
cin>>*d;
while(*d<0)
{
cout<<"请输入一个正值:";
cin>>*d;
}
length=*c;
width=*d;
}
void Where()
{
cout<<"("< }
void Area()
{
cout< }
};
void main()
{
HANDLE e;
COORD f={0,0};
e=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(e,f);
SetConsoleTextAttribute(e,0x01|0x08);
CRectangle r;
int a=1,b=2,c=4,d=3;
char i='0';
r.setPoint(a,b);
r.showRectangle(c,d);
while(i!='5')
{
cout<<"按1移动矩形:"< cout<<"按3返回左上角坐标值:"< i=getch();
if(i=='1')
{
r.Move(&a,&b);
r.showRectangle(c,d);
}
if(i=='2')
{
r.Size(&c,&d);
r.showRectangle(c,d);
}
if(i=='3')
r.Where();
if(i=='4')
r.Area();
}
}
这个是我自己做的矩形类,你自己拿去删除一些修改一下,有什么问题再问我吧,顺便求采纳