IGI2000
23-11-2005, 10:50 PM
السلام عليكم
شباب شوفوا هذا الكود وقولولي على الخطأ اللي في
اناعملت البرنامج بس اريده لما يستدعي العضو draw()l يستدعيه حسب ماهو مطلوب بس ما عرفت ايش الخطا في
#include <iostream.h>
class shape
{
public:
shape(){}
virtual ~shape(){}
virtual void draw(){cout<<"You hade not choice the shape "<<endl;}
};
class rectangle:public shape
{
int itslength;
int itswidth;
public:
rectangle(int len,int wid):itslength(len),itswidth(wid){}
virtual ~rectangle(){}
virtual void draw();
};
void rectangle::draw()
{
for(int i=0;i<itslength;i++)
{
for(int j=0;j<itswidth;j++)
cout<<"*";
cout<<endl;
}
}
class square:public rectangle
{
int itslength;
int itswidth;
public:
square(int len,int wid):rectangle(len,wid){}
~square(){}
void draw();
};
void square::draw()
{
for(int i=0;i<itslength;i++)
{
for(int j=0;j<itslength;j++)
cout<<"*";
cout<<endl;
}
}
void main()
{
int len,wid;
cout<<"Enter the length of the shape you want to draw :";
cin>>len;
cout<<"Enter the width of the shape you want to draw :";
cin>>wid;
shape *draw;
int i;
char choice;
for(i=0;i<1;i++)
{
cout<<"1.Rectangle ."<<endl;
cout<<"2.square ."<<endl;
cout<<"Please choose the shape you want to draw :";
cin>>choice;
switch(choice)
{
case '1':draw=new rectangle(len,wid);
case '2':draw=new square(len,wid);
default:draw=new shape();
}
}
for(i=0;i<1;i++)
{
draw->draw();
}
}
اعرف ان الخطأ في ال switch الاخيرة بس ايش لازم اسوي علشان لما استدعي ال draw()l يستدعي الصحيحة
وشكرا
شباب شوفوا هذا الكود وقولولي على الخطأ اللي في
اناعملت البرنامج بس اريده لما يستدعي العضو draw()l يستدعيه حسب ماهو مطلوب بس ما عرفت ايش الخطا في
#include <iostream.h>
class shape
{
public:
shape(){}
virtual ~shape(){}
virtual void draw(){cout<<"You hade not choice the shape "<<endl;}
};
class rectangle:public shape
{
int itslength;
int itswidth;
public:
rectangle(int len,int wid):itslength(len),itswidth(wid){}
virtual ~rectangle(){}
virtual void draw();
};
void rectangle::draw()
{
for(int i=0;i<itslength;i++)
{
for(int j=0;j<itswidth;j++)
cout<<"*";
cout<<endl;
}
}
class square:public rectangle
{
int itslength;
int itswidth;
public:
square(int len,int wid):rectangle(len,wid){}
~square(){}
void draw();
};
void square::draw()
{
for(int i=0;i<itslength;i++)
{
for(int j=0;j<itslength;j++)
cout<<"*";
cout<<endl;
}
}
void main()
{
int len,wid;
cout<<"Enter the length of the shape you want to draw :";
cin>>len;
cout<<"Enter the width of the shape you want to draw :";
cin>>wid;
shape *draw;
int i;
char choice;
for(i=0;i<1;i++)
{
cout<<"1.Rectangle ."<<endl;
cout<<"2.square ."<<endl;
cout<<"Please choose the shape you want to draw :";
cin>>choice;
switch(choice)
{
case '1':draw=new rectangle(len,wid);
case '2':draw=new square(len,wid);
default:draw=new shape();
}
}
for(i=0;i<1;i++)
{
draw->draw();
}
}
اعرف ان الخطأ في ال switch الاخيرة بس ايش لازم اسوي علشان لما استدعي ال draw()l يستدعي الصحيحة
وشكرا