Question

C++. Write a program that draws a rocket shape on the screen based on user input...

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.   

Homework Answers

Answer #1
#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;
    }
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Write a C program that prompts the user to input as many unsigned(n) as the user...
Write a C program that prompts the user to input as many unsigned(n) as the user wants to type, terminated by non negative number You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a double You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a negative number. For each number the user types, output whether that number is prime or not. You won't need...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a C++ program which consists of several functions besides the main() function. 1)   The main()...
Write a C++ program which consists of several functions besides the main() function. 1)   The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. 2)   A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. 3)   A value-returning function called Power(int a,...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Please write it in c# program please and if possible no arrays only loops Loop Introduction...
Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...