hi 2 all, I have an assignment about classes, everything IS OK , except of the draw function of a square.(after running the prog. there is no square drawn )
this wt I did till now:
class Square{
private:
int sidelength;
char ch;
public:
Square();//default constructor
void setSidelength(int);//sets default values
double getSidelength(int);//gets the values
double getArea();//calculates the area of the square
double getPerimeter();//calculates the perimeter of the square
void draw(int,char);
};//end square.h
#include<iostream>
#include"Square.h"
using namespace std;
int L;
char ch;
int s=4;
int line, loop;
Square::Square()//default constructor
{
sidelength=1;
}
void Square::setSidelength(int L)//sets default values to side
{
if (L>0 && L<20)
sidelength=L;
}
double Square::getSidelength(int L)//gets the value for
{
return sidelength;
}
double Square::getArea()//calculates area of square
{
return sidelength*sidelength;
}
double Square::getPerimeter()//calculates the circumference of the square
{
return (4*sidelength);
}
void Square::draw (int sidelength,char ch)
{
for (line=1;line<=s;line++)
{
for (loop=1;loop<=s;loop++)
cout<<" ";
cin>>ch;
cout<<endl;
}
}
void main()
{
int n;
char ch;
int sidelength;
Square Sqr;
cout<<"Two Dimensional Shapes System:\n";
cout<<"[1] Square\n";
cout<<"[2] Rectangle\n";
cout<<"[3] Triangle\n";
cout<<"[4] Circle\n";
cout<<"[5] Exit\n";
cout<<"Enter your choice from the menu list: ";
cin>>n;
if(n==1){
cout<<"Enter the square sidelength:";
cin>>sidelength;
Sqr.setSidelength(sidelength);
cout<<"The Perimeter = "<<Sqr.getPerimeter()<<endl;
cout<<"The area ="<<Sqr.getArea()<<endl;
cout<<"Enter the character symbol for drawing: ";
cin>>ch;
cout<<"The rectangle is shown as:"<<endl;
Sqr.draw(sidelength,ch);
}
}
please try to help as possible :)