Sum of Two Numbers

You might also like

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

sum of two numbers

#include<iostream.h>
#include<conio.h>
class sample
{
int x,y,sum;
public:
void getdata()
{
cout<<"Enter two numbers\n";
cin>>x>>y;
}
int sumf()
{
sum=x+y;
return(sum);
}
void putdata()
{
cout<<"Sum is : "<<sumf();
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.putdata();
getch();
}

pattern (*)
#include<iostream.h>
#include<conio.h>
class pattern
{
int n,i,j;
public:
void getdata()
{
cout<<"Enter no. of rows\n";
cin>>n;
}
void pat()
{
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
cout<<"* ";
}
cout<<endl;
}
}
};
void main()
{
pattern x;
clrscr();
x.getdata();
x.pat();
getch();
}

swap two numbers


#include<iostream.h>
#include<conio.h>
class sample
{
int x,y,temp;
public:
void getdata()
{
cout<<"Enter two numbers\n";
cin>>x>>y;
cout<<"Numbers before swapping\n";
cout<<x<<" "<<y;
}
void swap()
{
temp=x;
x=y;
y=temp;
}
void putdata()
{
cout<<"\nNumbers after swapping\n";
cout<<x<<" "<<y;
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.swap();
x.putdata();
getch();
}

greatest of three numbers


#include<iostream.h>
#include<conio.h>
class sample
{
int x,y,z,l;
public:
void getdata()
{
cout<<"Enter three numbers\n";
cin>>x>>y>>z;
}
int great()
{
l=(x>y)?((x>z)?x:z):((y>z)?y:z);
return(l);
}
void putdata()
{
cout<<"Largerst of three numbers is : "<<great();
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.putdata();
getch();
}

greatest of N number
#include<iostream.h>
#include<conio.h>
class sample
{
int a[50],n,i,temp;
public:
void getdata()
{
cout<<"Enter no.of elements\n";
cin>>n;
cout<<"Enter numbers\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
int large()
{
temp=a[0];
for(i=1;i<n;i++)
{
if(temp<a[i])
{
temp=a[i];
}
}
return(temp);
}
void putdata()
{
cout<<"Greatest number is " <<large();
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.putdata();
getch();
}

simple interest

#include<iostream.h>
#include<conio.h>
class sample
{
float p,r,t,si,a;
public:
void getdata()
{
cout<<"Enter principle : ";
cin>>p;
cout<<"\nEnter Rate of interest : ";
cin>>r;
cout<<"\nEnter Time : ";
cin>>t;
}
void simple()
{
si=p*r*t/100;
a=si+p;
}
void putdata()
{
cout<<"\nSimple interest is : "<<si;
cout<<"\nAmount is : "<<a;
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.simple();
x.putdata();
getch();
}

Area and circumference of circle


#include<iostream.h>
#include<conio.h>
float const pi=3.14;
class circle
{
float a,c,r;
public:
void getdata()
{
cout<<"Enter radius : ";
cin>>r;
}
float circum()
{
c=2*pi*r;
return(c);
}
float area()
{
a=pi*r*r;
return(a);
}
void putdata()
{
cout<<"\nCircumference is : "<<circum();
cout<<"\nArea is : "<<area();
}
};
void main()
{
circle x;
clrscr();
x.getdata();
x.putdata();
getch();
}

Size of Differeny data types

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Size of Diffrent data types are :-\n";
cout<<"Int = "<<sizeof(int);
cout<<"\nFloat = "<<sizeof(float);
cout<<"\nChar = "<<sizeof(char);
cout<<"\nDouble = "<<sizeof(double);
getch();
}

Gross salary
#include<iostream.h>
#include<conio.h>
class sample
{
float basic;
float hra,da,gs;
public:
void getdata()
{
cout<<"Enter Basic salary : ";
cin>>basic;
}
void calc()
{
hra=basic*15/100;
da=basic*60/100;
gs=basic+hra+da;
}
void putdata()
{
cout<<"HRA is "<<hra<<endl;
cout<<"DA is "<<da<<endl;
cout<<"Gross salary is "<<gs;
}
};
void main()
{
sample x;
clrscr();
x.getdata();
x.calc();
x.putdata();
getch();
}

define member of class using scope


resolution operator
#include<iostream.h>
#include<conio.h>
class sample
{
int rno,age;
char name[50];
public:
void getdata();
void putdata();
};
void sample::getdata()
{
cout<<"Enter details of students\n";
cout<<"Name : ";
cin>>name;
cout<<"Roll no : ";
cin>>rno;
cout<<"Age : ";
cin>>age;
}
void sample::putdata()
{
cout<<"\nDetails of students\n";
cout<<"\nRoll no : "<<rno;
cout<<"\nName : "<<name;
cout<<"\nAge : "<<age;
}
void main()
{
sample x;
clrscr();
x.getdata();
x.putdata();
getch();
}

Array of object (Account information)


#include<iostream.h>
#include<conio.h>
class account
{
int acc;
char name[20];
double bal;
public:
void getdata();
void putdata();
};
void account::getdata()
{
cout<<"Enter account no. , name and balance"<<endl;
cin>>acc>>name>>bal;
}
void account::putdata()
{
cout<<"Account no. = "<<acc<<endl;
cout<<"Name = "<<name<<endl;
cout<<"Balance = "<<bal<<endl;
}
void main()
{
account x[10];
int n;
clrscr();
cout<<"Enter how many account holders"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
x[i].getdata();
}
for(i=0;i<n;i++)
{
x[i].putdata();
}
getch();
}

Array of object (Students marks)


#include<iostream.h>
#include<conio.h>
class student
{
char name[20];
int roll;
public:
int marks;
void getdata();
void putdata();
};
void student::getdata()
{
cout<<"Enter Roll no.,Name and Marks";
cin>>roll>>name>>marks;
}
const int size=3;
void main()
{
student s[size];
int sum=0;
float mean;
clrscr();
for(int i=0;i<3;i++)
{
cout<<"Details of student"<<i+1;
s[i].getdata();
sum=sum+s[i].marks;
}
mean=sum/size;
cout<<"Average is "<<mean;
getch();
}

Fuctions of various bitwise operators


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"enter values of a and b"<<endl;
cin>>a>>b;
cout<<"bitwise and:"<<(a&b)<<endl;
cout<<"bitwise or:"<<(a+b)<<endl;
cout<<"bitwise not:"<<(~a)<<endl;
cout<<"bitwise exponent:"<<(a^b)<<endl;
cout<<"shift right:"<<(a>>4)<<endl;
cout<<"shift left:"<<(a<<3)<<endl;
getch();
}

You might also like