OOPS Assign
OOPS Assign
ASSIGNMENT.NO:1 DATE:17-03-2024
QUESTION:
SOURCE CODE:
#include <iostream>
using namespace std;
class octal;
class binary{
long int n;
public:
void getdata(){
cout<<"Enter Number (10 digits):";
cin>>n;
}
friend void bintooct(binary &b,octal &o);
};
class octal{
long int m;
public:
void display(){
cout<<"Octal Value is "<<m;
}
friend void bintooct(binary &b,octal &o);
};
int pow( int a,int b){
int t=1;
for (int i=0;i<b;i++){
t*=a;
}
return t;
}
void bintooct(binary &b,octal &o){
int t1,t2,t3=0,nz=0,flag=0;
while(b.n){
t1=b.n%1000;
int i=0,t4=0;
if(!(t1 || flag))nz+=1;
ASSIGNMENT.NO:1 DATE:17-03-2024
QUESTION:
2 Create an 'Employee' class having the following functions and print the
final salary.
1 - 'getInfo()' which takes the salary, number of hours of work per day of
employee as parameters
2- 'AddSal()' which adds $10 to the salary of the employee if it is less
than $500.
3 - 'AddWork()' which adds $5 to the salary of the employee if the
number of hours of work per day is more than 6 hours.
SOURCE CODE:
#include <iostream>
using namespace std;
class employee{
int salary;
int nhwpd;
public:
void getInfo(int tsal,int tnhwpd){
salary=tsal;
nhwpd=tnhwpd;
}
void AddSal(){
if(salary<500)salary+=10;
}
void AddWork(){
if(nhwpd>6)salary+=5;
}
void display(){
cout<<"salary is "<<salary<<endl;
cout<<"no of hours of work per day is "<<nhwpd;
}
};
int main(){
employee e;
e.getInfo(450,8);
e.AddSal();
e.AddWork();
ASSIGNMENT.NO:1 DATE:17-03-2024
QUESTION:
SOURCE CODE:
#include <iostream>
using namespace std;
class stack{
int stackarray[30];
int stackptr;
public:
stack(){
stackptr=0;
cout<<"Stack Initialised"<<endl;
}
void push(int val){
if (stackptr==30)cout<<"Overflow"<<endl;
else{
stackarray[stackptr]=val;
stackptr++;
}
}
void pop(){
if (!stackptr)cout<<"Underflow"<<endl;
else{
stackptr--;
cout<<stackarray[stackptr];
}
}
~stack(){
cout<<"Stack Destroyed";}
};
int main(){
stack s;
s.pop();
s.push(5);
return 0;}
ASSIGNMENT.NO:1 DATE:17-03-2024
QUESTION:
4. Create a class called Triangle that has private member variables for the
lengths of its three sides. Use all the types of Constructor to initialize the values
and Implement member functions to determine if the triangle is equilateral,
isosceles, or scalene.
SOURCE CODE:
#include <iostream>
using namespace std;
class triangle{
int s1,s2,s3;
public:
triangle(){
s1=0;
s2=0;
s3=0;
}
triangle(int ts1,int ts2,int ts3=0){
s1=ts1;
s2=ts2;
s3=ts3;}
triangle(triangle &t){
s1=t.s1;
s2=t.s2;
s3=t.s3;}
void checknature(){
if(s1==0 && s2==0 && s3==0)cout<<"TRIANGLE DOESN'T EXIST"<<endl;
else if(s1==s2 && s2==s3)cout<<"EQUILATERAL TRIANGLE"<<endl;
else if(s1!=s2 && s2!=s3)cout<<"SCALENE TRIANGLE"<<endl;
else cout<<"ISOSCELES TRIANGLE"<<endl;
}
};
int main(){
triangle t1;
triangle t2(1,2,3);
triangle t3=t2;
triangle t4(6,6,6);