You are on page 1of 23

CERTIFICATE

This is to certify that this dissertation


is
Submitted by PRANAV ANAND to
Computer science department of
RYAN INTERNATIONAL
SCHOOL,ROHINI
Was carried under guidance and
supervision during the academic year
2015-1016
MS.RITU DAWAR(Computer science
teacher)

ACKNOWLEDGEME
NT
I wish to express my deep gratitude thanks to
the principle ,MS.PRIYA ARORA for all the
facilities that she provided for this project
work .I extend my hearty thanks to MS.RITU
DAWAR,C.S teacher, who guided me to the
successfully completion of this project work.
I cant forget to offer my sincere thanks to
my mother who helped me to carry out this
project work successfully and for their
valuable advice and support which I received
from time to time.

CLASS

#include<iostream.h>
#include<fstream.h>
class Student
{
char name[20];
int mark;
public:
void GetStudentData();
void ShowStudentData();
};
void Student :: GetStudentData()
{
cout << "Enter Student Name:" << endl;
cin >> name;
cout << "Enter Student Mark:" << endl;
cin >> mark;}
void Student :: ShowStudentData()
{
cout << "Student Details are:" << endl;
cout << "Name: " << name << endl
<< "Mark: " << mark << endl;
}
int main(int argc, char *argv[])
{char ans='y';
Student sobj;
//We open student.dat in append mode
ofstream out("student.dat", ios::app);
if(!out.eof())
{//Loop will continue until something other then y is entered
while( ans == 'y')
{
cout << endl << "Continue ?";
cin >> ans;
if(ans == 'y')
{sobj.GetStudentData();

out.write((char*) & sobj, sizeof(sobj));


}
}
}
out.close();
ifstream in("student.dat");
if(!in.eof())
{
while(!in.eof())
{
in.read((char*) &sobj, sizeof(sobj));
if(!in.eof())
{sobj.ShowStudentData();
}
}
}
in.close();
}

OUTPUT

PROGRAM FOR BUBBLE SORT


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[80],n;
cout<<"Enter desired size of array (<80): "; cin>>n;
cout<<"\n\nEnter the array : \n";
for(int i=0; i<n; i++)
cin>>A[i];
cout<<"\n\nArray of elements is as shown below : \n\n";
for(i=0; i<n; i++)
cout<<A[i]<<" ";
cout<<"\n\nNow Elements will be arranged in ascending order using
bubble sort :\n\n";
void bubble_sort(int A[],int n);
bubble_sort(A,n);
getch();
}
void bubble_sort (int A[], int n)
{ int temp; int count=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n-1; j++)
{ if(A[j+1]<A[j])
{ count++;
temp=A[j+1];
A[j+1]=A[j];
A[j]=temp;
cout<<"\n\nArray for iteration "<<count<<" is :
\n\n";
for(int k=0; k<n; k++)
cout<<A[k]<<" ";

}
}

OUTPUT

CLASS
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class aeroplane
{
private:
int flightno;
char destination[25];
float distance;
float fuel;
float calfuel();
public:
void feedinfo();
void showinfo();
};
float aeroplane::calfuel()
{
float cost;
if(distance<=1000)
cost=500;
else if((distance>1000)&&(distance<=2000))
cost=1100;
else

cost=2200;
return cost;
}
void aeroplane::feedinfo()
{
cout<<"Enter the flight number:";
cin>>flightno;
cout<<"Enter the destination:";
gets(destination);
cout<<"Enter the distance:";
cin>>distance;
fuel=calfuel();
}
void aeroplane::showinfo()
{
cout<<"Flight number:"<<flightno<<'\n';
cout<<"Destination:"<<destination<<'\n';
cout<<"Distance:"<<distance<<'\n';
cout<<"Fuel cost:"<<fuel<<'\n';
}
void main()
{
aeroplane a1;
a1.feedinfo();
a1.showinfo();
getch();
}

OUTPUT

LINEAR SAERCH
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int A[50]; int n; int p; int subscript; /*Note:
subscript and index are same.*/
cout<<"Enter the array size : ";
cin>>n;
// n=size upto which user wants to
insert values in array
cout<<"\n\nEnter elements of array : \n";

for(int i=0; i<n; i++)


cin>>A[i];
cout<<"\n\nThe array formed = ";
for(i=0; i<n; i++)
cout<<A[i]<<" ";
cout<<"\n\nEnter the element to be searched : ";
cin>>p;
// p=element to be searched
void linear_search ( int A[], int n, int p);
//function declaration
linear_search(A,n,p);
getch();
}
void linear_search(int A[], int n, int p)
{ int count=0; int B[50]; int flag=0;
for(int i=0; i<n; i++)
{ flag=count;
if( A[i]==p)
{
B[count]=i;
count++;
flag=count;
}
}
if(flag==0)
cout<<"\n\nRequested element not found.";
else
for(i=0; i<=n; i++)
{ if(A[i]==p)
{
cout<<"\n\nElement "<<p<<" is found";

cout<<"\n\nSubscript =
"<<i<<"\n\nPosition = "<<i+1<<"\n\n\n";
}
}
}

