Uploaded on September 16 Due on September 26, 11:30 pm on the Blackboard without
ID: 3754400 • Letter: U
Question
Uploaded on September 16 Due on September 26, 11:30 pm on the Blackboard without a penalty Final submission on the Blackboard on September 29, 11:30 PM with 20% penalty formal parameters What to submit: 1. Upload a zip file on the blackboard which contains your code (do not forget comments), your UML diagram, exe file and output 2. Additionally submit a printout of your code, your UML diagram and output by the due date at the beginning of the class. Do not Il CSC 330 Hw1 ll Your Name Late submissions (up to 3 days after the due date, where Sat and Sun will be counted as well uploaded on the Blackboard and printouts after the due date will be penalized 20 %. All printouts must be submitted (left on my desk) before the start of the class. Your Blackboard submission will not be checked if I don't have your printout. NO submissions will be accepted after Final Submission date. ASSIGNMENT SUBMISSION When finished, make sure to click Submit. Optionally, click Save as Draft to save changes and continue working later, or click Cancel to quit without saving ch Cance sejd%3D_161 6649-1 %26content,id%3D,35885945-1 %26mode%3Dr
Explanation / Answer
ScreenShot
-------------------------------------------
Program
//Header class
#include<iostream>
#include<string>
using namespace std;
//Class Point2D
class Point2D {
//Member variables
protected:
int x;
int y;
//Member functions
public:
//Default constructor
Point2D() {
x = 0;
y = 0;
}
//Parameterised constructor
Point2D(int x,int y) {
this->x = x;
this->y = y;
}
//Setters
void setX(int x) {
this->x = x;
}
void setY(int y) {
this->y = y;
}
//Getters
int getX()
{
return x;
}
int getY()
{
return y;
}
//Equal check
bool equal(const Point2D &p) {
if (this->x == p.x&&this->y == p.y) {
return true;
}
else {
return false;
}
}
void print() {
cout << "X= " <<x<<" Y= "<<y<<endl;
}
};
class Circle:public Point2D {
//Member Variables
protected:
double radius;
//Member Functions
public:
//Default constructor
Circle() {
radius = 0.0;
x = 0;
y = 0;
}
//Parameterised constructor
Circle(double r,int x,int y) {
radius = r;
this->x = x;
this->y = y;
}
//Setter
void setRadius(double r) {
radius = r;
}
/*void setX(int x) {
this->x = x;
}
void setY(int y) {
this->y = y;
}*/
//Getter
double getRadius() {
return radius;
}
/*int getX() {
return x;
}
int getY() {
return y;
}*/
//Equal check
bool equal(const Circle &c) {
if (this->radius==c.radius) {
return true;
}
else {
return false;
}
}
//Area
double area() {
return 3.14*(radius*radius);
}
//Distance methods
double distance(Point2D &p) {
return sqrt(pow(this->x -p.getX(), 2) + pow(this->y -p.getX(), 2));
}
double distance(Circle &c2) {
return sqrt(pow(c2.x - this->x, 2) + pow(c2.y - this->y, 2));
}
void print() {
cout << "Radius of the circle= " << radius << " Area= "<<area()<<endl;
}
};
class Cyllinder :public Circle {
//Member Variables
private:
double height;
//Member Functions
public:
//Default constructor
Cyllinder() {
height = 0.0;
radius = 0;
}
//Parameterised constructor
Cyllinder(double h,double r) {
height = h;
radius = r;
}
//Setter
void setHeight(double h) {
height = h;
}
//Getter
double getHeight() {
return height;
}
//Equal check
bool equal(const Cyllinder &c) {
if (this->height == c.height) {
return true;
}
else {
return false;
}
}
double area() {
return (2*3.14*(radius*radius))+(height*(2*3.14*radius));
}
double volume() {
return (2 * 3.14*radius*height);
}
void print() {
cout << "Height of the cyllinder= " << height << " Area= " << area() << " Volume= " << volume() << endl;
}
};
//Non member functions
double distance(Point2D &p,Circle &c) {
return sqrt(pow(c.getX() - p.getX(), 2) + pow(c.getY() - p.getY(), 2));
}
double distance(Circle &c1, Circle &c2) {
return sqrt(pow(c2.getX() - c1.getX(), 2) + pow(c2.getY() - c1.getY(), 2));
}
int main()
{
//Two object of Point2D class
Point2D p(1, 2);
Point2D p1(1, 2);
//Check meber functions
cout<<p.equal(p1)<<endl;
p.print();
////Two object of Circle class
Circle c(3,1,2);
Circle c1(4,3,4);
//Distance method call
cout << "Distance from origin to object= "<<c.distance(p1) << endl;
cout << "Distance from center to center= " << c.distance(c1) << endl;
//Distance with non memebr function method
cout << "Distance from origin to object(Non member)= " << distance(p,c1) << endl;
cout << "Distance from center to center(Non member)= " << distance(c,c1) << endl;
//Area of the circle
c.print();
//Two object of cyllinder
Cyllinder cl1(4,3);
Cyllinder cl2(5,2);
//Print details
cl1.print();
//Object pointer
Point2D *ptr;
ptr = &p;
p.print();
Circle *circle;
circle = &c1;
circle->print();
Cyllinder *cl;
cl = &cl2;
cl->print();
//Alias
Circle &c3=c;
c3.print();
//Array object
Point2D pd[2];
Circle cir[2];
Cyllinder cyl[2];
//One printing example
pd[0].setX(p.getX());
pd[0].setY(p.getY());
pd[1].setX(p1.getX());
pd[1].setY(p1.getY());
for (int i = 0; i < 2; i++) {
pd[i].print();
}
return 0;
}
------------------------------
Output
Both points are same
X= 1 Y= 2
Distance from origin to object= 1
Distance from center to center= 2.82843
Distance from origin to object(Non member)= 2.82843
Distance from center to center(Non member)= 2.82843
Radius of the circle= 3 Area= 28.26
Height of the cyllinder= 4 Area= 131.88 Volume= 75.36
X= 1 Y= 2
Radius of the circle= 4 Area= 50.24
Height of the cyllinder= 5 Area= 87.92 Volume= 62.8
Radius of the circle= 3 Area= 28.26
X= 1 Y= 2
X= 1 Y= 2
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.