C++ HELP PLEASE! Asterisks shapes.

My teacher for my online C++ class assigned an optional assignment. He said learning this may help on the test but he did not give any information on how to go about doing it. I watched some videos online and know how to make asterisks shapes but this is way over my head:

Write a program that
repeatedly asks the user to select either square, left or right triangle, then inputs the figure size and
then prints the appropriate shape in stars. For square, the program should ask whether the user wants a
filled or a hollow square. The program should quit if the user inputs an invalid option. See an example
dialog below:
1. square
2. left triangle
3. right triangle
select figure: 1
select size: 4
filled or hollow [f/h]: h
****
* *
* *
****
1. square
2. left triangle
3. right triangle
...
You can reuse your code from the Looping lab (assignment 3). Place the star-printing code in four separate
functions: filledSquare, hollowSquare, leftTriangle and rightTriangle. Each function should accept a single
integer parameter - the size of the figure and return no value (be a void-function). Place the triangle and
square function definitions below main function, and their prototypes above the main.

Here is what I have so far. I am do not really know what I am doing.

#include <iostream>
using std::cout; using std::cin; using std::endl;
int main(){
int shape, size, enterS;
char shapeType;

cout << "Select a shape by entering its number" << endl;
cout << "1. Square" << endl << "2. Left triangle" << endl << "3. Right triangle" << endl;
cin >> shape;

cout << "Select size of shape";
cin >> size; cout << endl;

cout << "Filled or hollow (f/h): ";
cin >> shapeType; cout << endl;

switch (shape){
case 1: cout << "You selected square"; break;
case 2: cout << "You selected left tringle"; break;
case 3: cout << "You Selected right triangle"; break;
}

if (shapeType == 'f' || shapeType == 'F'){
}
}
Your next step is to write the four functions (filledSquare, hollowSquare, leftTriangle and rightTriangle) called for in the assignment.

You may find it helpful to write one additional function that emits a line of a specified length and filled or not.
1
2
3
void emit_line (int len, bool filled)
{  // You supply the code
}

Then the four shape functions are just a matter of calling emit_line () as needed with the correct arguments.

edit: It might be clearer if you create two functions:
1
2
void emit_filled_line (int len);
void emit_hollow_line (int len);


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.