This is a simple program that displays a menu of choices and then displays shapes through function calls. Any help would be appreciated!!!!
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void drawRectangle();
void drawSquare();
void drawRightTriangle();
void drawETriangle();
void drawDiamond();
void main()
{ //start main function
char choice=0;
int done=0;
//display menu choices
//do
//{
cout<<"Welcome to the shape demonstration program.\n";
cout<<"Choose one of the menu options below to see a sample of the shape.\n";
cout<<endl<<endl;
cout<<setw(5)<<"1. "<<"Rectangle\n\n";
cout<<setw(5)<<"2. "<<"Square\n\n";
cout<<setw(5)<<"3. "<<"Right Triangle\n\n";
cout<<setw(5)<<"4. "<<"Equilateral Triangle\n\n";
cout<<setw(5)<<"5. "<<"Exit the program\n";
cout<<endl;
cin>>choice;
switch (choice) //switch is like nested if statements
{ //start switch
case '1':
drawRectangle();
break;
case '2':
drawSquare();
break;
case '3':
drawRightTriangle();
break;
case '4':
drawETriangle();
break;
case '5':
done=1;
break;
} //end switch
if (!done)
{ //start compound statement if
system("PAUSE");
system("CLS");
} //end of compound statement
return;
} //end of main
void drawRectangle(int height, int width) //this function def draws the rectangle
{
//note the opening bracket
//int height, width;
char symbol;
int counter;
cout<<"You have chosen the rectangle. Please enter the desired height and width \n";
cout<<"of the rectangle separated by a space."<<endl;
cin>>height>>width;
cout<<"You may enter a character of your choice to build this shape.";
cin>>symbol;
for (counter=0;
counter < height;
counter++)
{ //note the for loops opening bracket
for
(int row=0;
row < width;
row++)
cout<<'*';
cout<<endl;
} //note the for loops closing bracket
} //note the functions closing bracket
void drawSquare() //this function def draws the square
{
int sqheight, sqwidth, counter, row;
cout<<"You have chosen the square. Please enter the height and width of a square \n";
cout<<"seperated by a space \n";
cout<<"For ease of viewing please do not exceed a height or width of 20."<<endl;
cin>>sqheight>>sqwidth;
for (counter=0;
counter < sqheight;
counter++)
{
for
(row=0;
row < sqwidth;
row++)
cout<<'0';
cout<<endl;
} //note the for loops closing bracket
} //note the functions closing bracket
void drawRightTriangle () //this function draws the right triangle
{
int rtheight,ilc, olr;
cout<<"Please enter the height of the right triangle \n";
cout<<"For ease of viewing we suggest entering a height less than 20 \n";
cin>>rtheight;
for (ilc=0; //inner loop represents columns. initialize to zero
ilc < rtheight;
ilc++)
{
cout<<'z';
for
(olr=0; //outer loop represents rows. initialize to zero
ilc!=0 && olr < ilc;
olr++)
cout<<'z';
cout<<endl;
}
} //note the functions closing bracket
void drawETriangle () //this function draws the equliateral trianle
{ //starting the function
int eheight,ilc,olr; //declaring variables
cout<<"Please enter the height of the equilateral triangle \n";
cout<<"For ease of viewing we suggest entering a height less than 20 \n";
cin>>eheight;
for (ilc=0; //inner loop represents columns. initialize to zero
ilc < eheight;
ilc++)
{
cout<<setw(eheight-ilc);
cout<<'z';
for
(olr=0; //outer loop represents rows. initialize to zero
olr < ilc*2+1;
olr++)
cout<<'z';
cout<<endl;
}
}


