diff --git a/lp2/README.md b/lp2/README.md index e69de29..82e28ac 100644 --- a/lp2/README.md +++ b/lp2/README.md @@ -0,0 +1,134 @@ +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +1 + +Enter URN => 1 + +Enter name => 1 + +Enter Sem => 1 + +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +1 + +Enter URN => 2 + +Enter name => 2 + +Enter Sem => 2 + +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +2 + +Enter the URN to be searched => 1 + +Record found + +Student URN1 + + + Name:1 + + Sem:1Enter your choice + +URN => 1 + +1.Name => 1 + +2.Sem => 1 + +3.Exit + +Enter your choice(1,2,3)1 + +Enter new name => Avinash + +Enter your choice + +URN => 1 + +1.Name => Avinash + +2.Sem => 1 + +3.Exit + +Enter your choice(1,2,3)3 + +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +1 + +Enter URN => 16 + +Enter name => Avi + +Enter Sem => 6 + +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +2 + +Enter the URN to be searched => 16 + +Record found + +Student URN16 + + Name:Avi + + Sem:6Enter your choice + +URN => 16 + +1.Name => Avi + +2.Sem => 6 + +3.Exit + +Enter your choice(1,2,3)3 + +Enter your choice + +1.Insert + +2.Search and Modify + +3.Exit + +3 + + diff --git a/lp2/p2.cpp b/lp2/p2.cpp new file mode 100644 index 0000000..9bbaadc --- /dev/null +++ b/lp2/p2.cpp @@ -0,0 +1,179 @@ +#include +#include +#include +#include +using namespace std; + +void search(); + +class Student +{ + public: + string urn; + string name; + string sem; + string Buf; + char buf[46]; + int pack(); + void write_f(fstream &); + void unpack(); + void print(ostream &); + void read_f(fstream &); +}; + +int Student::pack() +{ + + Buf=urn+"|"+name+"|"+sem+"|"; + if(Buf.length()>45) + return 0; + while(Buf.length()<45) + Buf+="_"; + Buf+="\0"; + return 1; +} + +void Student::write_f(fstream &fp) +{ + fp.flush(); + fp<>ch; + switch(ch) + { + case 1: fp.open("in.txt",ios::out | ios::app); + cout<<"Enter URN => "; + cin>>s.urn; + cout<<"Enter name => "; + cin>>s.name; + cout<<"Enter Sem => "; + cin>>s.sem; + int k ; + k = s.pack(); + if(k==0) + { + cout<<"Invalid data\n"; + } + else + s.write_f(fp); + fp.close(); + break; + case 2: search(); + break; + case 3: exit(1); + } + } + while(ch<=3); + + return 0; +} + +void search() +{ + int c=0,choice; + string usn; + Student s[1100]; + fstream fp1; + fp1.open("in.txt",ios::in); + cout<<"Enter the URN to be searched => "; + cin>>usn; + int cnt=0; + int i=0; + while(fp1) + { + s[i].read_f(fp1); + s[i].unpack(); + i++; + } + fp1.close(); + cnt=i-1; + for(i=0;i "< "< "<>choice; + switch(choice) + { + case 1: cout<<"Enter new name => "; + cin>>s[i].name; + break; + case 2: cout<<"Enter new sem => "; + cin>>s[i].sem; + break; + case 3: break; + default: cout<<"Wrong choice, please enter a valid choice\n"; + } + } + while(choice!=3); + fp1.open("in.txt",ios::out); + for(i=0;i