Question: Complete the following programming project Rocket......and you will understand a bit more about functional decomposition. This program is broken down into phases for your convenience

Complete the following programming project "Rocket"......and you will understand a bit more about "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. hollow 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 odd or even user input for the height of the box..... Draw a hollow 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 PROGRAM OUTPUT 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 PROGRAM OUTPUT 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 ***** ***** *****  

Your program structure with functional decomposition in phase 1 may look like either of these:

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

functional decomposition#2 - a single drawBox function but with procedures within the function to generate either hollow or filled in box shape

*notice in this phase the functions do not have any parameters. So each function definition contains a procedure and the algorithm to generate a part of the rocket shape.

#include using namespace std; //function prototypes void drawCone(); void drawEvenBox(); void drawOddBox(); int main() { 
//function calls for sample#1 drawCone(); drawEvenBox(); drawEvenBox(); drawCone(); //functions for sample#2 drawCone(); drawOddBox(); drawOddBox(); drawCone(); return 0; } //define functions below void drawCone(){ //code your algorithm or procedure here } void drawEvenBox(){ //code your algorithm or procedure here } void drawOddBox(){ //code your algorithm or procedure here }
#include using namespace std; //function prototypes void drawCone(); void drawBox(); int main() { 
//function calls for sample#1 and sample#2 drawCone(); drawBox(); drawCone();
return 0; }
//define functions below
void drawCone(){ //code your algorithm or procedure here
}
void drawBox(){ //procedures within the function to generate both box shapes //code your algorithm or procedure here
} 

The functions in this phase do not necessarily need external data. You may use simple cout statements (no loops are necessary) in your drawCone function, but you must write your drawBox function or the drawEvenBox and drawOddBox functions using nested loops. For example, you can set-up a drawBox function with a procedure within it that uses nested loops to generate a 5 x 6 or a 5 x 7 box shape as shown in the sample figures above.

