Showing posts with label CPP. Show all posts
Showing posts with label CPP. Show all posts

Sunday, 7 December 2014

#include<iostream.h>
#include<conio.h>
class area
{       private:
  int a,r,l,b,a1;
 public:
  void getdata();
  void sqr();
  void crl();
  void rec();
};
void area::getdata()
{
 cout<<"\nenter a,b,l,r:";
 cin>>a>>b>>l>>r;
}
void area::sqr()
{
 //int a,a1;
 //cout<<"\nenter a:";
 //cin>>a;
 a1=a*a;
 cout<<"\narea of squre:"<<a1;
}
void area::crl()
{
 //int r,a1;
       // cout<<"\nenter r:";
 //cin>>r;
 a1=3.14*r*r;
 cout<<"\narea of circle is:"<<a1;
}
void area::rec()
{
 //int l,b,a1;
 //cout<<"\nenter l,b:";
 //cin>>l>>b;
 a1=l*b;
 cout<<"\narea of rectangle is:"<<a1;
}
void main()
{
 clrscr();
 area x;
 x.getdata();
 x.sqr();
 x.crl();
 x.rec();
 getch();
}

Read More

C++ program to print salary details of an employee

#include<iostream.h>
#include<conio.h>
class emp
{
 private:
  int sno,gross,ta,da,pf,dec,hra,b_sal,n_sal;

  char name[20];
 public:
  void getdata();
  void putdata();
};
void emp::getdata()
{
 cout<<"\nenter sno,name,b_sal:\n";
 cin>>sno>>name>>b_sal;
}
void emp::putdata()
{
 ta=0.008*b_sal;
 da=0.001*b_sal;
 hra=0.004*b_sal;
 pf=0.02*b_sal;
 dec=0.02*b_sal;
 gross=b_sal+ta+da+hra+pf;
 n_sal=gross+dec;
 cout<<sno;
 cout.width(10);
 cout<<name;
 cout.width(10);
 cout<<hra;
 cout.width(10);
 cout<<da;
 cout.width(10);
 cout<<gross;
 cout.width(10);
 cout<<dec;
 cout.width(10);
 cout<<n_sal;
}
void main()
{
 clrscr();
 emp s[5];
 int i,n;
 cout<<"\nenter no of employees:";
 cin>>n;
 for(i=1;i<n;i++)
 {
  s[i].getdata();
 }
 cout<<"\n******************************************************************\n";
 cout<<"sno";
 cout.width(10);
 cout<<"name";
 cout.width(10);
 cout<<"hra";
 cout.width(10);
 cout<<"da";
 cout.width(10);
 cout<<"gross";
 cout.width(10);
 cout<<"dec";
 cout.width(10);
 cout<<"n_sal";
 cout<<"\n******************************************************************\n";
 for(i=1;i<n;i++)
 {
  s[i].putdata();
  cout<<"\n";
 }
 cout<<"\n******************************************************************\n";
 getch();
}

Read More
#include<iostream.h>
#include<conio.h>
void main()
{
 int n,k=0,l=0;
 clrscr();
 cout<<"\nenter n:";
 cin>>n;
 cout<<"\neven nums are:";
 for(int i=0;i<=n;i++)
  if(i%2==0)
  {
   cout<<"\t"<<i;
   k++;
  }
  cout<<"\nnum of evens:"<<k;
 cout<<"\nodd nums are:";
 for(i=0;i<=n;i++)
  if(i%2!=0)
  {
   cout<<"\t"<<i;
   l++;
  }
  cout<<"\n no of odds are:"<<l;
  getch();
}

