Rocket Program (Functions and prototypes)

I am having a difficult time with a project I am currently working on. I have written the following code but it will not work. If anybody has anny suggestions please let me know!


The assignment is as follows:
Complete the following programming project "Rocket"......which deals a great deal with "functional decomposition". This program is broken down into phases for your convenience only. Please turn in only your final product. Note: You are encouraged to use as much code from lesson#5 notes as you can for this project! DO NOT USE global variables.

Phase 1: Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (ie. an outline or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box.....

Draw an outline of a box for each stage if the value for the height of the box (or number of rows) is an even number.
Draw a filled-in box for each stage if the value for the height of the box (or number of rows) is an odd number.

INPUT VALIDATION: Do not accept values less than 3 or greater than 15 for height and width and the input for stages must be a nonnegative value.

ROCKET SAMPLE#1 WITH 2 STAGES
ROCKET BODY HAS TWO EVEN HEIGHT BOX SHAPES
(i.e., each with height = 6 or number of rows = 6)
NOTE THAT THE BOX SHAPE HAS A CARGO BAY THAT IS EMPTY
*
* *
* *
***** < top row
* *
* * <= box outline for stage#1
* *
* *
***** < bottom row
***** < top row
* *
* * <= box outline for stage#2
* *
* *
***** < bottom row
*
* *
* *
ROCKET SAMPLE#2 WITH 2 STAGES
ROCKET BODY HAS TWO ODD HEIGHT BOX SHAPES
(i.e., each with height = 7 or number of rows = 7)
NOTE THAT THE BOX SHAPE HAS A CARGO BAY THAT IS FILLED
*
* *
* *
***** < top row
*****
*****
***** <= box filled for stage#1
*****
*****
***** <bottom row
***** < top row
*****
*****
***** <= box filled for stage#2
*****
*****
***** < bottom row
*
* *
* *

Your main function in phase 1 may look like either of these:

function decomposition #1 - seperate functions to generate an outline or filled in box shape


void drawCone();//function prototype
void drawEvenBox(); //function prototype
void drawOddBox(); //function prototype functional decomposition#2 - one drawBox function but with procedures within the functions to generate both an outline and a filled in box shape


void drawCone();//function prototype
void drawBox(); //function prototype
int main()
{
//functions for sample#1
drawCone();
drawEvenBox();
drawEvenBox();
drawCone();
//functions for sample#2
drawCone();
drawOddBox();
drawOddBox();
drawCone();
}
//define functions below
drawCone(){
}
drawEvenBox(){
}
drawOddBox(){
}

int main()
{
//functions for sample#1 and sample#2
drawCone();
drawBox(); //procedures within the function to generate both box shapes
drawCone();

}
//define functions below
drawCone(){
}
drawBox(){
}



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 #include <iostream>
using namespace std;


void drawBox(int width, int height, int stages);//Added int stage to parameter
void drawCone(int width, int stages);
void drawHorizontalLine(int Numbers);
void draw2VerticalLines(int num_Spaces, int numRows);
void drawOneRow(int Number_Space);
void getDimensions(int &width, int &height, int &stages);
//////////////////////////////////////////////////
void drawRocket(int width, int height, int stages);

int main(){
    int width;
    int height;
    int stages;




    getDimensions(width, height, stages);
    drawRocket(width, height, stages);

    }
    ////////////////////////////////////////////////////////
    void getDimensions(int &width, int &height, int &stages)
    {
    ///////////////////////////////////////////
    // Allow user to input parameters
    cout << "Input Height of Stages\n" << endl;
    cin >> height;
    cout << "Input Width of Stages\n" << endl;
    cin >> width;
    cout << "Input number of stages\n" << endl;
    cin >> stages;
    ////////////////////////////////////////////
    }
    ////////////////////////////////////////////////////////


    ///////////////////////////////////////////////////////
    void drawRocket(int width, int height, int stages)
    {

    //Draw intial cone
    drawCone(width, stages);
    //Added stages ttp parameter
    drawBox(width, height, stages);
    //Draw final cone
    drawCone(width, stages);

    }
    ////////////////////////////////////////////////////////

    void drawCone (int width, int stages) {

        if (width%2==0) {
            width=width/2;
            int count,count1;
            for (count=1; count<=width; count++)
            {
                for (count1=width-count; count1>=1; count1--)
                { cout <<" "; }
                cout <<"*";
                for (count1=2; count1<=count*2-1; count1++)
                {
                cout << " ";
                }
                cout <<"*"<<endl;
            }
        }

        else
        {
            width=(width/2)+1;
            int count,count1;
            for (count=1; count<=width; count++)
            {
                for (count1=width-count; count1>=1; count1--)
                { cout <<" "; }
                cout <<"*";

                for (count1=2; count1<=count*2-2; count1++)
                {cout << " "; }
                //Added if statement to avoid printing the 2nd "*" for the 1st printed line
                if(count == 1)
                cout<< " "<<endl;
                else
                cout<< "*"<<endl;}
        }
    }

    void drawBox(int width, int height, int stages)
    {
        //Added for loop to draw multiple stages
       for(int i = 0; i<stages; i++)
       {
        drawHorizontalLine(width);
        draw2VerticalLines(width-2, height-2);
        drawHorizontalLine(width);
        }
    }

    void drawHorizontalLine(int numXs)
    {        int count;
            for (count = 0; count < numXs; count++){
            cout << "*";
        }
        cout << endl;
    }

    void draw2VerticalLines(int numSpaces, int numRows)
    {
        int rowCount;

        for (rowCount = 0; rowCount < numRows; rowCount++){
            drawOneRow(numSpaces);
        }
    }

    void drawOneRow(int numSpaces)
    {
        int spaceCount;

        cout << "*";
        for (spaceCount = 0; spaceCount < numSpaces; spaceCount++){
            cout << " ";
        }
        cout << "*" << endl;
        return 0;
    }
 
Hello cristina999.

Over all your program appears to work for the most part from the testing that I have done. The only two big problems I see are:
INPUT VALIDATION: Do not accept values less than 3 or greater than 15 for height and width and the input for
stages must be a nonnegative value.

The getDimensions function needs to validate your input numbers.

And
Draw an outline of a box for each stage if the value for the height of the box (or number of rows) is an even
number.

Draw a filled-in box for each stage if the value for the height of the box (or number of rows) is an odd number.

The odd numbers for "height" does not have a filled in box.

I have not figured out yet where you will need to determine if the box needs to be empty or filled. I am thinking it could either in the drawBox function or in one of the functions that drawBox calls. I will let you know when I figure it out better.

Hope that helps,

Andy
Thank you currently working on it!
Hello cristina999,

Instead of a lengthy discussion I will just show you the changes I made. I put comments on the changes and I hope that all my changes and additions are in bold.

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
void drawBox(int width, int height, int stages)
{
	//Added for loop to draw multiple stages
	for (int i = 0; i<stages; i++)
	{
		drawHorizontalLine(width, height);  // <--- Added height parameter.
		draw2VerticalLines(width - 2, height - 2);
		drawHorizontalLine(width, height);  // <--- Added height parameter.
	}
}

void drawHorizontalLine(int numXs, int numRows)  // <--- Added height parameter. Needs chnged in proto type.
{
	int count;
	for (count = 0; count < numXs; count++) {
		std::cout << (numRows % 2 == 0 ? "*" : "-");  // <--- Changed output.
	}
	std::cout << std::endl;
}

void draw2VerticalLines(int numSpaces, int numRows)  // <--- Added height parameter. Needs chnged in proto type.
{
	int rowCount;

	for (rowCount = 0; rowCount < numRows; rowCount++) {
		drawOneRow(numSpaces, numRows);
	}
}

void drawOneRow(int numSpaces, int numRows)  // <--- Added height parameter. Needs chnged in proto type.
{
	int spaceCount;

	std::cout << "*";
	for (spaceCount = 0; spaceCount < numSpaces; spaceCount++) {
		std::cout << (numRows % 2 == 0 ? " " : "*");  // <--- Changed output
	}
	std::cout << "*" << std::endl;
	//return 0;
}


Have not worked on the validation part yet.

Hope that gives you an idea of what you can do,

Andy
Topic archived. No new replies allowed.