C++ code
Circle + Circle Rectangle + Rectangle Rectangle + Circle Circle - Circle Rectangle - Rectangle Rectangle - Circle Box - Cylinder |
Box+Cylinder Box + Box Box -Box Rectangle + Box Box + Circle Box - Circle Rectangle - Box |
Cylinder + Cylinder Rectangle + Cylinder Cylinder + Circle Cylinder - Circle Rectangle - Cylinder Cylinder - Cylinder |
Box * Box Cylinder * Cylinder Box * Cylinder |
Box / Box Cylinder / Cylinder Box / Cylinder |
#include<iostream>
using namespace std;
class Shape2D
{
protected:
float area;
public:
Shape2D()
{
area = 0;
}
Shape2D(float a)
{
area = a;
}
float getArea()
{
return area;
}
friend Shape2D operator + (Shape2D &s1, Shape2D &s2)
{
Shape2D temp;
temp.area = s1.getArea()+ s2.getArea();
return temp;
}
};
class Rectangle : public Shape2D
{
float length, width;
public:
Rectangle()
{
length = width = 0;
}
Rectangle(float l, float w) : Shape2D(0.0f)
{
length = l;
width = w;
area = length * width;
}
};
class Circle : public Shape2D
{
float radius;
public:
Circle()
{
radius = 0;
}
Circle(float r) : Shape2D(0.0f)
{
radius = r;
area = 3.141f r r;
}
};
int main()
{
Rectangle rr1(2, 3), rr2(3, 4);
Circle c1(5), c2(3), c3;
Shape2D &r1 = rr1, &r2 = rr2, r3;
r3 = r1 + r2;
cout<<"\n Rectangle + Rectangle: "<<r3.getArea();
r1 = c1; r2 = c2;
r3 = r1 + r2;
cout<<"\n Circle + Circle: "<<r3.getArea();
r1 = rr1; r2 = c1;
r3 = r1 + r2;
cout<<"\n Circle + Rectangle: "<<r3.getArea();
}
Sample Output:
Rectangle + Rectangle: 18
Circle + Circle: 106.794
Circle + Rectangle: 157.05
C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized...
using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship (all attributes private) String attribute for the name of ship float attribute for the maximum speed the of ship int attribute for the year the ship was built Add the following behaviors constructor(default and parameterized) , finalizer, and appropriate accessor and mutator methods Override the toString() method to output in the following format if the attributes were name="Sailboat Sally", speed=35.0f and year built of...
Program must be written in C++: Create a parent class called CompSciProfessor. Each professor has name (type string), email (type string), and facultyId (type long). Specialize the CompSciProfessor class into two more classes: AdjunctProf, and TenureTrackProf classes. The specialized class AdjunctProf has three attributes of its own: degree (type char), NoOfTA (type int), and NoOfCourses (type int). The attribute ‘degree’ refers to the degree of the adjunct professor. You assign ‘B’ to represent bachelor degree, ‘M’ for Master degree, and...
C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Please use C++ and Please do all file separate separately. And also I need output too. thanks. Please do it complete work. ShapeNodePoly.cpp Avaliable from: Wednesday, July 27, 2016, 10:20 AM Requested files: Point.h, Point.cpp, Shape.h, Shape.cpp, Polygon.h, Polygon.cpp, Ellipse.h, Ellipse.cpp, ShapeNodePoly.cpp, ShapeNodePoly_test.cpp (Download) Type of work: Individual work In this assignment, you will create a class that can behave as any of the shapes listed below. You will use object inheritance to enable all shapes to be managed using...
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...
in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base classes. Circle int r; void area(); void perimeter(); void volume(); //No volume for circle Sphere int r; void area();//Sphere surface area= 4 × pi × radius2 void perimeter(); //No perimeter for Sphere void volume();//Sphere volume= 4/3 × pi × radius2 Cylinder int r, height; void area();// Cylinder surface area=perimeter of...
code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...