Read More
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class mat
{
 int a[3][3],b[3][3],c[3][3],i,j,k;
 public:
  void add();
  void mul();
};
void mat::add()
{
 cout<<"\nenter elements of a";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cin>>a[i][j];
  }
 }
 cout<<"\nenter elements of b";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cin>>b[i][j];
  }
 }
 cout<<"\naddition of a,bis:\n";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   c[i][j]=a[i][j]+b[i][j];
  }
 }
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cout<<"\t"<<c[i][j];
  }
  cout<<"\n";
 }
}
 void mat::mul()
 {
   cout<<"\nenter elements of a";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cin>>a[i][j];
  }
 }
 cout<<"\nenter elements of b";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cin>>b[i][j];
  }
 }
 cout<<"c=";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   c[i][j]=0;
   for(k=0;k<3;k++)
   {
    c[i][j]=c[i][j]+a[i][k]*b[k][j];
   }
  }
 }
 cout<<"\nresultant matrix is:\n";
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   cout<<"\t"<<c[i][j];
  }
  cout<<"\n";
 }
 }

 void main()
 {
 clrscr();
 mat m;
 m.add();
 m.mul();
 getch();
 }

Read More

C++ program for bubble sort

#include<iostream.h>
#include<conio.h>
class bub
{
 private:
  int a[20],i,j,t,n;
 public:
  void getdata();
  void putdata();
};
void bub::getdata()
{

 cout<<"\nenter the size of an array:";
 cin>>n;
 cout<<"\nenter the array elements:";
 for(i=0;i<n;i++)
 cin>>a[i];
}
void bub::putdata()
{
       // cout<<"\nenter the array elements:";
 for(i=0;i<n;i++)
 {
  for(j=0;j<n;j++)
  {
   if(a[i]<a[j])
   {
    t=a[i];
    a[i]=a[j];
    a[j]=t;
   }
  }
 }
 cout<<"\nthe resultant bubble sort is:";
 for(i=0;i<n;i++)
 cout<<"\t"<<a[i];
}
void main()
{
 clrscr();
 bub b;
 b.getdata();
 b.putdata();
 getch();
}

Read More
#include<iostream.h>
#include<conio.h>
void main()
{
 int a[100],p,s,i,n;
 clrscr();
 cout<<"\nenter size of an array:";
 cin>>n;
 s=a[0];
 p=0;
 cout<<"\nenter the arrray:";
 for(i=1;i<n;i++)
 cin>>a[i];

 for(i=1;i<n;i++)
 {
  if(a[i]>s)
  {
   s=a[i];
   p=i;
  }
 }
 cout<<"big="<<s;
 cout<<"position"<<p;
 getch();
}

Read More
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
 int i,ac,uc,sc;
 char a[100];
 clrscr();

 cout<<"\nenter string:";
 cin>>a;

      // ac=dc=sc=0;
 for(i=0;a[i]!='\0';i++)
 {
  if(a[i]>=65&&a[i]<=90)
  {
   a[i]+=32;
  }
 }
 cout<<"string is:"<<a;
 getch();
      }

Read More

C++ program to print sum of first n numbers

#include<constream.h>
void main()
{
 int sum();
 int x;
 clrscr();
 x=sum();
 cout<<"sum="<<x;
 getch();
}
int sum()
{
 int s=0,n,i;
 cout<<"\nenter n:";
 cin>>n;
 for(i=0;i<=n;i++)
 s+=i;
 return s;
}

Read More

C++ program to get factorial of a given number

#include<constream.h>
long int fact();
void main()
{
 clrscr();
 long int y;
 y=fact();
 cout<<"fact of n:"<<y;
 getch();
}
long int fact()
{
       long int fact=1,n,i;
 cout<<"\nenter n:";
 cin>>n;
 for(i=1;i<=n;i++)
 {
  fact=fact*i;
 }
 return fact;
}

Read More
#include<constream.h>
int arm(int);
void main()
{
 clrscr();
 int n,n1,x;
 cout<<"\n enter n:";
 cin>>n;
 n1=n;
 x=arm(n);
 if(x==n1)
 cout<<"armstrong";
 else
 cout<<"not";
 getch();
}
int arm(int n)
{
 int s=0,r;
 while(n>0)
 {
  r=n%10;
  s=s+r*r*r;
  n=n/10;
 }
 return s;
}

