Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here I have started the program but need help finishing: #include using namespace std; const double PI = 3.1416; const char CIRCLE = 'c'; const

image text in transcribedimage text in transcribedimage text in transcribed

Here I have started the program but need help finishing:

#include using namespace std;

const double PI = 3.1416; const char CIRCLE = 'c'; const char SQUARE = 's'; const char RECTANGLE = 'r'; const char TRIANGLE = 't';

// add comments double getNumber(string label); char getShape(); void calcCircle(double radius, double& area, double& perimeter);

int main() { double area, perimeter; double radius; double side; double height; double width;

char shape = getShape(); switch (shape) { case CIRCLE: radius = getNumber("the radius"); calcCircle(radius, area, perimeter); cout

// finish the other shapes } }

void calcCircle(double radius, double& area, double& perimeter) { area = radius * radius* PI; perimeter = 2 * PI * radius; }

// add definition for rectangle, square and triangle double getNumber(string label) { // Insist on values in the range first...last cout > in_value; return in_value; }

char getShape() { char shape;

cout > shape; // clear any error flags on input cin.clear(); // flush the buffer cin.ignore(100, ' ');

return shape; }

CS 161 Programming Lab 7 Problem Description For this assignment, you are to compute the areas of four different geometric shapes: circle, square, rectangle, and triangle. For circle, square, and rectangle, you will also compute the perimeter. While this program requires the use of reference parameters, it will also be a review of functions, data validation, selection, and loops. Your functions should be split into function prototypes or declarations in a header file and function definitions in a code or source file. As part of the development process, you will need to write stubs for each of your functions to test that main works properly. The stubs should simply output their parameters. Note, in the final lab, the functions should not do any output, they should just do a calculation. For this, as in all assignments, you are expected to follow the course programming style guidelines. Program Functionality In main, the user will be asked to enter a character to choose which shape they want, c for circle, s for square, r for rectangle, t for triangle, and e for end. Define constants for these characters. Display clear instructions to the user Input a character code for a shape, either upper or lower case Select the proper function based on the code o C-circle, get radius, call circle function, display area & circumference E-end program R - rectangle, get length & width, call rectangle function, display area & perimeter S - square, get side, call square function, display area & perimeter T - triangle, get length & width, call triangle function, display area o invalid input, output an error message Continue looping until the user has entered E for end o o o o Use floating point values for all numbers. PI should be a constant equal to 3.14159. Required Functions Required Functions At a minimum the program should have the following functions: getNumber o gets a valid positive floating-point number o returns the value circle o o input is the radius calculates area (PI*r*r) and circumference (2*PI*r) passes back area and circumference via reference This work by Jim Bailey is licensed under a Creative Commons Attribution 4.0 International License. o O rectangle input is length and width o calculates the area (length*width) and perimeter(2*(length+width)) passes back area and perimeter via reference square input is length and width calculates the area (length*width) and perimeter(2*(length+width)) passes back area and perimeter via reference O O o O triangle input is length and width calculates the area (length*width/2) returns area via return O Tatiana Mbavad teataba . rectangle o input is length and width o calculates the area (length*width) and perimeter(2*(length+width)) o passes back area and perimeter via reference square o input is length and width o calculates the area (length*width) and perimeter(2*(length+width)) passes back area and perimeter via reference . o triangle input is length and width O calculates the area (length*width/2) returns area via return The function getNumber is used to get all input numbers. Your main program will get all input and display all output. Make sure that all parameters and return values are the correct types

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions