Professional Documents
Culture Documents
Answer:
• Encapsulation: Objects created in OOPs are able to hide certain parts of code from programmer.
This prevents unintentional modification in the code which may cause unwanted outcomes.
• Code Reuse: Objects created in OOPs can easily be reused in other programs.
• Design Benefits: OOPs needs extensive design planning which certainly provide design benefits
over traditional style
Answer
Classes (or rather their instances) are for representing things. Classes are used to define the operations
supported by a particular class of objects (its instances). If your application needs to keep track of
people, then Person is probably a class; the instances of this class represent particular people you are
tracking.
Functions are for calculating things. They receive inputs and produce an output and/or have effects
Functions are easy to understand even for someone without any programming experience, but with a
fair math background. On the other hand, classes seem to be more difficult to grasp.
Answer:
Answer:
The basic syntax of defining a an object oriented Class :
class className{
// variables
// constructors
// functions
}
Q5: Using Object oriented programming, write a program to calculate perimeter, area and
volume of a rectangle?
Answer:
#include "pch.h"
#include <iostream>
class rectangle
{
int length;
int breadth;
int height;
public:
int getarea(int l, int b)
{
int area;
area = l * b;
cout << "Area = " << area << "\n";
return area;
}
};
int main()
{
int l, b, h;
rectangle r;
cout << "Enter length of rectangle ";
cin >> l;
cout << "Enter breadth of rectangle ";
cin >> b;
cout << "Enter height of rectangle ";
cin >> h;
r.getarea(l, b);
r.getperimeter(l, b);
r.getvolume(l, b, h);
system("pause");
return 0;
}