CECS 282
LAB ASSIGNMENT 6
Assigned date: 10/15
Due date: 10/22
20 points
Before doing this lab assignment, you need to do the following activities:
Problem 1 [10 points]
In this problem, you will create an inheritance hierarchy for classes pointType, circleType, and cylinderType. Use the pointType class as a base class of hierarchy. The following files are provided to the problem.
You need to implement the file cylinderTypeImp.cpp.
Create a Win 32 console application, add the header files, the implementation files including cylinderTypeImp.cpp and the testmain.cpp. Your output should shown as below:
***** Cylinder 1 *****
Base Center: (3.00, 2.50)
Base Radius: 4.00
Base Circumference: 25.13
Base Area: 50.27
Cylinder height: 2.50
Cylinder surface area: 62.83
Cylinder volume: 125.66
***** Cylinder 2 *****
Base Center: (-2.50, 7.00)
Base Radius: 4.00
Base Circumference: 25.13
Base Area: 50.27
Cylinder height: 3.90
Cylinder surface area: 98.02
Cylinder volume: 196.04
Enter x Coordinates of the center: 1
Enter y Coordinate of the center: 2
Enter base radius: 10.0
Enter cylinder height: 20.0
***** Cylinder 3 *****
Base Center: (1.00, 2.00)
Base Radius: 10.00
Base Circumference: 62.83
Base Area: 314.16
Cylinder height: 20.00
Cylinder surface area: 1256.64
Cylinder volume: 6283.20
Supplemental code
The header files, implementation files and the main files are provided below:
pointType.h
#ifndef H_PointType
#define H_PointType
class pointType
{
public:
void setPoint(double x, double y);
void print() const;
double getX() const;
double getY() const;
pointType(double x = 0.0, double y = 0.0);
protected:
double xCoordinate;
double yCoordinate;
};
#endif
pointTypeImp.cpp
//Implementation File pointTypeImp.cpp
#include <iostream>
#include "pointType.h"
using namespace std;
void pointType::setPoint(double x, double y)
{
xCoordinate = x;
yCoordinate = y;
}
void pointType::print() const
{
cout << "(" << xCoordinate << ", " << yCoordinate << ")" << endl;
}
double pointType::getX() const
{
return xCoordinate;
}
double pointType::getY() const
{
return yCoordinate;
}
pointType::pointType(double x, double y)
{
xCoordinate = x;
yCoordinate = y;
}
circleType.h
//Class circleType
#ifndef H_CircleType
#define H_CircleType
#include "pointType.h"
class circleType: public pointType
{
public:
void print() const;
void setRadius(double r);
double getRadius() const;
double getCircumference() const;
double getArea() const;
circleType(double x = 0.0, double y = 0.0, double r = 0.0);
protected:
double radius;
};
#endif
circleTypeImp.cpp
//Implementation file circleTypeImp.cpp
#include <iostream>
#include "circleType.h"
using namespace std;
void circleType::print() const
{
cout << "Center: ";
pointType::print();
cout << endl;
cout << "Radius: " << radius << endl;
cout << "Circumference: " << getCircumference() << endl;
cout << "Area: " << getArea() << endl;
}
void circleType::setRadius(double r)
{
radius = r;
}
double circleType::getRadius() const
{
return radius;
}
double circleType::getCircumference() const
{
return (2 * 3.1416 * radius);
}
double circleType::getArea() const
{
return (3.1416 * radius * radius);
}
circleType::circleType(double x, double y, double r)
:pointType(x,y)
{
radius = r;
}
cylinderType.h
//Class cylinderType
#ifndef H_CylinderType
#define H_CylinderType
#include "circleType.h"
class cylinderType: public circleType
{
public:
void print() const;
void setHeight(double h);
void setBaseCenter(double x, double y);
void setCenterRadiusHeight(double x, double y,
double r, double h);
double getHeight() const;
double getVolume() const;
double getSurfaceArea() const;
cylinderType(double x = 0.0, double y = 0.0,
double r = 0.0, double h = 0.0);
protected:
double height;
};
#endif
#include "cylinderType.h"
using namespace std;
int main()
{
cylinderType cylinder1(3, 2.5, 4, 2.5);
cylinderType cylinder2;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "***** Cylinder 1 *****" << endl;
cylinder1.print();
cout << endl;
cylinder2.setPoint(-2.5, 7);
cylinder2.setRadius(4);
cylinder2.setHeight(3.9);
cout << "***** Cylinder 2 *****" << endl;
cylinder2.print();
cout << endl;
double x, y;
double r;
double h;
cylinderType cylinder3;
cout << "Enter x Coordinates of the center: ";
cin >> x;
cout << endl;
cout << "Enter y Coordinate of the center: ";
cin >> y;
cout << endl;
cout << "Enter base radius: ";
cin >> r;
cout << endl;
cout << "Enter cylinder height: ";
cin >> h;
cout << endl;
cylinder3.setCenterRadiusHeight(x, y, r, h);
cout << "***** Cylinder 3 *****" << endl;
cylinder3.print();
cout << endl;
return 0;
}
GRADING
2. [10 points] A publishing company that markets both hard copy book and ebook version of its work. Create a class publication that store the title and price of a publication. From this class derive two classes: book, which add a page count and digital, which add a storage capacity in MG bytes. Each of these there classes should have a getdata() function to get its data from the user at the keyboard, and put a putdata() function to display its data.
Add a base class sales that hold an array of three floats so that it can record the dollar sales of particular publication for the last three months. Include a getData() function to get three sales amount from the user and a putdata() function to display the sales figures. Modify the book and digital classes so they are derived from both publication and sales. An object of class book or digital should input and output sales data along with its other data. Write a main function to create a book object and a digital object and test their input and output capabilities.
GRADING