OUTPUT

Program to carry operations on matrix


#include<iostream.h>
#include<conio.h>
void main()
{
int A[3][3],i,j;
cout<<"Enter the matrix:";
for(i=0;i<3;i++)

{cout<<"\n";
for(j=0;j<3;j++)
{
cin>>A[i][j];
}
}
int s1=0,s2=0,s3=0,s4=0,s5=0,s6=0,s7=0;
for(j=0;j<3;j++)
{
s1=s1+A[0][j];
s2=s2+A[1][j];
s3=s3+A[2][j];
}
for(i=0;i<3;i++)
{
s4=s4+A[i][0];
s5=s5+A[i][1];
s6=s6+A[i][2];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if((i==j)||(i+j==2))
{
s7=s7+A[i][j];
}
}
}
cout<<"Sum of first row:"<<s1<<'\n';
cout<<"Sum of second row:"<<s2<<'\n';
cout<<"Sum of third row:"<<s3<<'\n';
cout<<"Sum of first column:"<<s4<<'\n';
cout<<"Sum of second column:"<<s5<<'\n';
cout<<"sum of third column:"<<s6<<'\n';
cout<<"Sum of diagonals:"<<s7<<'\n';
cout<<"Upper half of matrix:"<<'\n';
for(i=0;i<3;i++)

{cout<<'\n';
for(j=0;j<3;j++)
{
if((i+j)<=2)
cout<<A[i][j]<<'\t';
}
}cout<<'\n';
cout<<"Lower half of matrix:"<<'\n';
for(i=0;i<3;i++)
{cout<<'\n';
for(j=0;j<3;j++)
{
if((i+j)>=2)
cout<<A[i][j]<<'\t';
}
}cout<<'\n';
cout<<"Transposed matrix:"<<'\n';
for(j=0;j<3;j++)
{cout<<"\n";
for(i=0;i<3;i++)
{
cout<<A[i][j]<<'\t';
}
}
getch();

OUTPUT

Program to check whether


string is pallindrome.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

#include<string.h>
void main()
{
char str[10];
char add1[]="Yes it is Pallindrome ";
char add2[]="No it is not Non-pallindrome ";
cout<<"\n\nEnter the string:";
gets(str);
int size=strlen(str);
int flag;
for(int i=0,j=size-1;i<size/2;i++,j--)
{
if(str[i]==str[j])
flag=1;
else
flag=0;
break;
}
if(flag==1)
{
strcat(add1,str);
cout<<add1;
}
else
{
strcat(add2,str);
cout<<add2;
}
getch();
}

//OUTPUT

SELECTION SORT

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[80],n;
lb: cout<<"Enter the size of array : ";
cin>>n;
if(n<=0||n>80)
{cout<<"\n\nEnter size of array less than or
equal to 80.";
goto lb;
}
cout<<"\n\nEnter the elements of array : \n\n";
for(int i=0; i<n; i++)
cin>>A[i];
void selection_sort(int A[],int n);
selection_sort(A,n);
cout<<"\n\n\n\n\nSorted array is : \n\n";
for(i=0; i<n; i++)
cout<<A[i]<<" ";
getch();
}
void selection_sort(int A[], int n)
{int small;
int k,count=0;
for(int i=0; i<n; i++)
{ small=A[i]; count++;
for(int j=i+1; j<n; j++)
{
if(A[j]<small)
{small=A[j];
A[j]=A[i];
A[i]=small;
}

}
cout<<"\n\nArray after iteration "<<count<<"
is :\n\n";
for(k=0; k<n; k++)
cout<<A[k]<<" ";
}
}

OUTPUT

Menu driven program to make


square of the number.
.

#include<iostream.h>
#include<conio.h>
int x;
class square
{
public:
int pow1(int x)
{ return x*x;
}
int pow2(int x);
};
int square::pow2(int x)
{
return x*x*x;
}
void main()
{
cout<<"\nEnter the number:";
cin>>x;
square s1;
int n;
cout<<"Enter your choice from 1,2 :";
cin>>n;
switch(n)
{
case 1:
cout<<"Output of inline
function:"<<s1.pow1(::x);
break;
case 2:

cout<<"Output of outline
function:"<<s1.pow2(::x);
break;
default:cout<<"Choose from 1 and 2
only.";
}
getch()

OUTPUT

Program to sum measurements.


#include<iostream.h>

#include<conio.h>
void main()
{
float inches;
float feet;
cout<<"Enter the inches measurement:";
cin>>inches;
cout<<"Enter the feet measurement:";
cin>>feet;
float sum=0;
float adjust(float inches);
sum=feet+adjust(inches);
cout<<"Sum="<<sum;
getch();
}
float adjust(float inches)
{
float convert;
convert=inches/12;
return convert;
}

output

BIBLOGRAP
HY
Computer science book
Notes

You might also like