C++ Practicle File
C++ Practicle File
C++ Practicle File
Shorting in array
#include<iostream>
min = i;
min = j;
temp = a[i];
a[i] = a[min];
a[min] = temp;
int main() {
int i;
cout<<endl;
selectionSort(a, n);
return 0;
OUTPUT
Given array is:
22 91 35 78 10 8 75 99 1 67
1 8 10 22 35 67 75 78 91 99
#include<conio.h>
void main()
clrscr();
cin>>size;
cin>>arr[i];
cin>>insert;
cout<<"At which position (Enter index number) ? ";
cin>>pos;
arr[i]=arr[i-1];
arr[pos]=insert;
cout<<arr[i]<<" ";
getch();
OUTPUT
Q. Searching in Array using function
#include<iostream>
int main()
cin>>n;
cout<<" ";
cin>>arr[i];
cin>>num;
if(arr[i]==num)
cnt=1;
pos=i+1;
break;
}
}
if(cnt==0)
else
return 0;
OUTPUT
Q. Print table of any given variable using function
#include<iostream>
int main()
int num;
cin>>num;
for(int a=1;a<=10;a++)
return 0;
OUTPUT
Q. To find greatest among three using Call-by value function.
#include<iostream.h>
#include<stdio.h>
#include<conio. h>
void main ()
clrscr ();
int a, b, c, l;
cin>>a;
cin>>b;
cin>>c;
l=greatest (a,b,c);
getch ();
if (a>b&&a>c)
cout<<" \n A is Greatest.";
if (b>a &&b>c)
cout<<" \n B is Greatest.";
if (c>a&&c>b)
cout<<" \n C is Greatest";
OUTPUT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void read (int *xyz)
int t;
cin>>t;
*xyz=t;
xyz++;
xyz=xyz-5;
for (i=0;i<5;i++)
{cout<<"\n\t"<<*xyz;
xyz++;}
{int* start;
start=xyz;
inti,j,temp;
for (j=0;j<5;j++)
for (i=0;i<4;i++)
if (*xyz>* (xyz+1))
temp=*xyz;
*xyz= * (xyz+1);
* (xyz+1) =temp;
xyz++;
xyz=start;
void main ()
clrscr ();
intf,g, arr[5];
int **;
x=&arr[0];
read (x);
st (x);
cout<<"\nSortedArr is \n";
{cout<<arr[i]; cout<<"\n";}
getch ();
OUTPUT
Q-Insertion of data using single level inheritance.
#include <iostream>
#include <conio.h>
private:
char fname[100],lname[100],gender[10];
protected:
int age;
public:
void input_person();
void display_person();
};
private:
char college_name[100];
char level[20];
public:
void input_student();
void display_student();
};
void person::input_person()
cin>>fname;
cin>>lname;
cout<<"Gender: ";
cin>>gender;
cout<<"Age: ";
cin>>age;
void person::display_person()
{
cout<<"Gender : "<<gender<<endl;
cout<<"Age : "<<age<<endl;
void student::input_student()
person::input_person();
cout<<"College: ";
fflush(stdin);
gets(college_name);
cout<<"Level: ";
cin>>level;
void student::display_student()
person::display_person();
cout<<"College : "<<college_name<<endl;
cout<<"Level : "<<level<<endl;
int main()
student s;
cout<<"Input data"<<endl;
s.input_student();
cout<<endl<<"Display data"<<endl;
s.display_student();
getch();
return 0;
OUTPUT
Input data
Gender: Male
Age: 23
Level: Bachelors
Display data
Gender : Male
Age : 23
Level : Bachelors
public:
void display()
};
class B : public A
};
class C : public B
};
int main()
C obj;
obj.display();
return 0;
OUTPUT
Base class content.
public:
Mammal()
};
class WingedAnimal {
public:
WingedAnimal()
};
};
int main()
Bat b1;
return 0;
OUTPUT
Mammals can give direct birth.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void main ()
clrscr();
int size=5,item;
do
cin>>ch;
switch (ch)
else
cin>>item;
arr[rear]=item;
rear++;
};break;
else
cout<<arr [front];
rear++;
};break;
again!";
} while (ch-3);
getch ();
OUTPUT
CONSTRUCTOR
#include <iostream>
class Line {
public:
void setLength( double len );
private:
double length;
};
Line::Line(void) {
length = len;
return length;
int main() {
Line line;
line.setLength(6.0);
return 0;
}
OUTPUT
Length of line : 6
DISTRUCTOR
#include <iostream>
class Line {
public:
private:
double length;
};
Line::Line(void) {
cout << "Object is being created" << endl;
Line::~Line(void) {
length = len;
return length;
int main() {
Line line;
line.setLength(6.0);
return 0;
OUTPUT
Object is being created
Length of line : 6
#include <stdlib.h>
void readmatA();
void printmatA();
void readmatB();
void printmatB();
void sum();
void diff();
void main()
exit(1);
else
readmatA();
printf("MATRIX A is \n");
printmatA();
readmatB();
printf("MATRIX B is \n");
printmatB();
sum();
diff();
void readmatA()
scanf("%d", &a[i][j]);
return;
void readmatB()
{
for (j = 0; j < column2; j++)
scanf("%d", &b[i][j]);
void printmatA()
printf("%3d", a[i][j]);
printf("\n");
void printmatB()
printf("%3d", b[i][j]);
}
printf("\n");
void sum()
printf("%3d", sumarray[i][j]) ;
printf("\n");
return;
void diff()
{
for (i = 0; i < row1; i++)
printf("%3d", arraydiff[i][j]);
printf("\n");
return;
OUTPUT
Enter the order of the matrix A
33
33
145
678
489
MATRIX A is
1 4 5
6 7 8
4 8 9
367
842
153
MATRIX B is
3 6 7
8 4 2
1 5 3
Sum matrix is
4 10 12
14 11 10
5 13 12
Difference matrix is
-2 -2 -2
-2 3 6
3 3 6