[SOLVED] c++ Creating Polyhedra

$25

File Name: c++_Creating_Polyhedra.zip
File Size: 207.24 KB

5/5 - (1 vote)

Creating Polyhedra

Read these general instructions on turning in assignmentsfor this course.

1 The Problem

This assignment deals with a program takes three types of Polyhedra from an input file and constructs the appropriate objects. These Polyhedra types are:

  • Sphere
  • Cylinder
  • Composite

The former two of these items are read as Polyhedra objects. A Composite Polyhedron is composed of one or more Polyhedra. The provided operator>>in Polyhedron.h
handles this mapping (through the PolyhedronFactory class). All three classes implement the Polyhedron interface.

In this exercise, you will be completing the Polyhedron Hierarchyspecifically the Cylinder and Composite classes.

1.1 Input

The program reads data from one file, polyhedra1.txt. File extensions on Linux may be arbitraryi.e., this file could have been named with .datas the extension.

sphere 1cylinder 2 1sphere 4cylinder 2 3composite 3sphere 3sphere 5sphere 7composite 2cylinder 1 2sphere 5sphere 3

Each polyhedron line is formatted as a keywordi.e., the name of the polyhedronand all appropriate attributes. A sphere is defined by a radius:

sphere 1

A cylinder with height 2 and radius 3 would take the form:

cylinder 2 3

A composite shape us defined by an integer representing the number, n, of polyhedra of which it is composed. It is then followed by npolyhedron input entries:

composite 2cylinder 1 2sphere 5

You may assume a valid input file. All input is well-formed.

The scaling parameter is specified as the second command line argument.

1.2 Output

The output consists of two reports written to standard output, one after the other.

  1. A report listing all polyhedra that were read from polyhedra1.txt.
  2. A report listing the result of scaling all polyhedra.

If the program is run with the polyhedra1.txt as the input file, the following output should be generated:

Original Polyhedra------------------------------------------------------[Sphere] (2, 2, 2)->Radius: 1 Diameter: 2[Cylinder] (2, 2, 2)->Radius: 1 Height: 2[Sphere] (8, 8, 8)->Radius: 4 Diameter: 8[Cylinder] (6, 6, 2)->Radius: 3 Height: 2[Composite] (14, 14, 14)->3 polyhedra[Sphere] (6, 6, 6)->Radius: 3 Diameter: 6[Sphere] (10, 10, 10)->Radius: 5 Diameter: 10[Sphere] (14, 14, 14)->Radius: 7 Diameter: 14[Composite] (10, 10, 10)->2 polyhedra[Cylinder] (4, 4, 1)->Radius: 2 Height: 1[Sphere] (10, 10, 10)->Radius: 5 Diameter: 10[Sphere] (6, 6, 6)->Radius: 3 Diameter: 6Scaled Polyhedra (Clones)------------------------------------------------------[Sphere] (4, 4, 4)->Radius: 2 Diameter: 4[Cylinder] (4, 4, 4)->Radius: 2 Height: 4[Sphere] (16, 16, 16)->Radius: 8 Diameter: 16[Cylinder] (12, 12, 4)->Radius: 6 Height: 4[Composite] (28, 28, 28)->3 polyhedra[Sphere] (12, 12, 12)->Radius: 6 Diameter: 12[Sphere] (20, 20, 20)->Radius: 10 Diameter: 20[Sphere] (28, 28, 28)->Radius: 14 Diameter: 28[Composite] (20, 20, 20)->2 polyhedra[Cylinder] (8, 8, 2)->Radius: 4 Height: 2[Sphere] (20, 20, 20)->Radius: 10 Diameter: 20[Sphere] (12, 12, 12)->Radius: 6 Diameter: 12

The easiest way to see generate the expected output is to run the sample executable solution I have provided. These two files are named as command-line parameters when the program is executed.

For example, if the sample data above is kept in polyhedra1.txt, to run this program, type:

 ./createPolyhedra polyhedra1.txt 2

Run the compiled solution with both the provided input file and your own test input files.

Once you have completed your solution, compare the output generated by your solution to the output generated by my solution. The two sets must be identical.

(On a Windows system, you would omit the ./. If you are running from Code::Blocks or a similar development environment, you may need to review how to supply command-line parametersto a running program.)

1.3 Your Tasks

  1. Complete display , read , clone , and scale functions for both Cylinder and Composite.
    • I was fealing generous and provided you the Composite::display method.
  2. Complete the Big-3 for Composite
    • Note that the Composite::polyhedra attribute, Polyhedron** polyhedra is an array of pointers. You will need to make use of the appropriate new , delete , and delete[] commands.
    • While you should strive to complete these functions without introducing memory leaks, memory leaks will not be evaluated during grading.
    • I was fealing generous and provided you the Composite::operator= method. This leaves you with the Copy Constructor and Destructor (2 of the Big-3).
  3. Optional : You may add supplemental member functions to the Cylinder class (Cylinder.h and Cylinder.cpp).

2 Mechanics

2.1 Grading

Tests 000 through 006 evaluate your program as a whole:

  • Test 000 confirms that your code compiles and runs without segmentation faults. This test discards all output.
  • Tests 001-002 evaluate how your program runs given input file consisting only of Cylinder objects. These tests disregard output formatting.
  • Test 003-004 evaluate how your program runs given input file consisting only of Composite objects. These tests disregard output formatting.
  • Test 005-006 evaluate how your program runs given input file consisting of both Cylinder and Composite objects. Theses tests include output formatting.

With the exception of Test 000, each of the above:

  • Odd numbered tests apply a scaling factor of 1 (i.e., do not evaluate your scaling functions).
  • Even numbered tests apply a scaling factor

2.2 Common Mistakes & Hints

  1. Many students forget to scale the bounding boxes. This can be done using the BoundingBox::scale or Polyhedron::scale functions.
  2. Many students are not sure where to start with output. Check the Polyhedron::display method. You may cough be able to use cough it to genenerate the Polyhedron name and bounding box portions of the output.
  3. Ask Questions. Come to Office Hours and make use of email.

2.3 Files

Files for this assignment appear in this directoryor, if you are logged in to a CS Dept Linux server, in ~cs330/Assignments/polyhedra_oop.

2.4 Submitting

Files to Submit:

  • Cylinder.h
  • Cylinder.cpp
  • Composite.cpp

Note that your submitted code must compile correctlyon our Unix workstationswith the other code in that directory, using the compilation commands generated by the provided makefile. Do not alter any of the other source code files, nor change the Inventory interface in such a way that it can only be compiled with some other compiler or some other sequence of commands.

To submit your assignment, use the button below. You will receive a preliminary grade via email (to your ODU email account) and will also be able to check your grade from the course web page Gradesbutton. This preliminary grade report will include any compilation errors encountered when compiling your code.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] c++ Creating Polyhedra
$25