Sie sind auf Seite 1von 12

6.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class matrix
{
private:
int r,c,a[5][5],b[5][5],i,j;
public:
void enterdata()
{
cout<<"\nEnter the row order:";
cin>>r;
cout<<"\nEnter the column order:";
cin>>c;
}
void getdata()
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
}
void putdata()
{
cout<<"\n RESULT MATRIX";
cout<<"\n ****** ******\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
}
matrix operator +(matrix m2)
{
matrix t;
t.r=m2.r;
t.c=m2.c;
for(int i=0;i<m2.r;i++)
for(int j=0;j<m2.c;j++)
t.a[i][j]=a[i][j]+m2.a[i][j];
return t;

matrix operator -(matrix m2)


{
matrix t;
t.r=m2.r;
t.c=m2.c;
for(int i=0;i<m2.r;i++)
for(int j=0;j<m2.c;j++)
t.a[i][j]=a[i][j]-m2.a[i][j];
return t;
}
matrix operator *(matrix m2)
{
matrix t;
t.r=m2.r;
t.c=m2.c;
for(int i=0;i<m2.r;i++)
for(int j=0;j<m2.c;j++)
t.a[i][j]=a[i][j]*m2.a[i][j];
return t;
}
};
void main()
{
matrix m1,m2,m3,m4,m5;
clrscr();
m1.enterdata();
cout<<"\nEnter The First A Matrix:";
m1.getdata();
m2.enterdata();
cout<<"\nEnter The First B Matrix:";
m2.getdata();
m3=m1+m2;
m3.putdata();
m4=m1-m2;
m4.putdata();
m5=m1*m2;
m5.putdata();
getch();
}
-------------------------------------------------------------------------------------------------------------------------7.
#include<iostream.h>
#include<conio.h>
class complex
{
int x,y;
public:
complex()
{
x=y=0;
}

complex(int a,int b)
{
x=a;
y=b;
}
complex operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return temp;
}
void showdata()
{
cout<<"\n"<<x<<"+i"<<y<<"\n"<<endl;
}
};
void main()
{
complex c3;
int a,b;
clrscr();
cout<<"\n Enter the A and B number:";
cin>>a>>b;
complex c1(a,b);
cout<<"\n Enter the A and B number:";
cin>>a>>b;
complex c2(a,b);
cout<<"\nFirst Number:";
c1.showdata();
cout<<"\nSecond Number:";
c2.showdata();
c3=c1+c2;
cout<<"\nRESULT OF COMPLEX NUMBER";
cout<<"\n------------------------";
c3.showdata();
getch();
}
-----------------------------------------------------------------------------------------------------------------------------8.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class employee
{
private:
char name[10];
int salary;
char grade[2];
int age;
public:
void getdata()
{
int n;

cout<<"\nEnter the no:";


cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"\nEnter The
cin>>name;
cout<<"\nEnter The
cin>>salary;
cout<<"\nEnter The
cin>>grade;
cout<<"\nEnter The
cin>>age;
}

Name:";
Salary:";
Grade:";
Age:";

}
void showdata()
{
cout<<"\nName:"<<name;
cout<<"\nSalary:"<<salary;
cout<<"\nGrade:"<<grade;
cout<<"\nAge:"<<age;
}
};
void main()
{
employee e;
char ch;
fstream file;
clrscr();
file.open("employee.dat",ios::app|ios::out|ios::in);
do
{
cout<<"\nEmployee The Employee Data";
cout<<"\n--------------------------";
e.getdata();
file.write((char*)&e,sizeof(e));
cout<<"\nEnter Your Choice(y/n):";
cin>>ch;
ch=getch();
}
while(ch=='y');
file.open("employee.dat",ios::in,ios::app);
file.seekg(0,ios::end);
int endposition=file.tellg();
int n=endposition/sizeof(employee);
{
cout<<"\nEmployee In File:";
cin>>n;
int position=(n-1)*sizeof(employee);
file.seekg(position);
file.read((char*)&e,sizeof(e));
e.showdata();
}
getch();
}
--------------------------------------------------------------------------------

