Object Oriented Programming: Assignment # 01

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Total Marks: 04

Obtained Marks:

Object Oriented
Programming
Assignment # 01
Last date of Submission: 20 February 2019

Submitted to: Mr. Muhammad Usman


_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Student Name:
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Reg. Number: ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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();

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT


c1.getColor();
c1.getArea();
c2.getRadius();
c2.getColor();
c2.getArea();
c3.getRadius();
c3.getColor();
c3.getArea();
system("pause");
return 0;
}

Instance Diagram:

Circle Class
Color
Properties of class
Radius
getArea()
Actions
getcolor()
getRadius()

Objects of class Properties of objects Behavior of objects


Circle
Radius Color Area

C1 1.2 Blue 4.5239


C2 3.4 Red 36.3169
C3 1 Green 3.1416

Object Oriented Programming BS(SE)-2 SZABIST-ISB

You might also like