Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help coding this program. Directions are on the attachments. It needs to show the same output as the following examples below. The code below was

Help coding this program. Directions are on the attachments. It needs to show the same output as the following examples below. The code below was given and needs to be changed so it will print the same output. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
#include
#include
#include
//Global variables for loop indicies
int i, j;
//Get a shape from a user, and return the shape if it is valid;
// otherwise, print an error message and terminate the program
char getShapeFromUser(void);
//Get a length from a user, and return the length if it is valid;
// otherwise, print an error message and terminate the program
int getLengthFromUser(void);
//Get a height from a user, and return the height if it is valid;
// otherwise, print an error message and terminate the program
int getHeightFromUser(void);
bool isShapeValid(char shape);
bool isLengthValid(int length);
bool isHeightValid(int height);
void drawRectangle(int length, int height);
void drawTriangle(int length);
void drawHexagon(int length);
void drawOctagon(int length);
void drawPentagon(int length);
//Do not modify the main function
int main(void){
char shape = getShapeFromUser();
int length = getLengthFromUser();
int height;
if(shape == 'r'){
height = getHeightFromUser();
printf("Below is a %d by %d rectangle of * ", length, height);
drawRectangle(length, height);
}
else if(shape == 't'){
printf("Below is a triangle with two side lengths of %d * ", length);
drawTriangle(length);
}
else if(shape == 'h'){
printf("Below is a hexagon with side lengths of %d * ", length);
drawHexagon(length);
}
else if(shape == 'o'){
printf("Below is an octagon with side lengths of %d * ", length);
drawOctagon(length);
}
else if(shape == 'p'){
printf("Below is a pentagon with 4 side lengths of %d * ", length);
drawPentagon(length);
}
return 0;
}
//Implement function prototypes below
char getShapeFromUser(void){
char shape = '\0';
printf("Enter a shape: r t h o p ");
scanf("%c", &shape);
if( !isShapeValid(shape) ){
printf("Invalid shape Goodbye! ");
exit(0);
}
return shape;
}
int getLengthFromUser(void){
int length = 0;
printf("Enter a length ");
scanf("%d", &length);
if( !isLengthValid(length) ){
printf("Length must be greater than 1 Goodbye! ");
exit(0);
}
return length;
}
int getHeightFromUser(void){
int height = 0;
printf("Enter a height ");
scanf("%d", &height);
if( !isHeightValid(height) ){
printf("Height must be greater than 1 Goodbye! ");
exit(0);
}
return height;
}
gcc Wall g proj3.c o proj3.out Program Requirements l. Below the main function in provided file proj3.c, implement all the function prototypes correctly. You'll need to study the main function, the function prototypes, and examples in this document to figure out how to correctly implement these functions. Note: the first three functions are already implemented, and you should not modify their code; however, reading and studying these functions should give you an idea on where to start 2. Do not modify any of the function prototypes at the top of proj3.c 3. Do not modify the main function in any way in proj3.c. The main function will work correctly once you finish implementing all the function prototypes. Modifying the main function in any way will result in grade of0 on this project. 4. You may use your own code from your previous project to implement the functions for this project, but you'll need to modify the code to match our examples (note: triangle and pentagon shapes are different in this project than the previous project). However, if you did not complete the previous project, then you'll have a lot of extra work to do for this project because you cannot use anyone else's code (the use ofanyone else's code besides what we provide will be considered as cheating). Ifsomeone asks to see your code for this project or a previous project, then you must tell them no (otherwise, we will consider that as cheating by providing unauthorized assistance). 5. You will need to comment all function prototypes with a brief description of that that function does. The first three function prototypes are already commented, and you can use those comments in your project. 6. The instructions in this document must be followed in order for full credit to be awarded. Following the instructions is a vital part to this and all programming assignments. 7. Your program must follow the examples provided in the Examples section, and your program's I/O (input and output) must match the examples exactly (otherwise, points will be deducted) when run on our Unix machines, which means you'll need to spend time studying the examples and testing your program in various ways. If your program doe not produce the same output as our examples, then your program has a bug, and you'll need to fix any bugs using gdbor other debugging techniques

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

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

What is the relationship between diversity, inclusion, and equity?

Answered: 1 week ago