Sei sulla pagina 1di 6

//DELETION FROM A LINKED QUEUE

#include<iostream.h>
#include<process.h>
#include<conio.h>
struct Node{int info; //for exit()
Node*next;
}*front,*newptr,*save,*ptr,*rear;
Node*Create_New_Node(int);
void Insert(Node*);
void Display(Node*);
void DelNode_Q();
void main()
{front=rear=NULL; //In the beginning Linked-Queue isn empty,thus,pointers are NULL
int inf;char ch ='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n Enter INFOrmation for the new code....";
cin>>inf;
newptr= Create_New_Node(inf);
if(newptr==NULL)
{cout<<"\nCannot crete new Node!!!Aborting!!\n";exit(1);}
Insert(newptr);
cout<<"\nPress Y to enter more nodes,N to exit...\n";
cin>>ch;
}
clrscr();
do
{cout<<"\n The Linked-Queue now is(Front...to..Rear):\n";
Display(front);
cout<<"Want to delete first node?(y/n)...";
cin>>ch;
if(ch=='y'||ch=='Y')
DElNode_Q();
}while(ch=='y'||ch=='Y');
}
Node*Create_New_Node(int n) //Function to create new node dynamically
{ ptr=new Node;
ptr->info=n; ptr->next=NULL;
return ptr;
}
void Insert(Node*np) //Function to insert node in the Linked_Queue
{ if(front==NULL){front=rear=np;}
else
{rear->next=np; rear=np;}
//FILE HANDLING

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
char rec[80],ch;
char fname[20];
int count =0,i;
char ans =’y’;
clrscr();
cout<<”Enter file name:”;
cin.get(fname,20);
ofstream fout(fname,ios::out);

if(!fout)
{cout<<”Error in creating file..!!\n”;
cout<<”Press any key to exit..!!\n”;
getch();
exit(1);
}
cin.get(ch);
cout<<”Enter information to store..\n”;
while(ans==’y’||ans==’Y’)
{
cin.get(rec,80);
fout<<rec<<”\n”;
cout<<”Want to enter more?(y/n)..”;
cin>>ans;
count++;
cin.get(ch);
}
cout<<”\nThe information successfully stored in the file..!!\n”;
fout.close();

cin.get(ch);
cout<<”Want to see? (y/n)..”;
cin>>ans;
if(ans==’y’||ans==’Y’)
{
ifstream fin(fname,ios::in);
if(!fin)
{
cout<<”Error in opening the file..!!\n”;
cout<<”Press any key to exit..\n”;
getch();
exit(2);
}
fin.seekg(0);
cout<<”\n”;

cout<<”The file contains:\n”;


for(i=0;i<count;i++)
{
fin.get(rec,80);
fin.get(ch);
cout<<rec<<”\n”;
}
fin.close();
}
getch();
}

Enter file name: trial


Enter information to store//
we r trying it
Want to enter more?(y/n)..y
learning is a life long process
Want to entermore?(y/n)..y
stay calm;
Want to enter more?(y/n)..n
The information successfully stored in the file..!!

Want to see..(y/n).. y

The file contains:


we r trying it
learning is a life long process
stay calm
//Program to create a single file and then display its contents
#include<fstream.h>
#include<conio.h>
{ ofstream fout ;
fout.open{“student”}; //CONNECT FILE TO OUTPUT STREAM
clrscr();
char name[30], ch;
float marks= 0.0;
for(int i=0;i<5;i++)
{
cout<<”student”<<(i+1)<<”/t name:”;
cin.get(name, 30);
cout<<”/t/ marks:”;
cin>>marks:”;
cin.get(ch);
fout<<name<<”/n”<<marks<<’’/n’’;
}
fout.close (); //DISCONNECTING STUDENT
ifstream fin (“student ‘’); //CONNECTING FILE TO INPUT STREAM
fin.seekg(0); //TO BRING FILE POINTER TO BEGINNING
cout<<”/n”;
for(i=0; i<5;i++)
{
fin.get(name,30);
fin.get(ch);
fin>>marks;
fin.get(ch)
cout<<”student name :”<<name;
cout<<”/t marks :”<<marks<<”/n”;
}
fin.close (); //DISCONNECT FILE
return 0;
}
student1 name:ritu
marks:45
student2 name:era
marks:67
student3 name:yuvi
marks:67
student4 name:ganesh
marks :78
student5 name:john
marks:56
student name.ritu marks:45
studentname.era marks:67
studentname.yuvi marks:67
studentname.ganesh marks:78
studentname.john marks:56
#include<fstream.h>
#include<coino.h>
#include<string.h>
#include<stdio.h>
#include<process.h>
class TABLE
{
int height;
char colour[10];
public:
void getdata()
{cout<<”enter height:”;
cin>>height;
cout<<”Enter Color:”;
gets(colour);
}
void showdata()
{ cout<<”Contents are :\n”;
cout<<height<<” “ <<colour<<endl;
}
};
//Function to write the object of class to binary file
void create()
{ ofstream afile;
TABLE tab;
afile.open(“Table.dat”,ios::out\ios::binary);
if(!afile)
{
cout<<”\n Unable to open the file”;
exit(1);
}
tab.getdata();
afile.write((char*)&tab,sizeof(tab));
afile.close();
}
//Function to read the object of class from the binary file
void read_file()
{
ifstream afile;
afile.open(“Table.dat”,ios::in\ios::binary);
if(!afile)
{
cout<<”\n File does not exist”;
exit(1);
}
TABLE tab;
afile.read((char *) &tab,sizeof(tab));
while(afile)
{
tab.showdata();
afile.read((char *) &tab,sizeoff(tab));
}
afile.close();
}
void main()
{
clrscr();
create();
read_file();
}

enter height :45


enter Color :red
contents are:
45 red

Potrebbero piacerti anche