C++ Programs XII
C++ Programs XII
C++Practical File
Submitted To:
By:
Submitted
INDEX
S.No Program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Teacher
s
Signatu
re
28
29
30
s=(a+b+c)/2;
ar(a,b,x); break;
default:cout<<"wrong choice";}}
OUTPUT:
OUTPUT:
Output:
OUTPUT:
Write a C+
+Program to implement multiple inheritance.
#include<iostream.h>
class chair{ public:
int a; };
class direct{ public:
int b; };
class compy:public chair,public direct
{public:int c;
void an(){cout<<"enter a,b,c respectively;\n";
cin>>a>>b>>c;
cout<<"a="<<a<<endl<<"b="<<b<<endl<<"c="<<c; }
};
void main()
{ compy a2;
a2.an(); }
Output:
Write a C+
+Program to illustrate access control of inherited
member in the privately derived class.
#include<iostream.h>
class an{
public:int a; };
class meh: private an
{int b;
public:
void har(){cout<<"enter a,b respectively;\n";
cin>>a>>b;
cout<<"a:"<<a<<",b:"<<b;}
};
void main()
{
meh a4;
a4.har();
}
Output:
int main()
{ ofstream fout;
fout.open("Student",ios::out);
char name[90],ch; float marks=0.0;
for(int i=0;i<5;i++)
{ cout<<"student"<<i+1<<":\tName:";
cin.get(name,30); cout<<"\t\tmarks:";
cin>>marks; cin.get(ch);
fout<<name<<'\n'<<marks<<"\n";
}
fout.close();
ifstream fin("Student",ios::in);
fin.seekg(0); cout<<"\n";
for(i=0;i<5;i++)
{ fin.get(name,30);
fin.get(ch); fin>>marks;
fin.get(ch);
cout<<"student name:"<<name<<"\tmarks:"<<marks<<endl;
}
fin.close();
return 0;}
Output:
{cout<<endl;line++;}
if(line>22){line=0;}
}
return 0;
}
Output:
last=size-1;
while(beg<=last)
{mid=(beg+last)/2;
return -1;
}
Output:
pos=j;}
}
tmp=A[i];
A[i]=A[pos];
A[pos]=tmp;
cout<<"\nArray After pass-"<<i+1<<"-is:";
for(j=0;j<size;j++)
cout<<A[j]<<" "<endl;
}
}
Output:
A[j+1]=tmp;
}
}
cout<<"\nArray After Iteration-"<<++ctr<<"-is:";
for(int k=0;k<size;k++)
cout<<A[k]<<" "<endl;
}
}
Output:
{
A[j+1]=A[j];
j--;
}
A[j+1]=tmp;
cout<<"\nArray After pass-"<<i<<"-is:";
for(int k=1;k<=size;k++)
cout<<A[k]<<" "<endl;
}
}
Output:
{ int a,b,c;
for(a=0,b=0,c=0;a<M&&b<N;)
{ if(A[a]<B[b]) C[c++]=A[a++];
else C[c++]=B[b++];
}
if(a<M)
{while(a<M)
C[c++]=A[a++];}
if(b<N)
{while(b<N)
C[c++]=B[b++];}
}
Output:
{for(j=0;j<n;j++)
c[i][j]+=a[i][j]*b[i][j]; }
cout<<"\nthe sum of 2 matrices is:\n" ;
for(i=0;i<m;i++)
{ cout<<endl;
for(j=0;j<n;j++)
cout<<" "<<c[i][j];
}
return 0;}}
Output:
{for(j=0;j<q;j++)
{c[i][j]=0;
for(ip=0;ip<n;ip++)
c[i][j]+=a[i][ip]*b[ip][j]; } }
cout<<"\nthe product of 2 matrices is:\n" ;
for(i=0;i<m;i++)
{ cout<<endl;
for(j=0;j<q;j++)
cout<<" "<<c[i][j]; }
return 0;}}
Output:
cout<<" "<<c[i][j];}
}
return 0;
}
Output:
else
{save=start; start=np;
np->next=save;}}
void disp(node*np)
{ while(np!=NULL)
{cout<<np->info<<"->";
np=np->next; }
cout<<"!!!!!!!!!\n"; }
Output: