1.time programe
#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<dos.h>
void main()
{
char t[9];
clrscr();
while(!kbhit())
{
_strtime(t);
gotoxy(20,20);
cout<<t;
delay(100);
}
}
2.command line programe
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int fact(int n);
void main(int n,char *c[])
{
int ans;
clrscr();
n=atoi(c[1]);
ans=fact(n);
cout<<"\n factorial="<<ans;
getch();
}
int fact(int n)
{
int fact=1,i;
for(i=n;i>=1;i--)
{
fact=fact*i;
}
return(fact);
}
3.circum ference programe
#include<iostream.h>
#include<conio.h>
inline float area(int r)
{
return(3.142*r*r);
}
inline float circumference(int r)
{
return(2*3.142*r);
}
void main()
{
int r;
clrscr();
cout<<"\n Enter the radius of circle";
cin>>r;
cout<<"\n Area of a circle="<<area(r);
cout<<"\n Circumference="<<circumference(r);
getch();
}
4.shopping list programe
#include<iostream.h>
#include<conio.h>
int total=0;
class shopping
{
private:char pname[10];
int price,qty,amt;
public:void accept()
{
cout<<"\n enter the pname\n price\n qty\n";
cin>>pname>>price>>qty;
amt=price*qty;
total=total+amt;
}
void display()
{
cout<<"product name="<<pname<<endl;
cout<<"price="<<price<<endl;
cout<<"amount="<<amt<<endl;
cout<<"quantity="<<qty<<endl;
}
};
void main()
{
shopping s[10];
int i,n;
clrscr();
cout<<"\n Enter the number of product:";
cin>>n;
cout<<"\n Enter product details:";
for(i=0;i<n;i++)
s[i].accept();
cout<<"\n pname price qty amt:";
cout<<"\n***************************************************\n";
for(i=0;i<n;i++)
s[i].display();
cout<<"\n totalbill="<<total;
getch();
}
5.max of 2 num friend fun programe
#include<iostream.h>
#include<conio.h>
class xyz
{
private:int a,b;
public:void input()
{
cout<<"\n Enter two numbers:";
cin>>a>>b;
}
friend void large(xyz obj);
};
void large(xyz obj)
{
if(obj.a>obj.b)
cout<<"\n largest="<<obj.a;
else
cout<<"\n largest="<<obj.b;
}
void main()
{
xyz obj;
obj.input();
large(obj);
getch();
}
6.swapping of 2 num programe
#include<iostream.h>
#include<conio.h>
class swap
{
private:int a,b;
public:swap()
{
a=0;
b=0;
}
swap(swap &obj)
{
int temp;
temp=obj.a;
obj.a=obj.b;
obj.b=temp;
}
void accept()
{
cout<<"\n Enter two numbers:";
cin>>a>>b;
}
void display()
{
cout<<"a="<<a;
cout<<"b="<<b;
}
};
void main()
{
swap obj1;
clrscr();
obj1.accept();
cout<<"\n Before Swapping\n";
obj1.display();
swap obj2(obj1);
cout<<"\n After Swapping\n";
obj1.display();
getch();
}
7.saving and current bank programe
#include<iostream.h>
#include<conio.h>
class current;
class saving
{
private:int accno;
float balance;
public:void input()
{
cout<<"\n Enter accno and balance:";
cin>>accno>>balance;
}
friend void sum(saving s,current c);
};
class current
{
private:int accno;
float balance;
public:void input()
{
cout<<"\n Enter accno and balance:";
cin>>accno>>balance;
}
friend void sum(saving s,current c);
};
void sum(saving s,current c)
{
int total=s.balance+c.balance;
cout<<"total="<<total;
}
void main()
{
saving s;
current c;
clrscr();
s.input();
c.input();
sum(s,c);
getch();
}
8. real and imaginary sum (complex) programe
#include<iostream.h>
#include<conio.h>
#include<math.h>
class complex
{
private:int real,img;
public:void accept()
{
cout<<"\n enter real and img value";
cin>>real>>img;
}
void display()
{
if(img<0)
cout<<real<<"-i"<<abs(img);
else
cout<<real<<"+i"<<img;
}
friend void sum(complex c1,complex c2);
};
void sum(complex c1,complex c2)
{
int r,i;
r=c1.real+c2.real;
i=c1.img+c2.img;
if(i<0)
cout<<r<<"-i"<<abs(i);
else
cout<<r<<"+i"<<i;
}
void main()
{
complex c1, c2;
clrscr();
cout<<"\n enter first complex number:";
c1.accept();
c2.accept();
cout<<"\n first complex number=";
c1.display();
cout<<"\n second complex number=";
c2.display();
cout<<"\n sum of two complex numbers";
sum(c1,c2);
getch();
}
9. comparing 2 strings(==) programe
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
private:char str[20];
public:void accept()
{
cin>>str;
}
friend int operator ==(string s1, string s2);
};
int operator ==(string s1,string s2)
{
int n=strcmp(s1.str,s2.str);
return(n);
}
void main()
{
string s1,s2;
clrscr();
cout<<"\n Enter first string:";
s1.accept();
cout<<"\n Enter second string:";
s2.accept();
int ans=(s1==s2);
if(ans==0)
cout<<"\n Two strings are equal:";
else
cout<<"\n Two strings are not equal:";
getch();
}
10. concatinating programe
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
private:char str[20];
public:void accept()
{
cin>>str;
}
void display()
{
cout<<str;
}
friend string operator +(string s1,string s2);
};
string operator +(string s1,string s2)
{
string s;
strcpy(s.str,s1.str);
strcat(s.str,s2.str);
return(s);
}
void main()
{
string s1,s2,s3;
clrscr();
cout<<"\n Enter first string:";
s1.accept();
cout<<"\n Enter second string:";
s2.accept();
s3=s1+s2;
cout<<"\n Concatination of two strings:";
s3.display();
getch();
}
11.geometrical figures(area of square,circle) programe
#include<iostream.h>
#include<conio.h>
class area
{
public:virtual void areacs()=0;
}
class circle:public area
{
public:void areacs()
{
int r;
cout<<"\n Enter the radius of the circle:";
cin>>r;
cout<<"Area of a circle="<<(3.142*r*r);
}
};
class square:public area
{
public:void areacs()
{
int s;
cout<<"\n Enter the number of sides";
cin>>s;
cout<<"area of a square="<<(s*s);
}
};
void main()
{
circle c;
square s;
clrscr();
c.areacs();
s.areacs();
getch();
}
12.addition of matrix
#include<iostream.h>
#include<conio.h>
class matrix
{
public: int i,j,r,c,m[10][10];
matrix()
{
r=2;
c=2;
}
void getmatrix();
void putmatrix();
matrix operator+(matrix);
};
void matrix::getmatrix()
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>m[i][j];
}
}
}
void matrix::putmatrix()
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<m[i][j]<<" ";
}
cout<<endl;
}
}
matrix matrix :: operator +(matrix B)
{
matrix temp;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
temp.m[i][j]=m[i][j]+B.m[i][j];
}
}
return temp;
}
void main()
{
matrix A, B,G;
clrscr();
cout<<"Enter matrix A elments\n";
A.getmatrix();
cout<<"Enter matrix B elments\n";
B.getmatrix();
cout<<"Matrix A is\n";
A.putmatrix();
cout<<"Matrix B is\n";
B.putmatrix();
G=A+B;
cout<<"Addition of two matrix is\n";
G.putmatrix();
getch();
}
13. multiplication matrix programe
#include<iostream.h>
#include<conio.h>
class matrix
{
public: int i,j,r,c,m[10][10];
matrix()
{
r=2;
c=2;
}
void getmatrix();
void putmatrix();
matrix operator*(matrix);
};
void matrix::getmatrix()
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>m[i][j];
}
}
}
void matrix::putmatrix()
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<m[i][j]<<" ";
}
cout<<endl;
}
}
matrix matrix :: operator *(matrix B)
{
matrix temp;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
//temp.m[i][j]=0;
{
temp.m[i][j]=0;
for(int k=0;k<r;k++)
{
temp.m[i][j]=temp.m[i][j]+(m[i][k]*B.m[k][j]);
}
}
}
return temp;
}
void main()
{
matrix A, B,G;
clrscr();
cout<<"Enter matrix A elments\n";
A.getmatrix();
cout<<"Enter matrix B elments\n";
B.getmatrix();
cout<<"Matrix A is\n";
A.putmatrix();
cout<<"Matrix B is\n";
B.putmatrix();
cout<<"Product of two matrix is\n";
G=A*B;
G.putmatrix();
getch();
}
14.inheritance programe
#include<iostream.h>
#include<conio.h>
class A
{
private:int regno;
char name[20];
public:void inputA()
{
cout<<"\n Enter regno and name:";
cin>>regno>>name;
}
void displayA()
{
cout<<"\n regno="<<regno;
cout<<"\n name="<<name;
}
};
class B:public A
{
private:int sem;
char course[10];
public:void inputB()
{
cout<<"\n Enter sem and course:";
cin>>sem>>course;
}
void displayB()
{
cout<<"\n sem="<<sem;
cout<<"\n course="<<course;
}
};
class C:public B
{
private:int m1,m2,m3;
public:void inputC()
{
cout<<"\n Enter marks of 3 subjects:";
cin>>m1>>m2>>m3;
}
void displayC()
{
int total=m1+m2+m3;
cout<<"\n marks1="<<m1;
cout<<"\n marks2="<<m2;
cout<<"\n marks3="<<m3;
cout<<"\n total marks="<<m1+m2+m3;
}
};
void main()
{
C obj;
clrscr();
obj.inputA();
obj.inputB();
obj.inputC();
obj.displayA();
obj.displayB();
obj.displayC();
getch();
}
15.template programe
#include<iostream.h>
#include<conio.h>
template <class T>
T large(T a,T b)
{
if(a>b)
return(a);
else
return(b);
}
void main()
{
int a,b;
float m,n;
clrscr();
cout<<"\n enter integer a and b value:";
cin>>a>>b;
cout<<"\n enter two float value m and n:";
cin>>m>>n;
cout<<"large="<<large(a,b);
cout<<"large="<<large(m,n);
getch();
}
16.file operation programme
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class student
{
private:int regno,m1,m2,m3;
char name[10];
public:void accept()
{
cout<<"\n enter the regno,name and three sub marks:";
cin>>regno>>name>>m1>>m2>>m3;
}
void display()
{
cout<<regno<<"\n "<<name<<"\n "<<m1<<"\n "<<m2<<"\n "<<m3<<"\n";
}
};
void main()
{
student s;
clrscr();
ofstream ofs("abc1.txt");
char ch='y';
while(ch=='y')
{
s.accept();
ofs.write((char*)& s,sizeof(s));
cout<<"\n do you want to insert another field(y/n):";
cin>>ch;
}
ofs.close();
{
ifstream ifs("abc1.txt");
cout<<"\n regno name m1 m2 m3";
while(ifs)
{
ifs.read((char*)& s,sizeof(s));
s.display();
}
ifs.close();
getch();
}
}