Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Shapes . 1 . cpp #include #include #include #include #include #include using namespace std; void calculateSquare ( double side ) { double area = side

Shapes.1.cpp
#include
#include
#include
#include
#include
#include
using namespace std;
void calculateSquare(double side){
double area = side * side;
double perimeter =4* side;
cout "SQUARE side=" side " area=" area " perimeter=" perimeter endl;
}
void calculateRectangle(double length, double width){
double area = length * width;
double perimeter =2*(length + width);
cout "RECTANGLE length=" length " width=" width " area=" area " perimeter=" perimeter endl;
}
void calculateCircle(double radius){
double area = M_PI * radius * radius;
double perimeter =2* M_PI * radius;
cout "CIRCLE radius=" radius " area=" area " perimeter=" perimeter endl;
}
void calculateCube(double side){
double surfaceArea =6* side * side;
double volume = side * side * side;
cout "CUBE side=" side " surface area=" surfaceArea " volume=" volume endl;
}
void calculateBox(double length, double width, double height){
double surfaceArea =2*(length * width + length * height + width * height);
double volume = length * width * height;
cout "BOX length=" length " width=" width " height=" height " surface area=" surfaceArea " volume=" volume endl;
}
void calculateCylinder(double radius, double height){
double surfaceArea =2* M_PI * radius *(radius + height);
double volume = M_PI * radius * radius * height;
cout "CYLINDER radius=" radius " height=" height " surface area=" surfaceArea " volume=" volume endl;
}
void calculatePrism(double side, double height){
double area =(sqrt(3)/4)* side * side;
double surfaceArea =3* area +2* side * height;
double volume = area * height;
cout "PRISM side=" side " height=" height " surface area=" surfaceArea " volume=" volume endl;
}
void handleInvalidObject(const string& objectName){
cout objectName " invalid object" endl;
}
int main(){
ifstream inputFile("Shapes.input.txt");
string line;
while (getline(inputFile, line)){
if (line.empty()){
continue;
}
istringstream iss(line);
string shape;
iss >> shape;
if (shape == "SQUARE"){
double side =0;
iss >> side;
if (side >0){
calculateSquare(side);
} else {
handleInvalidObject("SQUARE");
}
} else if (shape == "RECTANGLE"){
double length =0, width =0;
iss >> length >> width;
if (length >0 && width >0){
calculateRectangle(length, width);
} else {
handleInvalidObject("RECTANGLE");
}
} else if (shape == "CIRCLE"){
double radius =0;
iss >> radius;
if (radius >0){
calculateCircle(radius);
} else {
handleInvalidObject("CIRCLE");
}
} else if (shape == "CUBE"){
double side =0;
iss >> side;
if (side >0){
calculateCube(side);
} else {
handleInvalidObject("CUBE");
}
} else if (shape == "BOX"){
double length =0, width =0, height =0;
iss >> length >> width >> height;
if (length >0 && width >0 && height >0){
calculateBox(length, width, height);
} else {
handleInvalidObject("BOX");
}
} else if (shape == "CYLINDER"){
double radius =0, height =0;
iss >> radius >> height;
if (radius >0 && height >=0){
calculateCylinder(radius, height);
} else {
handleInvalidObject("CYLINDER");
}
} else if (shape == "PRISM"){
double side =0, prismHeight =0;
iss >> side >> prismHeight;
if (side >0 && prismHeight >=0){
calculatePrism(side, prismHeight);
} else {
handleInvalidObject("PRISM");
}
} else {
handleInvalidObject(shape);
}
}
inputFile.close();
return 0;
}
image text in transcribed

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

What are the exceptions to solicitation allegations?

Answered: 1 week ago