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

AREA AND PERIMETER OF A TRIANGLE USING

CLASS AND FUNCTION


#include<iostream>
#include<math.h>
using namespace std;
class triangle
{
float p;
float a;
float hyp;
public:
int area(float b, float h)
{
int a;
a = (h*b)/2;
cout<<"\nArea: "<<a;
return a;
}
int perimeter(float b, float h)
{
int p;
hyp=pow(h*h + b*b,0.5);
p=h+b+hyp;
cout<<"\nPerimeter: "<<p;
return p;
}

};
int main()
{
triangle t;
float b, h;
cout<<"Enter base and height of the triangle\n";
cin>>b>>h;
t.area(b,h);
t.perimeter(b,h);
}

ADDITION AND SUBSTRACTION OF COMPLEX


NUMBERS
#include<iostream>
using namespace std;
class complex
{
int real,img;
public:
void setcomplex(void)
{
cout<<"Enter real and imaginary part of number\n";
cin>>real>>img;
}
void addition(complex c1, complex c2)
{
int r1,i1;
r1=c1.real+c2.real;
i1=c1.img+c2.img;
cout<<"\nAddition of two complex numbers: "<<r1<<"+"<<i1<<"i";
}
void substraction(complex c1, complex c2)
{
int r2,i2;
r2=c1.real-c2.real;
i2=c1.img-c2.img;
cout<<"\nSubstraction of complex numbers: "<<r2<<"+"<<i2<<"i";

}
};
int main()
{
complex a, b, c;
a.setcomplex();
b.setcomplex();
c.addition(a,b);
c.substraction(a,b);
return 0;
}

TOTAL SALARY AND TAX TO BE PAID BY


EMPLOYER USING CLASS INCOME
#include<iostream>
using namespace std;
class income{
double basic, da, tax, total;
public:
void read()
{
cout<<"\nEnter annual figures for basic and da\n";
cin>>basic>>da;
}
int calc_deduct()
{
return(0.08*basic);
}
void pay_sal()
{
total=basic+da+0.15*basic-calc_deduct();
cout<<"\nTotal annual salary to be paid= "<<total<<"\n";
}
void d_tax()
{
if(total>100000.0)
tax=0.2*total;
else

tax=0.3*total;
cout<<"Total annual tax= "<<tax;
}
};
int main()
{
income i;
i.read();
i.pay_sal();
i.d_tax();
return 0;
}

OOPS
LAB FILE

NAME-SALONI SINGHAL
ROLL NO.- 2K15/CO/108

You might also like