Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit e7cf879

Browse files
committed
files added
1 parent 3287bec commit e7cf879

File tree

2 files changed

+313
-0
lines changed

2 files changed

+313
-0
lines changed

lp2/README.md

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
Enter your choice
2+
3+
1.Insert
4+
5+
2.Search and Modify
6+
7+
3.Exit
8+
9+
1
10+
11+
Enter URN => 1
12+
13+
Enter name => 1
14+
15+
Enter Sem => 1
16+
17+
Enter your choice
18+
19+
1.Insert
20+
21+
2.Search and Modify
22+
23+
3.Exit
24+
25+
1
26+
27+
Enter URN => 2
28+
29+
Enter name => 2
30+
31+
Enter Sem => 2
32+
33+
Enter your choice
34+
35+
1.Insert
36+
37+
2.Search and Modify
38+
39+
3.Exit
40+
41+
2
42+
43+
Enter the URN to be searched => 1
44+
45+
Record found
46+
47+
Student URN1
48+
49+
50+
Name:1
51+
52+
Sem:1Enter your choice
53+
54+
URN => 1
55+
56+
1.Name => 1
57+
58+
2.Sem => 1
59+
60+
3.Exit
61+
62+
Enter your choice(1,2,3)1
63+
64+
Enter new name => Avinash
65+
66+
Enter your choice
67+
68+
URN => 1
69+
70+
1.Name => Avinash
71+
72+
2.Sem => 1
73+
74+
3.Exit
75+
76+
Enter your choice(1,2,3)3
77+
78+
Enter your choice
79+
80+
1.Insert
81+
82+
2.Search and Modify
83+
84+
3.Exit
85+
86+
1
87+
88+
Enter URN => 16
89+
90+
Enter name => Avi
91+
92+
Enter Sem => 6
93+
94+
Enter your choice
95+
96+
1.Insert
97+
98+
2.Search and Modify
99+
100+
3.Exit
101+
102+
2
103+
104+
Enter the URN to be searched => 16
105+
106+
Record found
107+
108+
Student URN16
109+
110+
Name:Avi
111+
112+
Sem:6Enter your choice
113+
114+
URN => 16
115+
116+
1.Name => Avi
117+
118+
2.Sem => 6
119+
120+
3.Exit
121+
122+
Enter your choice(1,2,3)3
123+
124+
Enter your choice
125+
126+
1.Insert
127+
128+
2.Search and Modify
129+
130+
3.Exit
131+
132+
3
133+
134+

lp2/p2.cpp

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#include<iostream>
2+
#include<string>
3+
#include<fstream>
4+
#include<cstring>
5+
using namespace std;
6+
7+
void search();
8+
9+
class Student
10+
{
11+
public:
12+
string urn;
13+
string name;
14+
string sem;
15+
string Buf;
16+
char buf[46];
17+
int pack();
18+
void write_f(fstream &);
19+
void unpack();
20+
void print(ostream &);
21+
void read_f(fstream &);
22+
};
23+
24+
int Student::pack()
25+
{
26+
27+
Buf=urn+"|"+name+"|"+sem+"|";
28+
if(Buf.length()>45)
29+
return 0;
30+
while(Buf.length()<45)
31+
Buf+="_";
32+
Buf+="\0";
33+
return 1;
34+
}
35+
36+
void Student::write_f(fstream &fp)
37+
{
38+
fp.flush();
39+
fp<<Buf<<'\n';
40+
fp.flush();
41+
}
42+
43+
void Student::print(ostream & stream)
44+
{
45+
stream<<"Student"<<"\t URN"<<urn<<"\n"<<"\t Name:"<<name<<"\n\t Sem:"<<sem;
46+
}
47+
void Student::unpack()
48+
{
49+
char stg[100];
50+
int pos=0,count=0,k;
51+
while(count<3)
52+
{
53+
k=0;
54+
for(int i=pos;i<strlen(buf);i++,k++)
55+
{
56+
stg[k]=buf[i];
57+
pos++;
58+
if(buf[i]=='|')
59+
break;
60+
}
61+
stg[k]='\0';
62+
count++;
63+
if(count==1)urn=stg;
64+
if(count==2)name=stg;
65+
if(count==3)sem=stg;
66+
}
67+
}
68+
69+
void Student:: read_f(fstream &fp)
70+
{
71+
char sg[55];
72+
fp.getline(buf,46,'_');
73+
fp.getline(sg,50,'\n');
74+
}
75+
76+
int main()
77+
{
78+
int ch,x;
79+
Student s;
80+
fstream fp;
81+
do
82+
{
83+
cout<<"Enter your choice\n";
84+
cout<<"1.Insert\n2.Search and Modify\n3.Exit\n";
85+
cin>>ch;
86+
switch(ch)
87+
{
88+
case 1: fp.open("in.txt",ios::out | ios::app);
89+
cout<<"Enter URN => ";
90+
cin>>s.urn;
91+
cout<<"Enter name => ";
92+
cin>>s.name;
93+
cout<<"Enter Sem => ";
94+
cin>>s.sem;
95+
int k ;
96+
k = s.pack();
97+
if(k==0)
98+
{
99+
cout<<"Invalid data\n";
100+
}
101+
else
102+
s.write_f(fp);
103+
fp.close();
104+
break;
105+
case 2: search();
106+
break;
107+
case 3: exit(1);
108+
}
109+
}
110+
while(ch<=3);
111+
112+
return 0;
113+
}
114+
115+
void search()
116+
{
117+
int c=0,choice;
118+
string usn;
119+
Student s[1100];
120+
fstream fp1;
121+
fp1.open("in.txt",ios::in);
122+
cout<<"Enter the URN to be searched => ";
123+
cin>>usn;
124+
int cnt=0;
125+
int i=0;
126+
while(fp1)
127+
{
128+
s[i].read_f(fp1);
129+
s[i].unpack();
130+
i++;
131+
}
132+
fp1.close();
133+
cnt=i-1;
134+
for(i=0;i<cnt;i++)
135+
{
136+
if(s[i].urn==usn)
137+
{
138+
c++;
139+
break;
140+
}
141+
}
142+
if(c==0)
143+
{
144+
cout<<"Record not found\n";
145+
return;
146+
}
147+
else
148+
{
149+
cout<<"Record found\n";
150+
s[i].print(cout);
151+
do
152+
{
153+
cout<<"Enter your choice\n";
154+
cout<<"URN => "<<s[i].urn<<"\n";
155+
cout<<"1.Name => "<<s[i].name<<"\n2.Sem => "<<s[i].sem<<"\n3.Exit\n";
156+
cout<<"Enter your choice(1,2,3)";
157+
cin>>choice;
158+
switch(choice)
159+
{
160+
case 1: cout<<"Enter new name => ";
161+
cin>>s[i].name;
162+
break;
163+
case 2: cout<<"Enter new sem => ";
164+
cin>>s[i].sem;
165+
break;
166+
case 3: break;
167+
default: cout<<"Wrong choice, please enter a valid choice\n";
168+
}
169+
}
170+
while(choice!=3);
171+
fp1.open("in.txt",ios::out);
172+
for(i=0;i<cnt;i++)
173+
{
174+
s[i].pack();
175+
s[i].write_f(fp1);
176+
}
177+
fp1.close();
178+
}
179+
}

0 commit comments

Comments
 (0)