C++.
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 (i.e.. a 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 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 4 or greater than 15 for height and width and the input for stages must be a nonnegative value.
Note: In the samples provided below you will see that the rocket body changes from hollow to filled boxes and this change is determined at program run-time by the even (height=6) or odd (height=7) value input by the user for the height dimension. The final phase of your rocket project should generate just one rocket with either a filled or hollow body.
ROCKET SAMPLE#1 WITH 2 STAGES ROCKET BODY HAS TWO EVEN HEIGHT BOX SHAPES (Each with height = 6 or number of rows = 6) THE ROCKET BODY (BOXES) WITH CARGO BAY 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 (Each with height = 7 or number of rows = 7) THE ROCKET BODY (BOXES) WITH CARGO BAY 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:
/* PHASE#1 - Rocket Project functional decomposition #1 separate functions to generate hollow or filled rocket body */ #include<iostream> using namespace std; //function prototypes void drawCone(<parameters>); void drawEvenBox(<parameters>); void drawOddBox(<parameters>); int main() { <variable declarations> //prompt for inputs //conditions and calls in Phase 1 //functions for hollow body rocket drawCone(<arguments>); drawEvenBox(<arguments>); drawEvenBox(<arguments>); drawCone(<arguments>); //functions for filled body rocket drawCone(<arguments>); drawOddBox(<arguments>); drawOddBox(<arguments>); drawCone(<arguments>); return 0; } //Function definitions with documentation void drawCone(<parameters) { //code to process } void drawEvenBox(<parameters) { //code to process } void drawOddBox(<parameters) { //code to process } |
/* PHASE#1 - Rocket Project functional decomposition #2 a single drawBox function with procedures to generate hollow or filled rocket body */ #include<iostream> using namespace std; //function prototypes void drawCone(<parameters>); void drawBox(<parameters>); int main() { <variable declarations> //prompt for inputs //condition and calls in Phase 1 //function for hollow and filled body rocket drawCone(<arguments>); drawBox(<arguments>); drawCone(<arguments>); return 0; } //Function definitions with documentation void drawCone(<parameters) { //code to process } void drawBox(<parameters) { //code to process } |
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 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.You may not use the setw() function in this project!
Phase 2: In this phase inside int main() you will allow the user to specify three data items (variables) and validate input to make sure that the values are not less than 4 or greater than 15.
If invalid values are input (such as an alpha character or out
of range values) 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 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.
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 this: (note: only two functions are shown below and
there should be others that generate parts of the rocket). DO
NOT ask the user for a hollow or filled body rocket instead
write a function getDimensions that will ask the user for only
three inputs.
/* PHASE#3 - Rocket Project functional decomposition #3 User input of rocket dimensions with separate functions to generate hollow or filled rocket body */ #include<iostream> using namespace std; //function prototypes void getDimensions (<parameters>); void drawRocket (<parameters>); //other function prototypes int main() { <variable declarations> //two function calls getDimensions(<arguments>); drawRocket(<arguments>); return 0; } //function definitions with documentation below |
Please make sure to include appropriate function related documentation, use good decomposition, separate your functions with at least 1 inches of whitespace and DO NOT use global variables.
Now would be a good time to reread the How To Get Good Grades on Your Programs and Function Documentation: Assertions and Dataflow comments. Note: Projects submitted without appropriate function related documentation will not be graded and you will need to resubmit your source code including all function related documentation.
#include <iostream>
using namespace std;
void drawBox(int width, int height, int stages);
void drawCone(int width, int stages);
void drawHorizontalLine(int numXs);
void draw2VerticalLines(int numSpaces, int numRows);
void drawOneRow(int numSpaces);
void getDimensions(int &width, int &height, int &stages);
void drawRocket(int width, int height, int stages);
int main(){
int width;
int height;
int stages;
int end = 1;
while(end == 1){
getDimensions(width, height, stages);
drawRocket(width, height, stages);
cout << "Would you like to continue type 1 Yes or type 0 No \n";
cin >> end;
}
}
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;
}
Get Answers For Free
Most questions answered within 1 hours.