Rocket Program: Need assistance on developing stages

My assignment requirements are here. [A "stage" in your rocket is one box] Your program will look a lot like it did before except that you will add 3 cout/cin statements including a data validation routine before you call the functions. In addition, you will now have some arguments in your function calls, and some other changes to call the appropriate functions (HINT: based on the height of each stage) to generate the correct type of rocket shape I got the body lay out down where it generates a filled and hollow body based on the numbers entered. What I am having trouble now is adding extra length.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Draw a Rocket with a filled or hollow body with stages
#include <iostream>
using namespace std;

void drawOddBox(/* in*/ int, /* im */ int); //Function prototype with two value parameters
void getDimensions(/* out */ int&, /* out */ int&); //Function prototype with two reference parameters
void drawEvenBox(/* in*/ int, /* im */ int); //Function prototype with two value parameters
void drawHorizontalLine(int);   //Function Prototype with one value parameter
void drawCone();    //Function prototype

int main()
{
    int width = 5, numRows = 10, stages = 0;

    //cout << width << " " << numRows << endl;
    getDimensions(width, numRows);  //A function call with two arguments
    //cout << width << " " << numRows << endl;


    if(numRows % 2 == 0)
    {
        drawCone(); //A function call to generate a cone
        drawHorizontalLine(width);  //A function call to generate a horizontal line
        drawEvenBox(width, numRows); //Function call to generate a hollow box
        drawHorizontalLine(width);  //A function call to generate a horizontal line
        drawCone(); //A function call to generate a cone
    }

    else
    {
        drawCone(); //A function call to generate a cone
        drawHorizontalLine(width);  //A function call to generate a horizontal line
        drawOddBox(width, numRows); //A function call to generate a filled box
        drawHorizontalLine(width);  //A function call to generate a horizontal line
        drawCone(); //A function call to generate a cone
    }

    cout << endl;
    //drawFilledBox(numRows, width); //A function call with two arguments

    return 0;
}

//Define all your functions below

//describe what the function will do and the role of the parameters
void getDimensions(/* out */ int& userInput1, /* out */ int& userInput2) //Function heading with two reference parameters
//Pre:
//Post:
{
    cout << "Program will draw a filled box based on two dimensions" << endl;
    cout << "WIDTH OF THE ROCKET BODY: ";
    cin >> userInput1;
    cout << "HEIGHT OF ROCKET BODY: ";
    cin >> userInput2;

    //Data range validation loop
    while(userInput1 < 3 || userInput1 > 15 || userInput2 < 3 || userInput2 > 15 || !cin)
    {
        cin.clear(); //To clear cin fail state
        cin.ignore(200, '\n'); //To ignore stray characters in the buffer
        cout << "Dimensions input should be in the range of 3 to 15, please retype." << endl;
        cout << "WIDTH OF THE BOX: ";
        cin >> userInput1;
        cout << "HEIGHT OF BOX: ";
        cin >> userInput2;
    }
}

void drawCone()
//Pre: Assume that no values are entered
//Post: Prints out a cone with three rows using a *.
{
    cout << "  *" << endl;
    cout << " * *" << endl;
    cout << "*   *" << endl;
}

//describe what the function will do and the role of the parameters
void drawEvenBox(/* incoming data */ int width, /* im */ int numRows) //This is known as a function heading
//Pre: assume that two values are not negative or too large
//Post: A box is drawn with numRows and width limits
{
    for(int row = 0; row < numRows; row++) //Outer loop generates new rows
    {
        for(int col = 0; col < width; col++) //Inner loop draws a single row
        {
            cout << '*';
        }
            cout << endl; //To move to the next row
    }
}

void drawHorizontalLine(int x) //This is a "function definition"
{
    int count;
    for(count = 1; count <= x; count++)
    {
        cout << "*";
    }
    cout << endl;
}

void drawOddBox(/* in*/ int width, /* im */ int numRows)
{
    int rowCount;
    int spaceCount;

    for(rowCount = 1; rowCount <= numRows-2; rowCount++)
    {
        cout << "*";
        for(spaceCount = 1; spaceCount <= width-2; spaceCount++)
        {
            cout << " ";
        }
        cout << "*" << endl;
    }
}
Last edited on
Hello Depressed,

DO NOT change your original post (OP). If you have a change or addition put this in another message. It is really confusing to go from:

Notice that in addition to generating two possible rocket types (based on stage height) if you run the program and
choose a different width for your stages, the cone won't really fit correctly anymore.

I won't make you fix this, but you can fix it for 10 points of extra credit if you like. However, I will not help you
with the extra credit.

In order to get the extra credit, the number of rows of your cone must be equal to the width of the stages
divided by 2 (plus 1 for odd widths).

If the stage width is an even number, your cone must have two stars in the top row instead of one. If you do this
perfectly and use good decomposition in the process you'll get 10 extra credit points.


I got the body lay out down where it generates a filled and hollow body based on the numbers entered. What I am having trouble now is adding extra length.


To

[A "stage" in your rocket is one box] Your program will look a lot like it did before except that you will add 3
cout/cin statements including a data validation routine before you call the functions.

In addition, you will now have some arguments in your function calls, and some other changes to call the appropriate
functions (HINT: based on the height of each stage) to generate the correct type of rocket shape.


I am having a little trouble trying to understand what you mean by:What I am having trouble now is adding extra length.. Extra length where?

Using the quote or output tag is a better choice rather than putting one long line in a code tag.

While working with the program I did make a change to the "drawCone" function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void drawCone(int width)
//Pre: Assume that no values are entered
//Post: Prints out a cone with three rows using a *.
{
	if (width % 2 == 0)
	{
		cout << "  **" << endl;
		cout << " *  *" << endl;
		cout << "*    *" << endl;
	}
	else
	{
		cout << "  *" << endl;
		cout << " * *" << endl;
		cout << "*   *" << endl;
	}
}

Not the best solution because it now works for a width of (5) or (6) only. Less than (5) and the cone is to wide. Greater than (6) and the cone is not centered properly.

Hope that helps,

Andy
By extra length i meant like a loop function for the rocket body that would detect a filled or hollow body and can make as many lengths as the user enters between the range of 3-15, basically expanding the body :D
Hello Depressed,

That I understand. Kind of like adding a different number of stages to the rocket body. Hint hint nudge nudge.

Now that I know what to look at I will see what I can do.

Andy
Thank you Andy :). I've been struggling on that part for a while on how to make it work.
Topic archived. No new replies allowed.