shape drawer class

tkud 0 Tallied Votes 187 Views Share

This code draws different shapes to the screen,(in this version, only a square or a cross. It will be updated soon!!).
This code was written by a beginner, for the beginners!!

//This is the code for drawing a square
#include<iostream>
using namespace std;
class square
{
 public:
 int h,w;
 square(){
 cout<<"Square's constructor!!"<<endl;
 h=0;
 w=0;
 }
 ~square(){
 cout<<"Square's destructor!!"<<endl;
 }
 public:void drawsquare(){
 cout<<"This program draws a square."<<endl;
 cout<<"Enter the height and width respectively.."<<endl;
 cin>>h;
 cout<<endl;
 cin>>w;
 cout<<endl;
 for(int i=0;i<h;i++){
 cout<<endl;
 for(int x=0;x<w;x++){
 cout<<"*";
 }
 }
 cout<<endl<<endl;
}
};
//This is the code for drawing a cross
#include<iostream>
using namespace std;

class cross
{
 public:
 int h,w;
 cross(){
 cout<<"Cross's constructor!!"<<endl;
 h=0;
 w=0;
 }
 ~cross(){
 cout<<"Cross's destructor!!"<<endl;
 }
 public:void drawcross(){
 cout<<"This program draws a cross"<<endl;
 cout<<"Please enter the height and width, respectively.."<<endl;
 cin>>h;
 cout<<endl;
 cin>>w;
 cout<<endl;
 int t=(h/2)+1;
 for(int i=0;i<(h/2);i++){
 for(int i=0;i<(w/2);i++){
 cout<<" ";
 }
 cout<<"*"<<endl;
 }
 for(int i=0;i<w/2;i++){
 cout<<"*";
 }
 cout<<" ";
  for(int i=0;i<w/2;i++){
 cout<<"*";
 }
 cout<<endl;
 for(int i=0;i<t;i++){
 for(int i=0;i<(w/2);i++){
 cout<<" ";
 }
 cout<<"*"<<endl;
 }
 }
};
//Then,this is a driver program for implementation
//Written by Kudayisi tobi,8th Oct.,2009...all rights reserved
#include"square.cpp"
#include"cross.cpp"
#include<iostream>
using namespace std;

int main()
{
 int choice=0;
 cout<<"This is a driver program that tests my new classes,cross and square."<<endl;
 cout<<"This program draws many shapes on the screen(depending on your choice)"<<endl;
 cout<<"(0)quit,(1)square,(2)cross....";
 cin>>choice;
 if(choice==0){
 return 1;
 }
 if(choice==1){
 square x;
 x.drawsquare();
 }
 else
 if(choice==2){
 cross y;
 y.drawcross();
 }
cout<<"Thank you!!"<<endl;
return 0;
}

This code is for beginners who can't decipher their heads from their toes in c++
Hope this helped!!