0% found this document useful (0 votes)
6 views

My Oop

Uploaded by

nimranadeem244
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

My Oop

Uploaded by

nimranadeem244
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Submitted to: Sir Nazim Hussain

Submitted by: Nimra Shahzadi


Roll no. 05
Section: A
Assignment no. 01
Subject: Object Oriented Programming
Department: BS-SWE
Q: Hexagon is a geometrical shape having six sides while square is a
shape which has four equal sides. You are required to write C++ classes
for hexagon and square having data members and member functions,
and create a repeating menu keeping in mind the following
requirements:
1.Add all numbers of your mobile number. Divide by 10 and take the
remainder. Consider the remainder as the length of one side of hexagon.
For example, if your Mobile Number is 03136275387, the sum is 45 and
remainder after dividing by 10 will be 5.
2.Calculate area and perimeter of hexagon.
(Hint: Area of hexagon= 1.5*1.732*s2; where ‘s’ is the length of one
side of hexagon.
Perimeter of hexagon= 6*s; where ‘s’ is the length of one side of
hexagon)
3.Calculate sum of all the angles of hexagon.
(Hint: Sum of all the angles of hexagon= 6*a; where ‘a’ is the
measurement of one angle of hexagon which is equal to 120.)
4.When the input of user is ‘1’, display area, perimeter and sum of all
the angles of hexagon.
5.Calculate area and perimeter of square whereas;
Length of one side of square = remainder + 1.
Note: how to get value of remainder is explained in the start
(Hint: Area of square= (length)2; where ‘length’ is the length of one side
of square.
Perimeter of square= 4*length; where ‘length’ is the length of one side
of square.)
6.When the input of user is ‘2’, display area and perimeter of square.
7.On any other input, program should exit.
#include<iostream>
#include<cmath>
using namespace std;
class hexagon
{
int side;
public:
hexagon(int s)
{
side=s;
}
double area(){
return 1.5*1.732*side*side;
}
int perimeter(){
return 6*side;
}
int sumAngles(){
return 6*120;
}
};
class square
{
int side;
public:
square(int s){
side=s;
}
int area(){
return side*side;
}
int perimeter(){
return 4*side;
}
};
int main(){
int mobNum=3440208053;
int sum=0;
while(mobNum!=0){
sum+=mobNum%10;
mobNum/=10;
}
int r=sum%10;
hexagon hexagon(r);
square square(r+1);
int choice;
while(true){
cout<<"enter 1 for hexagon, 2 for square, any other key to exit= ";
cin>>choice;
if(choice==1){
cout<<"hexagon area= "<<hexagon.area()<<endl;
cout<<"hexagon perimeter= "<<hexagon.perimeter()<<endl;
cout<<"hexagon angles= "<<hexagon.sumAngles()<<endl;
}else if(choice==2){
cout<<"square area= "<<square.area()<<endl;
cout<<"square perimeter= "<<square.perimeter()<<endl;
}else{
break;
}
}
return 0;
}

THE END

You might also like