Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help finishing code so that it looks like examples below. Shows all shapes and invalid inputs. The code below the attachments was given and

Need help finishing code so that it looks like examples below. Shows all shapes and invalid inputs. The code below the attachments was given and needs to be fixed in order to show the code that is shown in the examples. Trying to figure out how to make the code work in order to get the same output. Could you please show output after coded.

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;

}

AT&T 3:57 PM 73% K Project 3 proj 3.pdf one or more compiler emors will result in a grade of zero on this assignment. Page2 Correctness lseptsl 80 points for correct output on various test cases. You can assume that will test your by inputting character shapes and integer lengths and heights, but you cannot Program assume the character or integer inputs are valid your program must handle when haracter or integer input is invalid). Project Submission After you have tested, tested, and retested that your code compiles and run correctly on many test cases (those provided in thisdocument and test cases that you create on your own. submit the file proj3.c (and only that file) via our Canvas CPSC l011 course website under this project's f you have any questions about how to submit your project, then you'll need ask your lab instructor days before the assignment is due) After you submit file(s) on Canvas for this program and other programs that you write this always double check that you submitted the correct filets) do this download your submission from Canvas, view it, and make sure the submitted file(s) compiles and nuns on our machines Examples Your program should work correctly on the examples below, issource code should be compiled with the command aforementioned to produce an executable called proj3-out, and it should draw various shapes comectly when the inputs are valid and output the messages shownin the examples below when it detects an invalid input. All input and output should be formatted as shown when nur via the command line on our Unix machines (note: the new lines saparating each example is not part of your program it is in this document show the difference between examples Each example is separate nun of a correctly working program. Some examples include invalid inputs, and some examples include Unix commands that provide alternative ways to input data into your program. /proj out Enter a shape r tho P Enter a length Enter a height Below is a 3 by 4 rectangle of Page 3 Courses To Do Notifications Messages Calendar

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_2

Step: 3

blur-text-image_3

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

What type of IT architecture is windows 7

Answered: 1 week ago