C++ programming problem


Question Description

This problem contains two part which are related, I will post them together.

The assignment 1's due date is 2 days from now.

The assignment 2's due date is 5 days from now.

So, please focus on the 1st assignment first.

Unformatted Attachment Preview

This is the first in a series of seven assignments (Assignments 1-4, 10, 11, 13) that will end with an object-oriented, GUI-based Windows program by the end of the semester. It begins as a console program, using coding techniques you've learned in prerequisite courses -- no object-oriented design (yet). Then as we learn new features of object-oriented programming, we'll refine and develop this original version until it takes full advantage of all that we'll learn in this course. For most of the series we'll be writing console programs. Once we learn enough about object-oriented syntax and design, we'll be ready to move to a GUI (graphical user interface) version of the program. Unfortunately there is not a common library for GUI programming in the standard C++ library. Instead there are add-ons included with some IDEs or supplied by 3rd parties for expanding your C++ installation to do GUI. A real nice option is "Qt" because it's free and works cross-platform. But there are licensing issues that make it not a desirable choice for a course like this. So since the DVC computer labs are equipped with Windows 10 workstations with Microsoft Visual Studio, that's what we'll be using for the lab assignments that involve GUI -- Assignments 12 to 15. Prepare to either install a version of Visual Studio (2015 or later) on your Windows PC (Win7 or later), or if that's not going to be possible (or if you only have a Mac), be prepared to spend some time in our computer lab in those weeks. The Shapes Program This program is the input and calculation "engine" for a drafting program we're writing (like SketchUp or AutoCad). While we'll never actually get there by the end of this course, it's the direction we're going and gives focus to our development efforts. Here is the specification for the Shapes program at this early stage of development. REQUIREMENTS: Write a C++ program named Shapes.1.cpp to calculate area, perimeter, surface area, and volume of common 2D and 3D shapes. The calculations for 8 shapes include: (reference: Geometric Formulae Review (Links to an external site.)Links to an external site. (http://www.purplemath.com/modules/geoform.htm)) • • • • • • area and perimeter of a 2D square area and perimeter of a 2D rectangle area and perimeter of a 2D circle area and perimeter of an 2D equilateral triangle surface area and volume of a 3D cube (a 2D square with a 3rd dimension) surface area and volume of a box (a 2D rectangle with a 3rd dimension) • • surface area and volume of a cylinder (a 2D circle with a 3rd dimension) surface area and volume of a prism (a 2D equilateral triangle with a 3rd dimension) NOTE: The "perimeter" of a circle is more commonly referred to as "circumference", but we're calling it perimeter. INPUT: The program input shall be from a text file named Shapes.input.txt, to be located in the same folder as the executable. The file shall consist of an unspecified number of lines. Each line of the file will specify one shape object, or be blank. The line format consists of (1) an object type in uppercase (SQUARE, RECTANGLE, CIRCLE, TRIANGLE, CUBE, BOX, CYLINDER, or PRISM), and (2) the dimensions of the object as follows: for square, 1 dimension: "side" for rectangle, 2 dimensions: "length" and "width" for circle, 1 dimension: "radius" for triangle, 1 dimension: "side" for cube, 1 dimension: "side" for box, 3 dimensions: "length", "width", and "height" for cylinder, 2 dimensions: "radius" and "height" for prism, 2 dimensions: "side" and "height" INPUT FILE FORMAT: A line of input may consist of up to 4 (four) usable "tokens", each separated by one or more spaces or tab characters. Ignore any tokens past the fourth token, if they exist. The first token is the object name (for example, "SQUARE"). The second through fourth tokens are dimensions. Some calculations need only one dimension (CIRCLE, SQUARE, CUBE, and TRIANGLE); others need two (RECTANGLE, CYLINDER, and PRISM) or three (BOX). There may be blank lines, which are to be ignored. HINT: If the number of tokens found in a parsed input line is (for example) 2, then only token[0] and token[1] exist. token[1] is the first dimension and there is no second dimension. So if the #of tokens > n, then token[n] exists. Otherwise it does not. The last line if the file marks the end of the file with uppercase EOF. It is possible for an invalid object to be specified, or for the wrong number of dimensions to be supplied. Here is a sample input file (which includes a blank line, and one pair of dimensions separated by more than one space): SQUARE 14.5 SQUARE <-- USE ZERO FOR THE MISSING "side" DIMENSIO N RECTANGLE 14.5 4.65 <-- IGNORE THE MULTI-SPACE SEPARATION BETWEE N DIMENSIONS CIRCLE 14.5 CUBE 13 BOX 1 2 3 SPHERE 2.4 CYLINDER 1.23 CYLINDER 50 1.23 TRIANGLE 1.2 3.2 EOF <-- IGNORE THIS BLANK -- SKIP OVER IT <-- IGNORE THIS UNKNOWN SHAPE <-- USE ZERO FOR THE MISSING 2ND DIMENSION <-- IGNORE THE EXTRA 2ND DIMENSION, 3.2 OUTPUT: Write results to two different sources -- the console screen and a TXT text file. Ref: chapter 10 of the optional, Burns textbook. CONSOLE OUTPUT FORMAT. Output the object name, its dimensions (1, 2, or 3 of them), and calculated results on one line. If the object is not recognized as one of the 8 allowable object types, produce output to this effect: "SPHERE invalid object". If the object is recognized, but there are not enough dimensions provided, use the default value of zero (0) for each missing dimension. The results for the above input should be as follows. Note the identifications of the dimensions and the calculated values. The dimensions and calculated results may appear in any order: SQUARE side=14.5 area=210.25 perimeter=58.00 SQUARE side=0 area=0.00 perimeter=0.00 RECTANGLE length=14.5 width=4.65 area=67.43 perimeter=38.30 CIRCLE radius=14.5 area=660.52 perimeter=91.11 CUBE side=13 surface area=1014.00 volume=2197.00 BOX length=1 width=2 height=3 surface area=22.00 volume=6.00 SPHERE invalid object CYLINDER radius=1.23 height=0 surface area=9.51 volume=0.00 CYLINDER radius=50 height=1.23 surface area=16094.37 volume=966 0.39 TRIANGLE side=1.2 area=0.62 perimeter=3.60 FILE OUTPUT FORMAT. Output to a TXT file named Shapes.output.txt in exactly the same format as the console output. But unlike the console output, skip invalid shapes -- only output valid shapes. ROUNDING: Format the calculated results to 2 digits after the decimal. But echo the input values without formatting. DO use the parsing function provided in this module. DO figure out how to handle missing dimensions -- there's more than one way. DO use the formatting code blocks modeled in this module. DO open your outputted TXT file in a text editor to see if it is formatted the same as the console output. DO include commented and cout'ed identification as modeled in Module 2. Submit Shapes.1.cpp for grading. Do NOT submit any TXT files. Rubric C++ coding assignment rubric (1) C++ coding assignment rubric (1) Criteria Ratings Pts This criterion is linked to a Learning OutcomeSource Code Content & Structure 80.0 pts This criterion is linked to a Learning OutcomeOutput Format 15.0 pts This criterion is linked to a Learning OutcomeFile Format/Submission Format 5.0 Total Points: 100.0 pts In the Shapes v.1 an input file was read and processed line-by-line. For possible use in a GUI program later, it would be important to read all of the input without immediate processing, and to process it all afterwards -- perhaps several times (for example, in a GUI window's "paint" function as the user pans and zooms). So to make that easier, the shapes described in the input file should be read, parsed, made into objects, and stored in a bag. Afterwards, the objects can be retrieved from the bag and we can use their supporting functions to output their metrics. That way they are stored in memory and we don't have to go back to the disk file every time we want to do something with the objects stored there. Copy Shapes.1.cpp from lab 1 to Shapes.2.cpp for this lab. Do not use more than one source file -- that means no .h files, and just a single .cpp. (To use multiple files would needlessly complicate this solution.) With one exception, the console output should match that of the lab 1 version. Unlike lab 1, read all of the file data before producing any object output. Only after the input file is read and closed, produce output for the objects. Here is the exception: any invalid object names will appear at the TOP of the console output list, outputted in the loop that reads the input file and stores the valid objects in a bag. Invalid objects are NOT stored in the bag, nor included in the TXT output, as they as ignored in any further processing. Program Changes Modify the program so that it includes struct s for each of the eight shapes that were the subject of lab 1. 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! 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 . 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. 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. Rubric C++ coding assignment rubric C++ coding assignment rubric Criteria Ratings Pts This criterion is linked to a Learning OutcomeSource Code Content & Structure Source Code Content & Structure 80.0 pts This criterion is linked to a Learning OutcomeOutput Format 15.0 pts This criterion is linked to a Learning OutcomeFile Format/Submission Format 5.0 Total Points: 100.0 pts ...
Purchase answer to see full attachment

Tutor Answer

School: UCLA


flag Report DMCA

Good stuff. Would use again.

Similar Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors