Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include #include #define PI 3.14159265359 using namespace std; int main() { ifstream in(Shapes.input.txt); ofstream out(Shapes.output.txt); stringstream sstr; map shapes; string shape,

#include

#include

#include

#include

#include

#include

#define PI 3.14159265359

using namespace std;

int main() {

ifstream in("Shapes.input.txt");

ofstream out("Shapes.output.txt");

stringstream sstr;

map shapes;

string shape, line;

float length, width, height, area, peri, volume;

//variable declaration

shapes.insert(pair("SQUARE", 1));

shapes.insert(pair("RECTANGLE", 2));

shapes.insert(pair("CIRCLE", 3));

shapes.insert(pair("TRIANGLE", 4));

shapes.insert(pair("CUBE", 5));

shapes.insert(pair("BOX", 6));

shapes.insert(pair("CYLINDER", 7));

shapes.insert(pair("PRISM", 8));

shapes.insert(pair("EOF", 9));

if (in.fail() || out.fail()) {

cout

return -1;

}

cout.precision(2);

cout

out.precision(2);

out

while (getline(in, line))

{

length = width = height = 0;

sstr

if (sstr >> shape) {

switch (shapes[shape]) {

case 1: //Square

sstr >> length;

area = length * length;

peri = 4.0 * length;

cout

out

break;

case 2: //Rectangle

sstr >> length >> width;

area = (length * width);

peri = 2.0 * (length + width);

cout

out

break;

case 3: //Circle

sstr >> length;

area = PI * (length * length);

peri = 2 * PI * length;

cout

out

break;

case 4: //Triangle

sstr >> length;

area = (1.732 * length * length) / 4.0;

peri = 3.0 * length;

cout

out

break;

case 5: //Cube

sstr >> length;

area = 6 * length * length;

volume = length * length * length;

cout

out

break;

case 6: //BOX

sstr >> length >> width >> height;

area = 2.0 * (length * width + length * height + width * height);

volume = length * width * height;

cout

out

break;

case 7: //Cylinder

sstr >> length >> height;

area = 2.0 * PI * length * (length + height);

volume = PI * length * length * height;

cout

out

break;

case 8: //Prism

sstr >> length >> height;

area = 3.0 * (length * height) + (1.732 * length * length) / 2.0;

volume = (1.732 * length * length * height) / 4.0;

cout

out

break;

case 9:

break;

default:

cout

}

}

sstr.str(string());

sstr.clear();

}

in.close();

out.close();

return 0;

}

-------- previous code----

Thank you

image text in transcribed

Program Changes 1. Modify the program so that it includes struct s for each of the eight shapes that were the subject of Assignment 2. Name these as follows: Square, Rectangle, Circle, Triangle, Cube, Box, Cylinder, and Prism. Include attributes of the double data type for the required dimensions for each (for example, length and width for the Rectangle). Provide a descriptive name for each of these data elements (for example, "radius" instead of "r"). Do NOT include any other attributes, and do NOT include any "member functions" -- avoid the temptation to extend the specifications beyond what is required. If you include attributes for area, volume, or perimeter, you are not doing this right! 2. Write supporting functions to do console output each shape (for example, void outputBox(ostream&, const Box&); ), which should output to either cout or fout -- whichever is the first parameter in a call, using the same format as v.1. Note that cout is an object of type ostream. So use cout as the first parameter in the function call in order to produce console output. Use the exact same supporting functions for text file output, which should output to fout. Create, open, and close fout in int main . fout is also an object of type ostream. Remember, the ROUNDING Format - the calculated results to 2 digits after the decimal (out.setflios::fixed); out.precision(2); ). But echo the input values without formatting. (out.unsetf(ios::fixed); out.precision(6):) 3. Use any type of array for your bag -- C, C++, or STL vector -- your choice. STL vectors track their or size, so if you use a C or C++ array instead, you'll have to use an int to track size yourself. 4. Write 4 loops -- one to process the input file and fill the bag, one for console output, one for TXT output, and one for deallocation. If you don't have 4 loops, or if you do more than one of these things in any single loop, you're not doing this right! Submit Shapes.2.cpp for grading

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

8. Praise the trainees for their success in learning the task.

Answered: 1 week ago