Read More

C++ program for bubble sort

#include<ionstream.h>
class bubl
{
 private:
  int n,a[100],t,i,j;
 public:
  void getdata();
  void putdata();
};
void bubl::getdata()
{
 cout<<"\nenter size of array:";
 cin>>n;
 cout<<"\nenter elememnts:";
 for(i=0;i<=n;i++)
 {
  cin>>a[i];
 }
}
void bubl::putdata()
{
 for(i=0;i<=n;i++)
 {
  for(j=0;j<=n;j++)
  {
   if(a[i]<a[j])
   {
    t=a[i];
    a[i]=a[j];
    a[j]=t;
   }
  }
 }
 cout<<"\nthe result bubble sort is:";
 for(i=0;i<=n;i++)
 cout<<"\t"<<a[i];
}
void main()
{
 clrscr();
 bubl b;
 b.getdata();
 b.putdata();
 getch();
}

Read More

C++ program to print details of student marks list

#include<constream.h>
int x=0,a[10];//global variables//
class stdn
{
 private:
  int sno,m1,m2,m3,total,avg,rank;
  char sname[10],grade;
 public:
  void get();
  void put();

};
 void stdn::get()
 {
  x++;
  cout<<"\nenter sno,sname,m1,m2,m3:";
  cin>>sno>>sname>>m1>>m2>>m3;

  total=m1+m2+m3;
  avg=total/3;
  a[x]=total;

 }
 void stdn::put()
 {
  if(m1>=35&&m2>=35&&m3>=35)
  {
   if(avg>=65)
   grade='A';
   else if(avg<65&&avg>=50)
   grade='B';
   else if(avg<50&&avg>=35)
   grade='C';
   for(int i=1;i<=x;i++)
   if(total==a[i])
   {
    rank=i;
    break;
   }

  }
  else
  {
   grade='F';
   rank=0;
  }
  cout<<sno<<"\t"<<sname<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<total<<"\t"<<avg<<"\t"<<grade<<"\t"<<rank;
 }
 void main()
 {
  clrscr();
  stdn s[10];
  int n,i,j;
  cout<<"\nenter n:";
  cin>>n;
  for(i=0;i<n;i++)
  {
   s[i].get();
  }
  for(i=1;i<=x;i++)
  for(j=1;j<=x;j++)
  {
   if(a[i]>a[j])
   {
    int t=a[i];a[i]=a[j];a[j]=t;
   }
  }

  cout<<"                      STUDENT MARKSLIST\n";
  cout<<"\n....................................................................\n";
  cout<<"sno\tsname\tm1\tm2\tm3\ttotal\tavg\tgrade\trank";
  cout<<"\n....................................................................\n";
  for(i=0;i<n;i++)
  {
   s[i].put();
   cout<<"\n";
  }
  cout<<"\n.....................................................................\n";
  cout<<"\n'F'represents Fail and '0'represents no rank issued";
  getch();
 }

Read More

C++ program to print a name or sting

#include<iostream.h>
#include<conio.h>
void main()
{
char name[15];
clrscr();
cout<<"enter your name:\t";
cin>>name;
cout<<"your nameis\t"<<name;
//return 0;
getch();
}

Read More
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
	clrscr();
	void funA(int s);
	void funB(int &);
	void funC(int *);

	int s=4;
	funA(s);
	cout<<"s="<<s;
	funB(s);
	cout<<"s="<<s;
	funC(&s);
	cout<<"s="<<s;
	getch();
}
void funA(int i)
{
i++;
}
void funB(int &k)
{
k++;
}
void funC(int *j)
{
++*j;
}

Read More

