Question: 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;
}
 Shapes.1.cpp #include #include #include #include #include #include using namespace std; void

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!