Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please help with making a program in C that can meet these requirements? The first page explains the requirements and the last few

Can you please help with making a program in C that can meet these requirements? The first page explains the requirements and the last few pages show examples of what output and input should be.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Requirements The requirements are the same as for the previous task, but this time pyramid must be rendered from the side: 1. Save your program to the file t9.c. 2. (Inherit requirements 2-5, 7 and 8 from the previous task) 3. On standard output render the view from the front of the pyramid, showing its triangular side, i.e., the projection of the pyramid onto the plane y=0. In this view, x increases from left to right and z increases from bottom to top. 4. The base of the pyramid should be drawn as a row of exactly width # characters. 5. The top row (tip of the pyramid) should be drawn such that every character position that intersects the boundary of the pyramid is drawn. 6. For every remaining text row, either one or two # characters shall be drawn, covering the left-most and right-most position on that row intersected by the edge of the pyramid, as shown in the shaded regions in this image of a pyramid of width==6, breadth==6, height==4: 7. Each line should be as few characters as possible:the final # character on each line should be immediately followed by a newline. Guide Don't be tempted to be artistic and make the pyramid "look right by insisting on a 1-pixel point at the top. Be sure to meet the requirements exactly. Consider example 3 below and the image above, for example. Notice that the requirements imply that your rendering will be symmetrical left-to-right. The view from the side of the pyramid involves drawing two lines from the base of the pyramid to the top. The left line starts from (21, 21) = (0,0) and ends at (x2, 22) = (, 2). The right line starts from (21, 21) = (x,0) and ends at (22,22) = (1, 2). The equation for a line where we can feed in the z values and compute the x values is x = mz+b where m is the slope and b is the intercept. If we know the end points (x1, 21) and (x2, 22) (which we do) we can compute the slope m = a where dz = 22 X1 and d. = Z2 21. The intercept b= x1 mz1. Based on these equations and simplifying them we can write down the pseudo code for drawing each point (3, 2) dx = x2 - x1 dz = z2 - z1 for z from z1 to z2 { x = x1 + dx * (z - z1) / dz plot(x, z) We need to draw two lines, but we can compute the value of x where we should draw the # for both lines inside the same loop. First use the pseudo code above to draw either the left or the right line. Once you do, you can add in the x value of the second line for each value z from zz to 22 (which is always from 0 to 2). For each j which goes from 0 to z we can use the above pseudo code to compute the points for both the lines in the same loop (after some substitution of values and algebraic simplification left = floor( j * (x/(2.0*2)) ); right = ceil( (x-1) + -j * (x/(2.0*z)) ); We use floor and ceil in order to obtain the correct integer values for each coordinate for the left and the right line. First print out the values of left and right for each j. For example for input 7 4 4 you should get left right Once you have these values you know how many spaces to print to print the # at the right x coordinate to depict the line. Start off by printing the pyramid upside down. It will be a lot easier to write the loop you need. For 7 7 4 you should get ####### #..... #...# ### Then do the loop from the largest to the smallest value (subtracting one each time) to print the pyramid upright. One thing to keep in mind is that the point on the base of the pyramid should be drawn once, so we only need to compute values of x for each j from 1 to z. Draw the base of the pyramid separately. Now for 7 7 4 you should get the desired output that will pass the auto grader ### #...# #.....# ####### Examples Input 6 64 Output ## #. # #....# ###### Input 774 Output ### #...# #.....# ####### Input 1 1 1 Output Input 12 6 6 Output ## #.. #......# . ###### ### Requirements The requirements are the same as for the previous task, but this time pyramid must be rendered from the side: 1. Save your program to the file t9.c. 2. (Inherit requirements 2-5, 7 and 8 from the previous task) 3. On standard output render the view from the front of the pyramid, showing its triangular side, i.e., the projection of the pyramid onto the plane y=0. In this view, x increases from left to right and z increases from bottom to top. 4. The base of the pyramid should be drawn as a row of exactly width # characters. 5. The top row (tip of the pyramid) should be drawn such that every character position that intersects the boundary of the pyramid is drawn. 6. For every remaining text row, either one or two # characters shall be drawn, covering the left-most and right-most position on that row intersected by the edge of the pyramid, as shown in the shaded regions in this image of a pyramid of width==6, breadth==6, height==4: 7. Each line should be as few characters as possible:the final # character on each line should be immediately followed by a newline. Guide Don't be tempted to be artistic and make the pyramid "look right by insisting on a 1-pixel point at the top. Be sure to meet the requirements exactly. Consider example 3 below and the image above, for example. Notice that the requirements imply that your rendering will be symmetrical left-to-right. The view from the side of the pyramid involves drawing two lines from the base of the pyramid to the top. The left line starts from (21, 21) = (0,0) and ends at (x2, 22) = (, 2). The right line starts from (21, 21) = (x,0) and ends at (22,22) = (1, 2). The equation for a line where we can feed in the z values and compute the x values is x = mz+b where m is the slope and b is the intercept. If we know the end points (x1, 21) and (x2, 22) (which we do) we can compute the slope m = a where dz = 22 X1 and d. = Z2 21. The intercept b= x1 mz1. Based on these equations and simplifying them we can write down the pseudo code for drawing each point (3, 2) dx = x2 - x1 dz = z2 - z1 for z from z1 to z2 { x = x1 + dx * (z - z1) / dz plot(x, z) We need to draw two lines, but we can compute the value of x where we should draw the # for both lines inside the same loop. First use the pseudo code above to draw either the left or the right line. Once you do, you can add in the x value of the second line for each value z from zz to 22 (which is always from 0 to 2). For each j which goes from 0 to z we can use the above pseudo code to compute the points for both the lines in the same loop (after some substitution of values and algebraic simplification left = floor( j * (x/(2.0*2)) ); right = ceil( (x-1) + -j * (x/(2.0*z)) ); We use floor and ceil in order to obtain the correct integer values for each coordinate for the left and the right line. First print out the values of left and right for each j. For example for input 7 4 4 you should get left right Once you have these values you know how many spaces to print to print the # at the right x coordinate to depict the line. Start off by printing the pyramid upside down. It will be a lot easier to write the loop you need. For 7 7 4 you should get ####### #..... #...# ### Then do the loop from the largest to the smallest value (subtracting one each time) to print the pyramid upright. One thing to keep in mind is that the point on the base of the pyramid should be drawn once, so we only need to compute values of x for each j from 1 to z. Draw the base of the pyramid separately. Now for 7 7 4 you should get the desired output that will pass the auto grader ### #...# #.....# ####### Examples Input 6 64 Output ## #. # #....# ###### Input 774 Output ### #...# #.....# ####### Input 1 1 1 Output Input 12 6 6 Output ## #.. #......# . ###### ###

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

Who are the main regulators of the life insurance industry? LO.1

Answered: 1 week ago