Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi there, I have a problem with this assignment. Please help Here\'s the questio

ID: 3538519 • Letter: H

Question

Hi there,

I have a problem with this assignment. Please help

Here's the question:


Phase 1:Write a program that draws a rocket on the screen. Here's what the rocket should look like:

Your main function in phase 1 must look like this:

You may use simple cout statements (no loops are necessary) in your drawCone function, but you must write your drawBox function using loops. You may not use the setw() function in this assignment! Do not hesitate to steal code from the lessons for this!

Phase 2:In this phase you will allow the user to specify three things:

[A "stage" in your rocket is one rectangle. The example rocket above has a stage-height of 6, a stage-width of 5, and the number of stages is 2.]

Your main function will look a lot like it did before except that you will add 3 cout/cin statements before you call the functions (to ask the user the height, width, and number of stages). In addition, you will now have some arguments in your function calls, and some other minor changes.

Notice that 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 5 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 5 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:

Please make sure to place a detailed comment above each of your function definitions, use good decomposition, and separate your functions with at least 2 inches of whitespace.


#include <iostream>
using namespace std;

void drawBox(int width, int height);
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);
   
int main(){
    int width;
    int height;
    int stages;
        
        getDimensions(width, height, stages);
        drawBox(width, height);
        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 << " "; }
                cout<< "*"<<endl;}
        }
    }
   
    void drawBox(int width, int height)
    {
        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;
    }

Explanation / Answer

#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 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    ";
    cin >> end;
    }
    }
    ////////////////////////////////////////////////////////
    void getDimensions(int &width, int &height, int &stages)
    {
    ///////////////////////////////////////////
    // Allow user to input parameters
    cout << "Input Height of Stages " << endl;
    cin >> height;
    cout << "Input Width of Stages " << endl;
    cin >> width;
    cout << "Input number of stages " << 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;
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote