SlideShare a Scribd company logo
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<fstream>
#include<stdlib.h>
#include<iomanip>
//record specification
using namespace std;
fstream data,indx;
char pri[125][15]; // to hold primary keys
int ind[125],count=0;
void sort1();
class student
{
public :
char Regno[10], Name[25], Address[50], Sem[5], Branch[10],
College[15];
public:
void Insert();
void Delete();
void Search(char *a); /* To display individual record */
void Display();/* to display all records in file-- yet to
implement*/
// void Loadindx();
void Writeindx();
}s;
void student::Insert()
{
char Buffer[100],offset[10];
int pos, high = count;
data.open("stu.txt",ios::app);
data.seekg(0,ios::end);
pos=data.tellg(); // gets the address of that posn
cout<<"ENTER RECORD DETAILSn";
cout<<"RegNo : ";
cin>>s.Regno;
for(int low=0;low<=high;)
{
int mid = (low+high)/2;
int k = atoi(pri[mid]), m = atoi(s.Regno);
if(k == m)
{
cout<<setw(44)<<"DUPLICATE RECORD !!!";
return;
}
else if(m < k)
high = mid-1;
else if(m > k)
low = mid + 1;
} // to search for duplicate usn -- can avoid
cout<<"Name : "; cin>>s.Name;
cout<<"Address : "; cin>>s.Address;
cout<<"Sem : "; cin>>s.Sem;
cout<<"Branch : "; cin>>s.Branch;
cout<<"College : "; cin>>s.College;
sprintf(Buffer,"|%s|%s|%s|%s|%s|%s|
#",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College);
data<<Buffer;
strcpy(pri[count],s.Regno);
ind[count]=pos;
count++;
cout<<count;
data.close();
s.Writeindx();
}
void student::Writeindx()
{
char buffer[100];
int i;
indx.open("inx.txt", ios::out);
sort1();
for(i=0;i<count;i++)
{
//itoa(ind[i],buffer,10);
sprintf(buffer, "%d", ind[i]);
indx<<"|"<<pri[i]<<"|"<<buffer<<"|"<<"#";
}
indx.close();
}
void sort1()
{
char temp[20];
int tempind,k,i,j,l;
for(i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
k = atoi(pri[i]);
l = atoi(pri[j]);
if(k > l)
{
strcpy(temp,pri[i]);
strcpy(pri[i],pri[j]);
strcpy(pri[j],temp);
tempind=ind[j];
ind[j]=ind[i];
ind[i]=tempind;
}
}
}
}
void student::Search(char *reg)
{
int high = count,flag1=0;
char Buffer[100];
data.open("stu.txt",ios::in);
for(int low=0;low<=high;)
{
int mid = (low+high)/2;
int k = atoi(pri[mid]), m = atoi(reg);
if(k == m) // or else use strcmp()==0
{
flag1 = 1;
data.seekg(ind[mid],ios::beg);
data.getline(Buffer,100,'#');
sscanf(Buffer,"|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%
[^|]#",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College);
cout<<endl<<"RECORD DETAILS"<<endl;
cout<<endl<<"URN : "<<s.Regno;
cout<<endl<<"NAME : "<<s.Name;
cout<<endl<<"ADDRESS : "<<s.Address;
cout<<endl<<"SEMESTER : "<<s.Sem;
cout<<endl<<"BRANCH : "<<s.Branch;
cout<<endl<<"COLLEGE : "<<s.College<<"n";
data.close();
return; // or use break stmt here
}
else if(m < k)
high = mid-1;
else if(m > k)
low = mid + 1;
}
if(flag1==0)
cout<<endl<<"RECORD DOES NOT EXISTSn";
data.close();
}
void student::Delete()
{
char reg[20],Buffer[100],usn[15];
int high = count,flag=0;
cout<<endl<<"ENTER USN: ";
cin>>reg;
data.open("stu.txt",ios::in | ios::out);
for(int low=0;low<=high;)
{
int mid = (low+high)/2;
int k = atoi(pri[mid]), m = atoi(reg);
if(k == m)
{
flag=1;
data.seekg(ind[mid],ios::beg);
data.getline(Buffer,100,'#');
Buffer[0]='*';
pri[mid][0]='*';
data.seekg(ind[mid],ios::beg);
data<<Buffer;
cout<<endl<<"RECORD DELETED";
data.close();
s.Writeindx();
return;
}
else if(m < k)
high = mid-1;
else if(m > k)
low = mid + 1;
}
if(flag==0)
{
cout<<endl<<"RECORD NOT FOUND !!!";
}
data.close();
}
void student :: Display()
{
char Buffer[100];
data.open("stu.txt",ios::in);
char b[100];
while(!data.eof())
{
data.getline(Buffer,100,'#');
if(data.eof())
break;
if(Buffer[0]!='*')
{
sscanf(Buffer,"|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%
[^|]#",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College);
cout<<s.Regno<<" "<<s.Name<<" "<<s.Address<<" "<<s.Sem<<"
"<<s.Branch<<" "<<s.College<<endl;
}
else
continue;
}
data.close();
}
int main()
{
fstream f1,f2;
int choice;
char usn[20];
for(;;)
{
cout<<"n1.Add record n2.search record n
3.deleterecordn4.display recordn";
cin>>choice;
switch(choice)
{
case 1:s.Insert();
break;
case 2:cout<<endl<<"ENTER UsN: ";
cin>>usn;
s.Search(usn);
break;
case 3:s.Delete();
break;
case 4: s.Display();
break;
default: exit(0);
}
}
}

More Related Content

What's hot

Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
Movel
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
Flavien Raynaud
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
Romain Lecomte
 
Simple uses of ADRCI
Simple uses of ADRCISimple uses of ADRCI
Simple uses of ADRCI
Douglas Hawthorne
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
Nikita Popov
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
Nikita Popov
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723
kamiyam .
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
Nikita Popov
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Mail.ru Group
 
Sample file processing
Sample file processingSample file processing
Sample file processingIssay Meii
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C SurvivesS Akai
 
File Handling Program
File Handling ProgramFile Handling Program
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
S Akai
 
Why I love Python!
Why I love Python!Why I love Python!
Why I love Python!
Johannes Ridderstedt
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenics
Giorgio Cefaro
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial
Bhavik Patel
 
Bits, bytes and characters
Bits, bytes and charactersBits, bytes and characters
Bits, bytes and characters
Shaikhul Islam Chowdhury
 
JavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive dataJavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive data
Charlie Gracie
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015
Mark Baker
 

What's hot (20)

Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
 
Simple uses of ADRCI
Simple uses of ADRCISimple uses of ADRCI
Simple uses of ADRCI
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
 
Sample file processing
Sample file processingSample file processing
Sample file processing
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
 
File Handling Program
File Handling ProgramFile Handling Program
File Handling Program
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
 
Why I love Python!
Why I love Python!Why I love Python!
Why I love Python!
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenics
 
CLinkedList
CLinkedListCLinkedList
CLinkedList
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial
 
Bits, bytes and characters
Bits, bytes and charactersBits, bytes and characters
Bits, bytes and characters
 
JavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive dataJavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive data
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015
 

Similar to P5

Student Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final ProjectStudent Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final Project
Haqnawaz Ch
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
herminaherman
 
Programs of C++
Programs of C++Programs of C++
Railway reservation
Railway reservationRailway reservation
Railway reservation
Swarup Boro
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Institute management
Institute managementInstitute management
Institute management
varun arora
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
Santhiya S
 
File Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.pptFile Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.ppt
muhazamali0
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
inbox5
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
RAGAVIC2
 
Data structure
Data structureData structure
Data structure
Markustec
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
Sreedhar Chowdam
 
streams and files
 streams and files streams and files
streams and files
Mariam Butt
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and JavaAli MasudianPour
 
Usp
UspUsp
STL
STLSTL

Similar to P5 (20)

Student Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final ProjectStudent Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final Project
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
C program
C programC program
C program
 
Programs of C++
Programs of C++Programs of C++
Programs of C++
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Institute management
Institute managementInstitute management
Institute management
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
File Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.pptFile Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.ppt
 
20DCE096_prac8.pdf
20DCE096_prac8.pdf20DCE096_prac8.pdf
20DCE096_prac8.pdf
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
 
Data structure
Data structureData structure
Data structure
 
Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
streams and files
 streams and files streams and files
streams and files
 
Arp
ArpArp
Arp
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
Usp
UspUsp
Usp
 
STL
STLSTL
STL
 

Recently uploaded

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

P5

  • 1. #include<iostream> #include<stdio.h> #include<string.h> #include<fstream> #include<stdlib.h> #include<iomanip> //record specification using namespace std; fstream data,indx; char pri[125][15]; // to hold primary keys int ind[125],count=0; void sort1(); class student { public : char Regno[10], Name[25], Address[50], Sem[5], Branch[10], College[15]; public: void Insert(); void Delete(); void Search(char *a); /* To display individual record */ void Display();/* to display all records in file-- yet to implement*/ // void Loadindx(); void Writeindx(); }s; void student::Insert() { char Buffer[100],offset[10]; int pos, high = count; data.open("stu.txt",ios::app); data.seekg(0,ios::end); pos=data.tellg(); // gets the address of that posn cout<<"ENTER RECORD DETAILSn"; cout<<"RegNo : "; cin>>s.Regno; for(int low=0;low<=high;) { int mid = (low+high)/2; int k = atoi(pri[mid]), m = atoi(s.Regno); if(k == m) { cout<<setw(44)<<"DUPLICATE RECORD !!!"; return; } else if(m < k) high = mid-1; else if(m > k) low = mid + 1; } // to search for duplicate usn -- can avoid cout<<"Name : "; cin>>s.Name; cout<<"Address : "; cin>>s.Address; cout<<"Sem : "; cin>>s.Sem; cout<<"Branch : "; cin>>s.Branch; cout<<"College : "; cin>>s.College; sprintf(Buffer,"|%s|%s|%s|%s|%s|%s| #",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College); data<<Buffer;
  • 2. strcpy(pri[count],s.Regno); ind[count]=pos; count++; cout<<count; data.close(); s.Writeindx(); } void student::Writeindx() { char buffer[100]; int i; indx.open("inx.txt", ios::out); sort1(); for(i=0;i<count;i++) { //itoa(ind[i],buffer,10); sprintf(buffer, "%d", ind[i]); indx<<"|"<<pri[i]<<"|"<<buffer<<"|"<<"#"; } indx.close(); } void sort1() { char temp[20]; int tempind,k,i,j,l; for(i=0;i<count;i++) { for(j=i+1;j<count;j++) { k = atoi(pri[i]); l = atoi(pri[j]); if(k > l) { strcpy(temp,pri[i]); strcpy(pri[i],pri[j]); strcpy(pri[j],temp); tempind=ind[j]; ind[j]=ind[i]; ind[i]=tempind; } } } } void student::Search(char *reg) { int high = count,flag1=0; char Buffer[100]; data.open("stu.txt",ios::in); for(int low=0;low<=high;) { int mid = (low+high)/2; int k = atoi(pri[mid]), m = atoi(reg); if(k == m) // or else use strcmp()==0 { flag1 = 1; data.seekg(ind[mid],ios::beg); data.getline(Buffer,100,'#'); sscanf(Buffer,"|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|% [^|]#",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College); cout<<endl<<"RECORD DETAILS"<<endl; cout<<endl<<"URN : "<<s.Regno; cout<<endl<<"NAME : "<<s.Name; cout<<endl<<"ADDRESS : "<<s.Address; cout<<endl<<"SEMESTER : "<<s.Sem;
  • 3. cout<<endl<<"BRANCH : "<<s.Branch; cout<<endl<<"COLLEGE : "<<s.College<<"n"; data.close(); return; // or use break stmt here } else if(m < k) high = mid-1; else if(m > k) low = mid + 1; } if(flag1==0) cout<<endl<<"RECORD DOES NOT EXISTSn"; data.close(); } void student::Delete() { char reg[20],Buffer[100],usn[15]; int high = count,flag=0; cout<<endl<<"ENTER USN: "; cin>>reg; data.open("stu.txt",ios::in | ios::out); for(int low=0;low<=high;) { int mid = (low+high)/2; int k = atoi(pri[mid]), m = atoi(reg); if(k == m) { flag=1; data.seekg(ind[mid],ios::beg); data.getline(Buffer,100,'#'); Buffer[0]='*'; pri[mid][0]='*'; data.seekg(ind[mid],ios::beg); data<<Buffer; cout<<endl<<"RECORD DELETED"; data.close(); s.Writeindx(); return; } else if(m < k) high = mid-1; else if(m > k) low = mid + 1; } if(flag==0) { cout<<endl<<"RECORD NOT FOUND !!!"; } data.close(); } void student :: Display() { char Buffer[100]; data.open("stu.txt",ios::in); char b[100]; while(!data.eof()) { data.getline(Buffer,100,'#'); if(data.eof())
  • 4. break; if(Buffer[0]!='*') { sscanf(Buffer,"|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|% [^|]#",s.Regno,s.Name,s.Address,s.Sem,s.Branch,s.College); cout<<s.Regno<<" "<<s.Name<<" "<<s.Address<<" "<<s.Sem<<" "<<s.Branch<<" "<<s.College<<endl; } else continue; } data.close(); } int main() { fstream f1,f2; int choice; char usn[20]; for(;;) { cout<<"n1.Add record n2.search record n 3.deleterecordn4.display recordn"; cin>>choice; switch(choice) { case 1:s.Insert(); break; case 2:cout<<endl<<"ENTER UsN: "; cin>>usn; s.Search(usn); break; case 3:s.Delete(); break; case 4: s.Display(); break; default: exit(0); } } }