------------------------------------------------9.
#include<iostream.h>
#include<conio.h>
class bank
{
private:
int bankid;
char bankname[10];
char branch[10];
public:
bank()
{
clrscr();
cout<<"\nEnter The BankID:";
cin>>bankid;
cout<<"\nEnter The Bankname:";
cin>>bankname;
cout<<"\nEnter The Branch:";
cin>>branch;
cout<<"Enter Main"<<endl;
cout<<"\nNo Of Bankdetails Is Created";
cout<<" "<<bankid<<" "<<bankname<<" "<<branch;
}
~bank()
{
cout<<"\nNo Of Bankdetails Is Destroyed";
cout<<" "<<bankid<<" "<<bankname<<" "<<branch;
}
};
void main()
{
bank b1;
cout<<"\nRenter Main";
getch();
}
--------------------------------------------------------------------------------------------------------------------------------10.
#include<iostream.h>
#include<conio.h>
#define maxsize 5
int cq[10];
int front=-1,rear=0;
int choice;
char ch;
int cqinsert();
int cqdelete();
void cqdisplay();
void main()
{

clrscr();
do
{
cout<<"\n1-->Insert";
cout<<"\n2-->Delete";
cout<<"\n3-->Display";
cout<<"\n4-->Exit";
int choice;
cout<<"\nEnter Your Choice:";
cin>>choice;
switch(choice)
{
case 1:
cqinsert();
break;
case 2:
cqdelete();
break;
case 3:
cqdisplay();
break;
case 4:
return;
}
}
while(choice!=4);
}
int cqinsert()
{
int num;
if(front==(rear+1)%maxsize)
{
cout<<"Queuefull";
return 0;
}
else
{
cout<<"\nEnter no";
cin>>num;
if(front==-1)
front=rear=0;
else
rear=(rear+1)%maxsize;
cq[rear]=num;
}
return 0;
}
int cqdelete()
{
int num;
if(front==-1)
{
cout<<"\nQueue empty";
return 0;
}
else

{
num=cq[front];
cout<<"Delete Element is:"<<cq[front];
if(front==rear)
front=rear=-1;
else
front=(front+1)%maxsize;
}
return(num);
}
void cqdisplay()
{
int i;
if(front==-1)
{
cout<<"\nQueue is empty";
}
else
{
cout<<"\nThe Status Of The Queue";
for(i=front;i<=rear;i++)
{
cout<<" "<<cq[i];
}
}
if(front>rear)
{
for(i=front;i<=maxsize;i++)
{
cout<<" "<<cq[i];
}
for(i=0;i<rear;i++)
{
cout<<" "<<cq[i];
}
cout<<"\n";
}
}
---------------------------------------------------------------------------------------------------------------------------------------11.
#include<iostream.h>
#include<conio.h>
class sat
{
private:
int a;
static int b;
public:
sat()
{
a=0;
a++;
b++;
cout<<"A="<<a<<" "<<"B="<<b<<endl;

}
};
int sat::b=0;
void main()
{
clrscr();
sat o1;
sat o2;
sat o3;
getch();
}
-----------------------------------------------------------------------------------------------------------------------------12.
#include<iostream.h>
#include<conio.h>
class the
{
private:
int data;
public:
the()
{
}
the(int d)
{
data=d;
}
void display()
{
cout<<data;
}
the operator=(the &a)
{
data=a.data;
cout<<"\nAssignment In Works";
return *this;
}
};
void main()
{
the a1(40);
the a2,a3;
clrscr();
a3=a2=a1;
cout<<"\nA2=";
a2.display();
cout<<"\nA3=";
a3.display();
getch();
}
--------------------------------------------------------------------------------------------------------------------------------

13.
#include<iostream.h>
#include<conio.h>
class override
{
public:
virtual void show()
{
int i=1;
cout<<"hello "<<i;
}
};
class override1:public override
{
public:
void show()
{
cout<<"\nOverride1";
cout<<"\n-------";
for(int i=1;i<=5;i++)
cout<<" "<<i;
}
};
class override2:public override1
{
public:
void show()
{
cout<<"\nOverride2";
cout<<"\n-------";
for(int i=1;i<=5;i++)
cout<<" "<<i;
}
};
void main()
{
override1 d1;
override2 d2;
override *ptr;
clrscr();
ptr=&d1;
ptr->show();
ptr=&d2;
ptr->show();
getch();
}
--------------------------------------------------------------------------------------------------------------------------------14.
#include<iostream.h>
#include<conio.h>

#include<math.h>
class nbcr
{
private:
int i,j,n,n1,a,x,bi[50];
public:
void getdata()
{
cout<<"\nConverting Decimal To Octal:";
cout<<"\nDecimal no:";
cin>>n;
n1=n;
i=0;
do
{
a=n%8;
bi[++i]=a;
n=n/8;
cout<<endl<<n<<"\t"<<a;
getch();
}while(n!=0);
}
void putdata()
{
cout<<"\nConverting Decimal To Binary:";
cout<<"\nDecimal no:";
cin>>n;
n1=n;
i=0;
do
{
a=n%2;
bi[++i]=a;
n=n/2;
cout<<endl<<n<<"\t"<<a;
getch();
}while(n!=0);
}
};
void main()
{
nbcr n;
clrscr();
n.getdata();
n.putdata();
clrscr();
}
--------------------------------------------------------------------------------------------------------------------------------15.
# include<iostream.h>
# include<conio.h>

class cal
{

int m,y,d,dw,mm,yy;
int dm[13];
public:
cal()
{
m=1;y=2003;d=1;dw=4;mm=yy=0;
dm[1]=dm[3]=dm[5]=dm[7]=dm[8]=dm[10]=dm[12]=31;
dm[4]=dm[6]=dm[9]=dm[11]=30;
dm[2]=29;
}
void getdate()
{
cout<<"enter month..(mm)";
cin>>mm;
cout<<"enter year..(yyyy)";
cin>>yy;
}
void calformat()
{
int d=dw;
if(mm==2)
{
if(y%4!=0)
dm[mm]=28;
}
int k=-1;
cout<<"SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n";
for(int i=1;i<d;i++)
cout<<'\t';
for(int j=1;i<8;i++,j++)
cout<<j<<'\t';
cout<<'\n';
for(i=j;i<dm[mm]+1;i++)
{
if(++k==7)
{
cout<<'\n';
k=0;
}
cout<<i<<'\t';
}
cout<<'\n';
}
void skiptonext()
{
int d1=29;
if((y%4)!=0 && m==2)
{}
else
{
for(;d1<dm[m]+1;d1++)
{
if(dw==7)
dw=1;
else
dw++;
}
}
m++;
}
void dwa()
{
if(dw==7)
dw=1;
else
dw++;
}
void dwd()
{
if(dw==1)

dw=7;
else

dw--;

}
void evaly()
{
if(yy>y)
{
while(y!=yy)
{
if((y%4)==0)
{
dwa();
}
dwa();
y++;
}
}
else if(yy<y)
{
while(y!=yy)
{ y--;
if((y%4)==0)
{
dwd();
}
dwd();
}
}
}
void evalm()
{
while(m!=mm)
{
skiptonext();
}
}
};
void main()
{
char f='y';
clrscr();
do
{
cal c;
c.getdate();
c.evaly();
c.evalm();
c.calformat();
cout<<"enter y to contn.,";
f=getch();
cout<<endl;
}while(f=='y');
}

Das könnte Ihnen auch gefallen