首页 > > 详细

CS 435编程辅导、C++程序调试、辅导c/c++程序辅导R语言编程|辅导Web开发

CS 435/535 Assignment #5 – Spring 2021
Project Overview: This project investigates polymorphism in C++. In C++, polymorphism allows the main
function to be written before an actual class is defined. In this project, you will download from Blackboard the file
main.cpp that contains the main function and the two files (Shape.h and Shape.cpp) that define a base
class named Shape. The Shape base class has a name represented by a private instance variable called name, but
it does not have any other details on the shape. However, the base class has four (4) pure virtual functions: getArea
(it is supposed to compute the surface area of the shape), getVolume (to compute the volume of the shape), test
(to test whether the shape satisfies a list of conditions), and getInfo (to form a string that describes the shape).
You are asked to write four (4) derived classes: Sphere, Cylinder, Cone, and Cuboid. For detailed information
on these four particular shapes, please refer to https://www.mathsisfun.com/geometry/common-3d-shapes.html.
The website also shows how to compute the surface area and the volume of these four shapes. The relationship
between the base class and these four derived classes is shown below. These four derived classes have added their
own instance variables to describe the details of the corresponding shapes. For each derived class, you need to have
one header file (with the .h extension) and one implementation file (with the .cpp extension). However, you can
use any name for the file, any name for the class, and any names for instance variables. The main function does not
need to know the class names you will use. The only requirement is that each derived class must be derived from the
Shape base class, which will force you to implement the four virtual functions in the derived class. Polymorphism
enables the main function to invoke a function of a derived class in the future by just calling the corresponding virtual function of the base
class.
To test the program, we assume that the shapes will be stored in a data file that will be passed to the program as a
command line argument. Each shape will occupy one line in the data file. Each line starts with the that is a
string, followed by the type (sphere, cylinder, cone or cuboid). The rest will be doubles to represent the
dimensions of the shape.
sphere
cylinder
cone
cuboid
You can download a sample data file named shapes.dat from Blackboard for an example. It contains the
following shapes.
Cube#1 cuboid 1 1 1
Cube#2 cuboid 2 2 2
Cone#1 cone 1 1
Cyl#1 cylinder 1 1
Box#1 cuboid 2 4 6
Box#2 cuboid 10.5 21 10.5
UnitSphere sphere 1
LargeSphere sphere 100
Cone#2 cone 1 2
Cyl#2 cylinder 1 2
You need to write a function named readFrom that will return a pointer to a vector of shapes read from a data file
with its name given as a parameter to the function. The function has the following signature.
std::vector

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!