C++ program to print addition og two matrices

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
	int a[3][3],b[3][3],c[3][3],i,j;
	clrscr();
	cout<<"\nenter elements of A matrix:";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		cin>>a[i][j];
	}
	cout<<"B elents:";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		cin>>b[i][j];
	}
	cout<<"\nA=";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		cout<<a[i][j]<<"\t";
	cout<<"\n";


	}

	cout<<"\nB=";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		cout<<b[i][j]<<"\t";
		cout<<"\n";
	}
	cout<<"C=A+B=\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		c[i][j]=a[i][j]+b[i][j];
	}
      //	cout<<"c=";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		cout<<c[i][j]<<"\t";
		cout<<"\n";
	}
	getch();
}

Read More
#include<iostream.h>
#include<conio.h>
class employee
{
	private:
		int sno,basic_salary,da,hra,it,lic,deductions,n_salary;
		char name[25];
	public:
		void get_details();
		void put_data();

};
void employee::get_details()
{
	cout<<"enter sno";
	cout<<"Enter name and net salary of employee";
	cin>>sno>>name>>n_salary;
}


void employee::put_data()
{
	da=0.8*n_salary;
	hra=0.6*n_salary;
	it=0.2*n_salary;
	deductions=da+hra+it;
	basic_salary=n_salary+deductions;

	cout<<sno;
	cout<<"\t"<<name;
	cout<<"\t"<<n_salary<<"\t"<<deductions<<"\t"<<basic_salary<<"\n";
}
void main()
{
	clrscr();
	employee e[5];
	int n;
	cout<<"enter n";
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		e[i].get_details();

	}
	clrscr();
	cout<<"Sno\tname\tnetsalary\tdeductions\tbasic\n";
	for(i=1;i<=n;i++)
	{
		e[i].put_data();
		cout<<endl;
	}
	getch();
}

Read More

C++ program to print two integers on console

#include<iostream.h>
#include<conio.h>
void main()
{
int num,num1 ;
clrscr();
cout<<"enter two numbers";
cin>>num>>num1;
cout<<"entered numbers are";
cout<<num<<"\t"<<num1;
getch();
}

Read More
#include<iostream.h>
#include<constream.h>
#include<string.h>
void main()
     {
       clrscr();
       int age;
       cout<<"enter your age:";
       cin>>age;
       if(age>=18)
       {
       cout<<"you are eligible for voting:";
       }
       else
       {
       cout<<"you are noneligible for voting:";
       cout<<"wait for"<<18-age<<"year(s):";
       }
       getch();
       }

Read More
#include<iostream.h>
#include<conio.h>
#define pi 3.14
class vol
{
int a,l,b,h,r,h1;
public:
void getdata()
{
 cout<<"enter a value:";
 cin>>a;
 cout<<"enter l b h values is:";
 cin>>l>>b>>h;
 cout<<"enter r h1 values:";
 cin>>r>>h1;
 }
 void putdata()
 {
 cout<<" the voluem of cube is=:"<<cube(a);
 cout<<" the voluem of rectangle is=:"<<rec(l,b,h);
 cout<<" the voluem of cylinder is=:"<<cylin(r,h1);
 }
 float cube(float x)
 {
 return(x*x*x);
 }
 float cylin(float x,float y)
 {
 return(pi*x*x*y);
 }
 float rec(float x,float y,float z)
 {
 return(x*y*z);
 }
 };
 void main()
 {
 clrscr();
 vol v;
 v.getdata();
 v.putdata();
 getch();
 }

Read More

C++ program for conditional if else statement

#include<iostream.h>
#include<conio.h>
void main()
{
int score;
clrscr();
  cout<<"\n enter sachin's score:";
  cin>>score;
if(score>=50)
{
if(score>=100)
cout<<"\n sachin scored a century and more runs:";
else
{
cout<<"\n sachin scored mare than half cantury:";
cout<<"\n cross your fingers and pray he complets century:";
}
}
else
{
if(score==0)
cout<<"oh my god";
else if(score>0)
cout<<"\n not in form today:";
}
getch();
}

Read More