Write a program that draws ASCII rockets. The user can enter the width, cylinder
ID: 3556357 • Letter: W
Question
Write a program that draws ASCII rockets.
The user can enter the width, cylinder length, border character and offest.
For example if the user enters a width = 7, cylinder length = 14, border character = @ and offset = 4, then your program will draw the shape below. (The offset means how many spaces are inserted to the left of the first nonblank character.)
To avoid asymmetry, you should increase the width to an odd number whenever the user enters an even number. So if the user enters a 6 you would set the width to 7. Also, you can set the minimum width to 5 and minimum height to 4.
The first line of the tail section should be four characters narrower than the width. The last line of the tail section shoud be equal to the width.
(Suppose to look like this minus the distorted picture when I post it for some reason)
Explanation / Answer
Program Code:
// Grading.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iomanip>
#include<iostream>
using namespace std;
int main()
{
int counter=0;
int width=0,length,offset;
char border_char;
do
{
cout<<"Enter width:(minumum 5)";
cin>>width;
if(width/2==0)
width=width+1;
}while(width<5);
do
{
cout<<"Enter length(minimum 4):";
cin>>length;
}while(length<4);
cout<<"Enter border character:";
cin>>border_char;
cout<<"Enter offset:";
cin>>offset;
for(int i=1;i<offset;i++)
{
cout<<setw((offset-1)-counter)<<" ";
cout<<border_char;
if(counter!=0)
if(counter!=2)
cout<<setw(counter)<<" "<<border_char;
else
cout<<setw(counter+1)<<" "<<border_char;
cout<<endl;
counter++;
}
for(int i=0;i<width;i++)
{
if(i==0 || i==(width-1))
for(int j=0;j<=length+1;j++)
cout<<border_char;
else
for(int j=0;j<=length+1;j++)
if(j==0||j==(length+1))
cout<<border_char;
else
cout<<" ";
cout<<endl;
}
system("pause");
return 0;
}
Sample Run:
Enter width:(minumum 5)6
Enter length(minimum 4):5
Enter border character:@
Enter offset:4
@
@ @
@ @
@@@@@@@
@ @
@ @
@ @
@ @
@@@@@@@
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.