Overview For this assignment you will write a C program that

Overview
For this assignment, you will write a C++ program that will draw two copies of a simple rocket. The first rocket will be a rocket made of (‘*’)s. The second rocket will be a rocket made up of a character input from the keyboard. The output should look like the picture shown.

You must use functions to handle common elements of the problem. You should have a main function, rocket function, a rectangle function and a triangle function.

Choose good function names. Write comments you understand. Each function should have at least a single line comment describing its purpose. Use appropriate indenting and blank lines between functions. Include your name and the month at the top along with a short description of the problem. Remember that people read your programs. Make them readable.

Drawing a Rocket
This is a very simple rocket with two kinds of parts. The triangular part can be used as a nosecone as well as the flame coming out of the bottom. The rectangular part is used three times for the middle stages. All of the rocket is drawn using the same character (‘*’). There are no blank lines within the picture.

Approaching the Problem
Remember to have #include <iostream> and using namespace std; near the beginning of your program.

Start by thinking about the parts of the rocket. It is composed of a triangle, three rectangles, and another triangle. Instead of drawing three separate rectangles, you can call one rectangle function three times. Instead of drawing a rectangle line as
  cout << \"*****\" << endl;
think more generally and use a char variable named sym and write
  cout << sym << sym <<sym << sym << sym << endl;
This will help you with your second rocket! You can use \"    \" to print as many spaces as you might need between symbols.

Develop your solution incrementally. I suggest the following initial iterations. For each iteration, modify your source code, save, compile, and execute. Don\'t do too much in each iteration, and you won\'t get overwhelmed.

Iteration 1: Start with a program in a file named rocket.cpp with a main function and one rocket function. The rocket function prints the phrase \"3-2-1-Blast off!!\" followed by sym. The rocket function prototype goes before main, and the function definition goes after main. Try this:

Be sure to call your rocket function from main. Save, compile, and execute.

Iteration 2: Add triangle and rectangle functions similar to the rocket function. Remember that a function must be declared (have a prototype) before it can be called. Call each function once to verify that they work as intended.

Iteration 3: Call the functions the appropriate number of times in the rocket function. Save, compile, and execute.

Iteration 4: Modify the triangle and rectangle functions so that they print the sym parameter rather than a ‘*’;

Iteration 6: Input a character from the keyboard and call the rocket function again from main. Be sure your program prints two rocket pictures.

NOTE: You should only have ONE rectangle function, ONE triangle function, ONE rocket function and the main function.

Drawing a Rocket
This is a very simple rocket with two kinds of parts. The triangular part can be used as a nosecone as well as the flame coming out of the bottom. The rectangular part is used three times for the middle stages. All of the rocket is drawn using the same character (‘*’). There are no blank lines within the picture.

Approaching the Problem
Remember to have #include <iostream> and using namespace std; near the beginning of your program.

Start by thinking about the parts of the rocket. It is composed of a triangle, three rectangles, and another triangle. Instead of drawing three separate rectangles, you can call one rectangle function three times. Instead of drawing a rectangle line as
  cout << \"*****\" << endl;
think more generally and use a char variable named sym and write
  cout << sym << sym <<sym << sym << sym << endl;
This will help you with your second rocket! You can use \"    \" to print as many spaces as you might need between symbols.

Develop your solution incrementally. I suggest the following initial iterations. For each iteration, modify your source code, save, compile, and execute. Don\'t do too much in each iteration, and you won\'t get overwhelmed.

       
       *  
      * *  
     *   *  
     *****  
     *   *  
     *   *  
     *****  
     *****  
     *   *  
     *   *  
     *****  
     *****  
     *   *  
     *   *  
     *****  
       *  
      * *  
     *   *  

Solution

#include <iostream>
using namespace std;
void drawRect(char,int);
void drawTriangle(char);
void rocket(char sym);
int main() {
   rocket(\'^\');
}

// prints a rocket using sym character
void rocket(char sym)
{
cout <<endl << \"3-2-1-Blast off!! \" << sym << endl<<endl;
drawTriangle(sym);
drawRect(sym,3);
drawRect(sym,3);
drawRect(sym,3);
drawTriangle(sym);
}
// prints a rectangle using sym character.
void drawRect(char sym,int n){
   int i,j;
   for(i=0;i<n+1;i++){
       for(j=0;j<n;j++){
       if(i==0 || i==n || j==0 || j==n-1)
       cout << sym << \" \";
       else
       cout << \" \";
           }
   cout<< endl;
   }
}
// prints a trinagle using sym character.
void drawTriangle(char sym){
   cout << \" \" << \" \" << sym<<endl;
   cout << \" \" << sym << \" \"<<sym<<endl;
   cout << sym << \" \" << \" \"<<\" \"<<sym<<endl;
}

/* sample output

*/

Overview For this assignment, you will write a C++ program that will draw two copies of a simple rocket. The first rocket will be a rocket made of (‘*’)s. The s
Overview For this assignment, you will write a C++ program that will draw two copies of a simple rocket. The first rocket will be a rocket made of (‘*’)s. The s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site