Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming: define each function and must be preceded by a comment block th

ID: 3933402 • Letter: C

Question

C++ programming: define each function and must be preceded by a comment block that includes:

1) One line per parameter indicating if it is an input (passed by value) or IO (passed by reference) parameter, the type of the parameter and a very brief description of the parameter.

2) One line indicating the return type and describing it, for void functions indicate the function returns nothing.

3) A very brief description of the function's purpose.

4) This comment block should contain the information needed to use the function.

Write a program that draws the shape of the user’s choice using the symbol of the user’s choice. Your program should have and use the following functions:

int displayMenu ();

int getDimension (string,string);

void drawLine (int blanks,int numPen,char pen);

void drawRectangle (int,char);

void drawRectangle (int,int,char);

void drawDiamond (int,char);

void drawEqualTriangle (int,char);

void drawInvertTriangle (int,char);

char getNewPen ();

The function drawDiamond should call the functions drawEqualTriangle and drawInvertedTriangle. There is a simple trick to make this work properly. Look closely at the test run of drawInvertedTriangle to determine the trick.

Sample Runs:

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

1

Height of the rectangle: 5

Width of the rectangle: 7

* * * * * * *

* * * * * * *

* * * * * * *

* * * * * * *

* * * * * * *

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

2

Width of the square: 6

* * * * * *

* * * * * *

* * * * * *

* * * * * *

* * * * * *

* * * * * *

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

9

Which symbol would you like to use? @

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

3

Base of the equilateral triangle: 5

@

@ @

@ @ @

@ @ @ @

@ @ @ @ @

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

4

Base of the inverted triangle: 4

@ @ @ @

@ @ @

@ @

@

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

5

Width of the diamond: 7

@

@ @

@ @ @

@ @ @ @

@ @ @ @ @

@ @ @ @ @ @

@ @ @ @ @ @ @

@ @ @ @ @ @

@ @ @ @ @

@ @ @ @

@ @ @

@ @

@

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

6

Invalid menu choice

1. Rectangle

2. Square

3. Draw Equilateral Triangle

4. Draw Inverted Triangle

5. Diamond

9. Pick new draw symbol

0. Quit

0

Logging you out

Here's a better look for the two triangles and diamond:

Explanation / Answer

#include <iostream>
using namespace std;
void drawRectangle(int,char);
void drawEquiTriangle(int,char);
void drawInvertTriangle(int,char);
void drawLine (int,int,char);
void drawDiamond (int,char);
void drawTriangle(char);
void drawRectangle(int,int,char);
void displayMenu();
int main() {
   char s;
   int c,h,w;
   cout << "Which symbol would you like to use? ";
   cin >> s;
   int flag = 1;
   while(flag){
       displayMenu();
       cin >> c;
       switch(c){
           case 1:
               cout << "Height:";
               cin >> h;
               cout << "Width:";
               cin >> w;
               drawRectangle(h,w,s);
               break;
           case 2:
               cout << "Side:";
               cin >> h;
               drawRectangle(h,s);
               break;
           case 3:
               cout << "Base:";
               cin >> h;
               drawEquiTriangle(h,s);
               break;
           case 4:
               cout << "Base:";
               cin >> h;
               drawInvertTriangle(h,s);
               break;
           case 5:
               cout << "Width:";
               cin>>w;
               drawDiamond(w,s);
               break;
           case 9:
               cout << "Enter Symbol:";
               cin >> s;
               break;
           case 0:
               flag = 0;
              
       }
   }
   return 0;
}

void displayMenu(){
   cout << "1. Rectangle 2. Square 3. Draw Equilateral Triangle 4. Draw Inverted Triangle 5. Diamond 9. Pick new draw symbol 0. Quit"<<endl;
}

// prints a rectangle using sym character.
void drawRectangle(int n,char sym){
   int i,j;
   for(i=0;i<n;i++){
       for(j=0;j<n;j++){
       cout << sym << " ";
           }
   cout<< endl;
   }
}
void drawRectangle(int h,int w,char sym){
   int i,j;
   for(i=0;i<h;i++){
       for(j=0;j<w;j++){
       cout << sym << " ";
           }
   cout<< endl;
   }
}

void drawLine (int blanks,int numPen,char pen){
   int i;
   for(i=0;i<numPen;i++){
       cout << pen << " ";
   }
   cout << endl;
}

void drawEquiTriangle(int rows, char s){
   int i, j;
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
cout << s << " ";
}
cout << endl;
}
}

void drawInvertTriangle(int rows,char s){
   int i, j;
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
cout << s << " ";
}
cout << endl;
}
}

void drawDiamond(int rows,char s){
   drawEquiTriangle(rows-1,s);
   drawLine(1,rows,s);
   drawInvertTriangle(rows-1,s);
}

/* sample output

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote