- Joined
- Sep 10, 2001
- Location
- Dayton, Ohio
nm after awhile of beating my head against the wall, i figured it out. hehe but here is the program if anyone wants to take a peek at the source. of course, this is just copied and pasted here so its not indented at all. and yeah my professor is a real stickler about commenting every line to clarify stuff.
/* James Martin
* CS 240
* Section 1
* Programming Project 3, Displaying simple graphic shapes using text symbols,
* based off of user input.
*/
#include <iostream>
using namespace std;
void box (); // The Box shape
void right (); // The Right Triangle shape
void isos (); // The Isosceles Triangle shape
void diamond (); // The Diamond shape
char getCommand ( char cmd); // To select the shape
void main()
{
char cmd;
do
{
cmd = getCommand (cmd);
switch( cmd )
{
case 'b': box (); break; // Calls void box ()
case 'B': box (); break; // Calls void box ()
case 'r': right(); break; // Calls void right ()
case 'R': right(); break; // Calls void right ()
case 'i': isos(); break; // Calls void isos ()
case 'I': isos(); break; // Calls void isos ()
case 'd': diamond(); break; // Calls void diamond ()
case 'D': diamond(); break; // Calls void diamond ()
case 'q': break; // Quits program
case 'Q': break; // Quits program
default: cout << "Invalid command " << cmd << " -- try again" << endl;
}
} while( cmd != 'q' );
}
void box () // calls the function to display the box
{
int r = 0; // number of rows in the box
int c = 0; // number of columns in the box
int rCount = 0; // number of iterations for rows
int cCount = 0; // number of iterations for columns
int i = 0; // number of iterations for loop
while ( r <= 0 || c <= 0 || c >= 80 ) // limitations of the rows and columns
{
i++;
if ( i >= 4 )
{
cout << "Too many invalid entries." << endl; // checks 3 times for invalid input
break; // drops user back to main menu
}
cout << "Enter the number of rows and columns (r,c): " << endl;
cin >> r >> c ; // Gets rows and columns
system ("cls"); // clears output screen
}
if ( i < 4) // If error check does not exceed 3, the box shape will be displayed
{
while ( rCount < r ) // loop to display box shape of desired rows and columns
{
while ( cCount < c )
{
cout << "* ";
cCount++;
}
cout << endl;
cCount = 0;
rCount++;
}
}
system ("pause"); //prompts user to strike a key to continue
system ("cls"); // clears the output screen
}
void right () // calls the function to display the right triangle
{
int b=0; // Base of the Right Triangle
int bCount=0; // Number of iterations for triangle loop
int rCount = 0; // number of iterations for columns
int i=0; // Number of iterations for error check loop
while ( b <=0 || b >= 80 ) //limitations of right triangle
{
i++;
if (i >=4 )
{
cout << "Too many invalid entries." << endl; // error checking
break; // drops user back to main menu
}
cout << "Enter the length of the base: " << endl;
cin >> b ; // length of the base of right triangle
system ("cls"); // clears output screen
}
if (i < 4)
{
while ( bCount < b)
{
while (rCount <= bCount)
{
cout << "* " ;
rCount++;
}
rCount = 0;
bCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
void isos () // calls the function to display the isosceles triangle
{
int b = 0; // legth of the base of the isosceles triangle
int cCount = 0; // number of iterations for columns
int rCount = 1; // number of iterations for rows
int sCount = 0; // number of iterations for triangles
int i = 0 ; // number of iterations for error check loop
while ( b <= 0 || b >= 80 || (b % 2) == 0 )
{
i++;
if (i >=4)
{
cout << "Too many invalid entries." << endl;
break; // drops user back to main menu
}
cout << "Enter the length of the base: " ;
cin >> b;
system ("cls");
}
if (i < 4)
{
int z = (b - 1) / 2;
int q = (b + 1) / 2;
while (rCount <= q)
{
while (sCount < z)
{
cout << " ";
sCount++;
}
int nDex = ((rCount * 2) - 1);
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < z)
{
cout << " ";
sCount++;
}
z--;
sCount = 0;
rCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
void diamond () //calls function to display diamond shape
{
int b = 0; // width of the widest part of diamond
int cCount = 0; //number of iterations for columns
int rCount = 1; // number of iterations for rows
int sCount = 0; // number of iterations for triangles
int i=0; // number of iterations for error check loop
while ( b <= 0 || b >= 80 || (b % 2) == 0 )
{
i++;
if (i >=4)
{
cout << "Too many invalid entries." << endl;
break; // drops user back to main menu
}
cout << "Enter the width of the widest part of the diamond: " ;
cin >> b; // width of the widest part of diamond
system ("cls"); // clears the output screen
}
if (i < 4)
{
int z = ( b - 1 ) / 2;
int q = ( b + 1 ) / 2;
while ( rCount <= q )
{
while (sCount < z)
{
cout << " ";
sCount++;
}
int nDex = ( ( rCount * 2 ) - 1 );
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < z)
{
cout << " ";
sCount++;
}
z--;
sCount = 0;
rCount++;
cout << endl;
}
z = ((b - 1) / 2);
q = (b + 1) / 2;
cCount = 0;
rCount = 1;
sCount = 0;
while (rCount <= z)
{
sCount = 0;
while (sCount < rCount)
{
cout << " ";
sCount++;
}
int nDex = (b - (rCount * 2));
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < rCount)
{
cout << " ";
sCount++;
}
rCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
char getCommand (char cmd) // prompts user to input which menu to go to
{
cout << "Enter a command (b, r, i, d, q): " << endl;
cin >> cmd; // which menu to take user to
return cmd; // passes command to main ()
}
/* James Martin
* CS 240
* Section 1
* Programming Project 3, Displaying simple graphic shapes using text symbols,
* based off of user input.
*/
#include <iostream>
using namespace std;
void box (); // The Box shape
void right (); // The Right Triangle shape
void isos (); // The Isosceles Triangle shape
void diamond (); // The Diamond shape
char getCommand ( char cmd); // To select the shape
void main()
{
char cmd;
do
{
cmd = getCommand (cmd);
switch( cmd )
{
case 'b': box (); break; // Calls void box ()
case 'B': box (); break; // Calls void box ()
case 'r': right(); break; // Calls void right ()
case 'R': right(); break; // Calls void right ()
case 'i': isos(); break; // Calls void isos ()
case 'I': isos(); break; // Calls void isos ()
case 'd': diamond(); break; // Calls void diamond ()
case 'D': diamond(); break; // Calls void diamond ()
case 'q': break; // Quits program
case 'Q': break; // Quits program
default: cout << "Invalid command " << cmd << " -- try again" << endl;
}
} while( cmd != 'q' );
}
void box () // calls the function to display the box
{
int r = 0; // number of rows in the box
int c = 0; // number of columns in the box
int rCount = 0; // number of iterations for rows
int cCount = 0; // number of iterations for columns
int i = 0; // number of iterations for loop
while ( r <= 0 || c <= 0 || c >= 80 ) // limitations of the rows and columns
{
i++;
if ( i >= 4 )
{
cout << "Too many invalid entries." << endl; // checks 3 times for invalid input
break; // drops user back to main menu
}
cout << "Enter the number of rows and columns (r,c): " << endl;
cin >> r >> c ; // Gets rows and columns
system ("cls"); // clears output screen
}
if ( i < 4) // If error check does not exceed 3, the box shape will be displayed
{
while ( rCount < r ) // loop to display box shape of desired rows and columns
{
while ( cCount < c )
{
cout << "* ";
cCount++;
}
cout << endl;
cCount = 0;
rCount++;
}
}
system ("pause"); //prompts user to strike a key to continue
system ("cls"); // clears the output screen
}
void right () // calls the function to display the right triangle
{
int b=0; // Base of the Right Triangle
int bCount=0; // Number of iterations for triangle loop
int rCount = 0; // number of iterations for columns
int i=0; // Number of iterations for error check loop
while ( b <=0 || b >= 80 ) //limitations of right triangle
{
i++;
if (i >=4 )
{
cout << "Too many invalid entries." << endl; // error checking
break; // drops user back to main menu
}
cout << "Enter the length of the base: " << endl;
cin >> b ; // length of the base of right triangle
system ("cls"); // clears output screen
}
if (i < 4)
{
while ( bCount < b)
{
while (rCount <= bCount)
{
cout << "* " ;
rCount++;
}
rCount = 0;
bCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
void isos () // calls the function to display the isosceles triangle
{
int b = 0; // legth of the base of the isosceles triangle
int cCount = 0; // number of iterations for columns
int rCount = 1; // number of iterations for rows
int sCount = 0; // number of iterations for triangles
int i = 0 ; // number of iterations for error check loop
while ( b <= 0 || b >= 80 || (b % 2) == 0 )
{
i++;
if (i >=4)
{
cout << "Too many invalid entries." << endl;
break; // drops user back to main menu
}
cout << "Enter the length of the base: " ;
cin >> b;
system ("cls");
}
if (i < 4)
{
int z = (b - 1) / 2;
int q = (b + 1) / 2;
while (rCount <= q)
{
while (sCount < z)
{
cout << " ";
sCount++;
}
int nDex = ((rCount * 2) - 1);
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < z)
{
cout << " ";
sCount++;
}
z--;
sCount = 0;
rCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
void diamond () //calls function to display diamond shape
{
int b = 0; // width of the widest part of diamond
int cCount = 0; //number of iterations for columns
int rCount = 1; // number of iterations for rows
int sCount = 0; // number of iterations for triangles
int i=0; // number of iterations for error check loop
while ( b <= 0 || b >= 80 || (b % 2) == 0 )
{
i++;
if (i >=4)
{
cout << "Too many invalid entries." << endl;
break; // drops user back to main menu
}
cout << "Enter the width of the widest part of the diamond: " ;
cin >> b; // width of the widest part of diamond
system ("cls"); // clears the output screen
}
if (i < 4)
{
int z = ( b - 1 ) / 2;
int q = ( b + 1 ) / 2;
while ( rCount <= q )
{
while (sCount < z)
{
cout << " ";
sCount++;
}
int nDex = ( ( rCount * 2 ) - 1 );
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < z)
{
cout << " ";
sCount++;
}
z--;
sCount = 0;
rCount++;
cout << endl;
}
z = ((b - 1) / 2);
q = (b + 1) / 2;
cCount = 0;
rCount = 1;
sCount = 0;
while (rCount <= z)
{
sCount = 0;
while (sCount < rCount)
{
cout << " ";
sCount++;
}
int nDex = (b - (rCount * 2));
int yDex = 0;
while(yDex < nDex)
{
cout << "*";
yDex++;
}
sCount = 0;
while (sCount < rCount)
{
cout << " ";
sCount++;
}
rCount++;
cout << endl;
}
}
system ("pause");
system ("cls");
}
char getCommand (char cmd) // prompts user to input which menu to go to
{
cout << "Enter a command (b, r, i, d, q): " << endl;
cin >> cmd; // which menu to take user to
return cmd; // passes command to main ()
}
Last edited: