creating a cone for my rocket ship

Here is what I have come up with so far. The goal is to have a rocket ship with two triangles - one on the bottom and one on the top. I am finished with the assignment, but for extra credit I can choose to have my cones be generated to scale with the height & width of the ship itself. I would like to do that so that I can get the points, but mostly because I'm a little OCD.

Anyone care to throw some ideas at me?

Teacher says:

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.


Now, below is my work. It does what it is supposed to do. It asks for the height, width, number of stages (number of rectangles to be drawn), and then if the height is even it draws a rectangle with space in the middle. If it is odd it draws the rectangle filled with asterisks. This is what was requested, as it is supposed to represent either an empty rocket (even) or an odd one.

I am going to get back to working on the cone now, but if anyone has some ideas, please let me know.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  #include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;


void rowRow1(int wide);
void rowRow2(int hi, int blankBlank);
void spaceJam(int blankBlank, int hi);
void make(int width, int height, int stages);
void get(int &width, int &height, int &stages);
void cone (int &width);










int main()

{
int width;
int height;
int stages;


get(width, height, stages);
//cone(width);
make(width, height, stages);
//cone(width);

return 0;

}

/* 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
*/
  /*
       cout << "  *" << endl;
       cout << " * * " << endl;
       cout << "*   *" << endl;

*/


void cone(int &width)
{

        if (width % 2 == 0)
        {
        cout << "  **" << endl;
        }

        else if (width % 2 != 0)
        {
        cout << "  *" << endl;
        }

       cout << " * * " << endl;
       cout << "*   *" << endl;



}











void get(int &width, int &height, int &stages)
{

cout << "enter height " << endl;
cin >> height;
if (height < 3 || height > 15)
  {
    cout << "Please enter a new height" << endl;
    cin >> height;
  }

  cout << "enter width " << endl;
cin >> width;
if (width < 3 || width > 15)
  {
    cout << "Please enter a new wid" << endl;
    cin >> width;
  }

cout << "enter stages " << endl;
cin >> stages;

}

















void make(int width, int height, int stages)
{
    int tminus;
    for (tminus = 0; tminus < stages; tminus++)
  {

  rowRow1(height);
  rowRow2(width - 2, height - 2);
  rowRow1(height);

  }

}










void spaceJam(int hi)
{

int blankBlank;
    cout << "*";
for (blankBlank = 0; blankBlank < hi; blankBlank++)
 {
   if (hi % 2 == 0)
    {
        cout << " ";
    }

    else if (hi % 2 != 0)
    {
        cout << "*";
   }

 }
    cout << "*" << endl;
}















void rowRow1(int height)
{

for (int r1 = 0; r1 < height; r1++)
  {
    cout << "*";
  }
cout << endl;
}
















void rowRow2(int hi, int blankBlank)
{
for (int r2 = 0; r2 < hi; r2++)
  {

        spaceJam(blankBlank);
  }
}

Hi there,

Let's break down the assignment:

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


I'm assuming by "good decomposition" the teacher means you should create (a) separate function(s) to perform this task. The assignment gives you pretty much what you need, you will only need to convert it into code. The only thing you need to keep in mind is that the spaces in between increase. In rough code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
num_spaces=0;
cone_rows = width/2;

if (width%2 != 0)
    cone_rows+=1;

for (size_t i=0; i<cone_rows; ++i)
{
    std::cout << "*";

    for (size_t j=0; j<num_spaces; ++j)
        std::cout << " ";

    std::cout << "*";

    ++num_spaces;
}



It's quite rough and doesn't address all the issues, but I'd rather not give you the exact solution per this forums homework policy. Hope this gets you underway, please do let us know if you have any further questions.

All the best,
NwN

Topic archived. No new replies allowed.