Professional Documents
Culture Documents
Object Oriented Programming: Assignment # 01
Object Oriented Programming: Assignment # 01
Object Oriented Programming: Assignment # 01
Total Marks: 04
Obtained Marks:
Object Oriented
Programming
Assignment # 01
Last date of Submission: 20 February 2019
Student Name:
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Instructions: Copied or shown assignments will be marked zero. Late submissions are not
entertained in any case.
Question
A class called Circle is to be defined as illustrated in the class diagram. It contains two
data members: radius (of. Type double) and color (of type String):and three members
functions: getRadius(), getColor(), and getArea().
Three instances of Circles called c1, c2, and c3 shall then be constructed with their
respective data members, also draw an instance diagrams.
Hint:
In this assignment, we shall keep all the codes in a single source file called CircleAIO.cpp.
Output
> CircleAIO
Radius=1.2 Area=4.5239 Color=blue
Radius=3.4 Area=36.3169 Color=red
Radius=1 Area=3.1416 Color=red
Solution:
#include<iostream>
#include<string>
using namespace std;
class circle
{
private:
double radius;
string color;
public:
void getRadius()
{
cout << "Enter radius= ";
cin >> radius;
}
void getColor()
{
cout << "Enter color= ";
cin >> color;
}
void getArea()
{
double Area;
Area = 3.1416 * (radius*radius);
cout << "Area=" << Area <<"\n"<< endl;
}
};
int main()
{
circle c1, c2, c3;
cout << "CircleAIO" << endl;
c1.getRadius();
Instance Diagram:
Circle Class
Color
Properties of class
Radius
getArea()
Actions
getcolor()
getRadius()