SlideShare a Scribd company logo
1 of 4
#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 CresineMovel
 
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 itFlavien 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éesRomain Lecomte
 
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 20160723kamiyam .
 
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
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門S Akai
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenicsGiorgio Cefaro
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial Bhavik Patel
 
JavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive dataJavaOne 2016 - JVM assisted sensitive data
JavaOne 2016 - JVM assisted sensitive dataCharlie Gracie
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015Mark 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 ProjectHaqnawaz 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 .pdfherminaherman
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Railway reservation
Railway reservationRailway reservation
Railway reservationSwarup Boro
 
Institute management
Institute managementInstitute management
Institute managementvarun arora
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 
#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.pdfinbox5
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptxRAGAVIC2
 
Data structure
Data structureData structure
Data structureMarkustec
 
streams and files
 streams and files streams and files
streams and filesMariam 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
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 

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++
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
Institute management
Institute managementInstitute management
Institute management
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
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
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 

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); } } }