Вы находитесь на странице: 1из 6

//SUM OF SERIES USING FUNCTION OVERLOADING

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>

double factorial(int n)
{
double pro=1;
for(int i=1;i<=n;i++)
pro*=i;
return(pro);
}
void sum()
{ double x,n,tot=0;
cout<<endl<<endl<<"Enter the 'n' value to find the sum of odd numbers : ";cin>>n;
cout<<"Enter the value for X to find the sum of odd numbers : ";cin>>x;
for(int i=1,j=1;i<=n;i++,j+=2)
{
tot+=(pow(x,j)/factorial(j));
}
cout<<endl<<"THE SUM OF ODD NUMBER SERIES="<<tot;
}
void sum(int m)
{ double x;
double tot=0;
cout<<"Enter the value for x to find even numbers : ";cin>>x;
for(double i=1,j=2;i<=m;i++,j+=2)
{
tot+=(pow(x,j)/factorial(j));
}
cout<<endl<<"THE SUM OF EVEN NUMBER OF SERIES="<<tot;
}
void main()
{
clrscr();
cout<<"\n SUM OF SERIES USING FUNCTION OVERLOADING "<<endl;
int n;
cout<<"\nEnter the 'n' value to find the sum of even numbers : ";
cin>>n;
sum(n);
sum();
getch();
}
//BINARY FILE OPERATIONS

#include<fstream.h>
#include<conio.h>

struct stu
{ int rollno;
char name[25],std[4];
float marks;
char grade;
};
void in()
{stu s1;
ofstream f("stu.dat",ios::binary);
char ch='y';
while(ch=='y')
{ cout<<"\n\nEnter the record:\n";
cout<<"rollno. :";
cin>>s1.rollno;
cout<<"Name:";
cin>>s1.name;
cout<<"std:";
cin>>s1.std;cout<<"Marks:";
cin>>s1.marks;
cout<<"Grade:";
cin>>s1.grade;
f.write((char*)&s1,sizeof(stu));
cout<<"Do you want to enter records into the file :";
cin>>ch;
}
}
void search()
{ stu s1;
ifstream fin("stu.dat",ios::in|ios::binary);
int rno,I=0;
cout<<"\nEnter the roll no to be searched:";
cin>>rno;
while(fin)
{ fin.read((char*)&s1,sizeof(stu));
if(s1.rollno==rno)
{ cout<<"Record found\n";
cout<<"rollno.:"<<s1.rollno<<endl<<"Name:"<<s1.name<<endl<<"std:"<<s1.std
<<endl<<"Marks:"<<s1.marks<<endl<<"Grade:"<<s1.grade<<endl;
I=1;break;}
}
if(I==0)
cout<<"Record not found";
}
void out()
{ stu s1;
ifstream f("stu.dat",ios::in|ios::binary);
while(f)
{ f.read((char*)&s1,sizeof(stu));
cout<<"rollno.:"<<s1.rollno<<endl<<"Name:"<<s1.name<<endl<<"std:"<<s1.std
<<endl<<"Marks:"<<s1.marks<<endl<<"Grade:"<<s1.grade<<endl;
}
}
void main()
{ clrscr();
cout<<"\t\t BINARY FILE OPERATION-SEARCH";
in();
search();
getch();
}
//MERGE SORT

#include<iostream.h>
#include<conio.h>

void merge(int a[],int b[],int m,int n)


{ int c[100];
for(int i=0,j=0,k=0;k<(m+n);k++)
if(j>=n||a[i]<b[j])
{c[k]=a[i];
i++;
}
else
{ c[k]=b[j];
j++;
}
cout<<"The merged sort :"<<endl;
for(i=0;i<(m+n);i++)
cout<<"Element"<<i+1<<" is: "<<c[i]<<endl;
}
void main()
{ clrscr();
int a[50],b[50],m,n;
cout<<"\t\t MERGE SORT\n";
cout<<"Enter the number of elements in first array:";
cin>>m;
cout<<"Enter the first array elements:"<<endl;
for(int i=0;i<m;i++)
{ cout<<"Enter "<<i+1<<" element:";
cin>>a[i];
}cout<<"Enter the number of elemets in second array:";
cin>>n;
cout<<"Enter the number of elements:"<<endl;
for(i=0;i<n;i++)
{cout<<"Enter "<<i+1<<" element:";
cin>>b[i];
}
merge(a,b,m,n);
getch();
}
//DELETE OPERATION IN A QUEUE

#include<iostream.h>
#include<conio.h>
#include<process.h>

void disp(int queue[],int rear,int front)


{ for(int i=front;i<=rear;i++)
cout<<queue[i]<<"<--";
cout<<endl;
}
void insert(int queue[],int n,int &rear,int &front)
{ char ch='y';
int item;
while(ch=='y')
{
if(rear==n-1)
{ cout<<"Overflow!!"<<endl;
break;
}
cout<<"Enter the item to be inserted : ";
cin>>item;
rear++;
queue[rear]=item;

disp(queue,rear,front);
cout<<"\nDo u want to insert an element into the queue(y/n):";
cin>>ch;
}
}
void del(int queue[],int &rear,int &front)
{ char ch='y';
while(ch=='y')
{ if(front==-1 || front==rear)
{ cout<<"Underflow!!"<<endl;
break;
}
else
front++;
disp(queue,rear,front);
cout<<"\nDo u want to delete an element into the queue(y/n):";
cin>>ch;
}
}
void main()
{ clrscr();
cout<<"\t\t DELETE OPERATIONS ON A QUEUE\n";
int queue[100],n,front=-1,rear=-1;
cout<<"Enter the number of elements in the queue:";
cin>>n;
char ch='s';
while(ch!='x')
{ cout<<"\nDo you want to insert or delete(type 'i' to insert, 'd' to delete,type 'x' to exit) : ";
cin>>ch;
if(ch=='i')
{ cout<<"\nINSERT"<<endl;
front=0;
insert(queue,n,rear,front);
}
else if(ch=='d')
{ cout<<"\nDELETE"<<endl;
del(queue,rear,front);
}
else if(ch=='x')
{ getch();
exit(0);
}
else
cout<<"OPTION INCORRECT";}
getch();
}

Вам также может понравиться