Note: You should not be using the setw() function in this project! Phase 2: In this phase inside int main() you will allow the user to specify three things and validate input to make sure that the values are not less than 3 or greater than 15. If needed, allow the user to re-input values that meet the program specification.: 1. The height of each stage 2. The width of each stage 3. How many stages in the rocket [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. Notice now that in addition to being able to generate two possible rocket body types (based on odd or even height values) 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. Phase 3: In this phase you won't change what the program produces. We're just going to improve on the organization a bit. Change your program so that the main function looks like either of the samples below:

Your program structure with functional decomposition in phase 3 may look like either of these:

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

functional decomposition#2 - a single drawBox function but with procedures within the function to generate either hollow or filled in box shape

*notice in phase 3 the functions have parameters. So each function definition contains a procedure to generate a part of the rocket shape and uses the parameter value/s passed into the function in the algorithm.

#include using namespace std; //function prototypes getDimensions(); drawRocket(); void drawCone(); void drawEvenBox(); void drawOddBox(); int main() {  //function calls for sample#1 & 2 getDimensions(); drawRocket(); return 0; }
//define functions below
void getDimensions(){
 //code your algorithm or procedure here }
void drawRocket(){
 //code your algorithm or procedure here }
void drawCone(){
 //code your algorithm or procedure here }
void drawEvenBox(){
 //code your algorithm or procedure here }
void drawOddBox(){
 //code your algorithm or procedure here }
#include using namespace std; //function prototypes getDimensions(); drawRocket(); void drawCone(); void drawBox(); int main() {  //function calls for sample#1 & 2 getDimensions(); drawRocket(); return 0; }
//define functions below
void getDimensions(){
 //code your algorithm or procedure here }
void drawRocket(){
 //code your algorithm or procedure here }
void drawCone(){
 //code your algorithm or procedure here }
void drawBox(){
 //code your algorithm or procedure here }

Project source code should have appropriate documentation including the following:

i. Data flow comments in all function parameter lists (here is an example function prototype: void drawRocket (/*in*/int height, /*in*/ int width, /*in*/ int stages)

ii. Description of what the function does....should be placed above each function heading.

iii. Pre and Post condition - specific to each function ...should be placed directly after each function heading prior to the function body

This is What I have so far:

#include #include

using namespace std;

//functions for sample#1 void drawOddCone(int width) { for (int j = 1; j <= width; j += 2) { for (int i = 1; i <= (width - j) / 2; i++) { cout << " "; } cout << "*"; if (j>1) { for (int h = 1; h <= j - 2; h++) { cout << " "; } cout << "*"; } cout << endl; } } void drawOddBoxFilled(int height, int width) { for (int k = 1; k <= height; k++) { for (int m = 1; m <= width; m++) { cout << "*"; } cout << endl; } } void drawOddBoxOpen(int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if ((j == 0) || (j == width - 1)) { cout << "*"; } else if ((i == 0) || (i == height - 1)) { cout << "*"; } else { cout << " "; } } cout << endl; } }

//functions for sample#2 void drawConeEven(int width) { for (int j = 1; j <= width / 2; j++) { for (int i = 1; i <= (width / 2) - j; i++) { cout << " "; } cout << "*"; if (j >= 1) { for (int h = 1; h <= 2 * j - 2; h++) { cout << " "; } cout << "*"; } cout << endl; } } void drawEvenBoxFilled(int height, int width) { for (int k = 1; k <= height; k++) { for (int m = 1; m <= width; m++) { cout << "*"; } cout << endl; } } void drawEvenBoxOpen(int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if ((j == 0) || (j == width - 1)) { cout << "*"; } else if ((i == 0) || (i == height - 1)) { cout << "*"; } else { cout << " "; } } cout << endl; } }

void getDiminsions(int &h, int &w, int &s, char &t) { cout << "Please enter a number for the height of the rocket? "; cin >> h;

cout << "Please enter a number for the width of the rocket? "; cin >> w;

cout << "Please enter a number for the stages of the rocket? "; cin >> s;

cout << "Would you like the rocket to be filled or open?(F/O) "; cin >> t; }

int main() { char again; int rocketHeight; int rocketWidth; int rocketStage; char rocketType;

do {

getDiminsions(rocketHeight, rocketWidth, rocketStage, rocketType);

if ((rocketHeight>3 && rocketHeight<15) && (rocketWidth>3 && rocketWidth<15)) {

// displays rocket with odd height and odd width and filled. if ((rocketHeight % 2 != 0) && (rocketWidth % 2 != 0) && (rocketType == 'F' || rocketType == 'f')) { drawOddCone(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawOddBoxFilled(rocketHeight, rocketWidth); } drawOddCone(rocketWidth); }

// displays rocket with odd height and odd width and open. if ((rocketHeight % 2 != 0) && (rocketWidth % 2 != 0) && (rocketType == 'O' || rocketType == 'o')) { drawOddCone(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawOddBoxOpen(rocketHeight, rocketWidth); } drawOddCone(rocketWidth); }

//displays rocket with even height and even width and filled. if ((rocketHeight % 2 == 0) && (rocketWidth % 2 == 0) && (rocketType == 'F' || rocketType == 'f')) { drawConeEven(rocketWidth); for (int q = 1; q <= rocketStage; q++) { drawEvenBoxFilled(rocketHeight, rocketWidth); } drawConeEven(rocketWidth); }

//displays rocket with even height and even width and open. if ((rocketHeight % 2 == 0) && (rocketWidth % 2 == 0) && (rocketType == 'O' || rocketType == 'o')) { drawConeEven(rocketWidth); for (int q = 1; q <= rocketStage; q++) { drawEvenBoxOpen(rocketHeight, rocketWidth); } drawConeEven(rocketWidth); }

// displays rocket with even height and odd width and filled. if ((rocketHeight % 2 == 0) && (rocketWidth % 2 != 0) && (rocketType == 'F' || rocketType == 'f')) { drawOddCone(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawEvenBoxFilled(rocketHeight, rocketWidth); } drawOddCone(rocketWidth); }

// displays rocket with even height and odd width and open. if ((rocketHeight % 2 == 0) && (rocketWidth % 2 != 0) && (rocketType == 'O' || rocketType == 'o')) { drawOddCone(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawEvenBoxFilled(rocketHeight, rocketWidth); } drawOddCone(rocketWidth); }

// displays rocket with odd height and odd width and filled. if ((rocketHeight % 2 != 0) && (rocketWidth % 2 == 0) && (rocketType == 'F' || rocketType == 'f')) { drawConeEven(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawOddBoxFilled(rocketHeight, rocketWidth); } drawConeEven(rocketWidth); }

// displays rocket with odd height and odd width and open. if ((rocketHeight % 2 != 0) && (rocketWidth % 2 == 0) && (rocketType == 'O' || rocketType == 'o')) { drawConeEven(rocketWidth); for (int l = 1; l <= rocketStage; l++) { drawOddBoxFilled(rocketHeight, rocketWidth); } drawConeEven(rocketWidth); } }

else { cout << "Invalid Input. Please try again or quit. "; }

cout << "Would you like to do this again?(y/n)" << endl; cin >> again;

} while (again == 'Y' || again == 'y');

return 0;

}

However, my teacher stated the following was wrong with the program. Could someone help me with the program? Here are the following things my professor recommended, but I am a bit lost.

Dar, Good effort here but the current version of the rocket source code does not quite meet project specifications and needs a bit more reorganization. Please make the necessary updates and resubmit. Thanks 1. We need 7 functon protoypes above and move all function defintions below the main function. 2. All the code in main inside the do-while loop directly after the call to the getDimensions function should be included in another drawRocket function as shown in Phase 3. int main() { //function calls for sample#1 & 2 getDimensions(); drawRocket(); return 0; } 3. The userinput for FIlled or Opened (F/O) is not needed instead the odd or even height value input should be used to determine filled of hollow rocket body boxes. Draw a hollow 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. 4. Although it is good to see some function related documentation, I suggest that you also include the following.... i. Data flow comments in all function parameter lists (here is an example function prototype: void drawRocket (/*in*/int height, /*in*/ int width, /*in*/ int stages) ii. Description of what the function does....should be placed above each function heading. iii. Pre and Post condition - specific to each function ...should be placed directly after each function heading prior to the function body * See also the function related documentation link for some guidance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!