help in search/edit/delete in text file(urgent)

can any one help me solve this problem?i had no idea to solve it!!!and need it fast....my search function cannot use....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include <iostream>                       
#include <fstream>                        
#include<cctype>
#include<iomanip>
#include <windows.h>
#include <cstring>
using namespace std;


class customer
{
    protected:
    protected:
	int uchoice;
	bool done;
	string date;
	int time;
	char from;
	char to;
	int passenger;
	double price;
	char choicebuy;
	string name;
	string ic;
	string handphone;
	string email;

public:
	void userMenu()
    {
    system("cls");
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |      ^^Express Bus Ticketing System^^       |" << endl;
    cout << "                |=============================================|" << endl;
    cout << "                | Welcome user!!! All ticket sold are RM22!!! |" << endl;
    cout << "                |                                             |" << endl;
    cout << "                | Select:                                     |" << endl;
    cout << "                | 1 => Customer                               |" << endl;
    cout << "                | 2 => Administrater                          |" << endl;
    cout << "                | 3 => Exit                                   |" << endl;
    cout << "                |                                             |" << endl;
    cout << "                | Request/info/feedback: expressbus@gmail.com |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << endl;
    cout << "Choice => ";

}

	void getticket()
	{
    system("cls");
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |    Welcome!!! All ticket sold are RM22!!!   |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |        Places        |         Time         |" << endl;
    cout << "                |=============================================|" << endl;
    cout << "                |  A => Johor Bahru    |  1 => 8.00  a.m.     |" << endl;
    cout << "                |  B => Kuala Lumpur   |  2 => 10.30 a.m.     |" << endl;
    cout << "                |  C => Melaka         |  3 => 1.00  p.m.     |" << endl;
    cout << "                |  D => Seremban       |  4 => 3.00  p.m.     |" << endl;
    cout << "                |  E => Kuantan        |  5 => 6.00  p.m.     |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << endl;
	cout<<"Date(dd/mm/yy):";
	cin>> date;

	aa:
	cout<<"Time:";
	cin>>time;
	if(time==1 || time == 2 || time == 3 || time == 4 || time == 5)
	goto bb;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto aa;
	}

	bb:
	cout<<"From:";
	cin>>from;
	from=toupper(from);
	if (from=='A' || from == 'B' || from == 'C' || from == 'D' || from == 'E')
    goto cc;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto bb;
	}

	cc:
	cout<<"To:";
    cin>>to;
    to=toupper(to);
	if ( to =='A' || to == 'B' || to == 'C' || to == 'D' || to == 'E')
    goto dd;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto cc;
	}

	dd:
	cout<<"Passenger:";
	cin>>passenger;
	price=passenger*22;
	cout<<"Price:RM"<<price<<endl;
	cout<<"Confirm?(y/n):";
			cin>>choicebuy;
			switch(choicebuy)
			{
				case 'y':getInfo();
						 break;
				case 'n':userMenu();
						 break;
				default:cout<<"Invalid. Please choose again."<<endl;
						break;
			}
	}
	virtual void getInfo()
	{
	cout<<"\nName:";
	cin>> name;
	cout<<"IC no:";
	cin>>ic;
	cout<<"Handphone:";
	cin>>handphone;
	cout<<"Email:";
	cin>>email;
	cout<<"Thank you. You can get your ticket(s) at our counter at any bus station by providing your IC no."<< endl;
	system("PAUSE");
	}
};


class admin:public customer
{
protected:
   int adchoice;
   string username;
   string password;
   string ic;

public:
	string retic() const;
    void show_record(string) const;
    void modify_record();
};


string admin::retic() const
{
	return ic;
}

void admin::show_record(string) const
{
	system("cls");
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |    Welcome!!! All ticket sold are RM22!!!   |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |        Places        |         Time         |" << endl;
    cout << "                |=============================================|" << endl;
    cout << "                |  A => Johor Bahru    |  1 => 8.00  a.m.     |" << endl;
    cout << "                |  B => Kuala Lumpur   |  2 => 10.30 a.m.     |" << endl;
    cout << "                |  C => Melaka         |  3 => 1.00  p.m.     |" << endl;
    cout << "                |  D => Seremban       |  4 => 3.00  p.m.     |" << endl;
    cout << "                |  E => Kuantan        |  5 => 6.00  p.m.     |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << endl;
	cout<<"\nIC no: "<<ic;
	cout<<"\nName: "<<name;
	cout<<"\nHandphone: "<<handphone;
	cout<<"\nEmail: "<<email;
	cout<<"\nDate(dd/mm/yy): "<<date;
	cout<<"\nTime: "<<time;
	cout<<"\nFrom: "<<from;
	cout<<"\nTo: "<<to;
	cout<<"\nPassenger: "<<passenger;
	cout<<"\nPrice: RM"<<price;
}

void admin::modify_record()
{
	system("cls");
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |    Welcome!!! All ticket sold are RM22!!!   |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |	      Places	    |         Time         |" << endl;
    cout << "                |=============================================|" << endl;
    cout << "		         |	A => Johor Bahru    |  1 => 8.00  a.m.     |" << endl;
    cout << "		         |	B => Kuala Lumpur   |  2 => 10.30 a.m.     |" << endl;
    cout << "		         |	C => Melaka         |  3 => 1.00  p.m.     |" << endl;
    cout << "		         |	D => Seremban       |  4 => 3.00  p.m.     |" << endl;
    cout << "	             |	E => Kuantan        |  5 => 6.00  p.m.     |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << endl;
	cout<<"\nIC no: "<<ic;
	cout<<"\nName: "<<name;
	cout<<"\nHandphone: ";
	cin>>handphone;
	cout<<"\nEmail: ";
	cin>>email;
	cout<<"\nDate(dd/mm/yy): ";
	cin>>date;

	aa:
	cout<<"Time:";
	cin>>time;
	if(time==1 || time == 2 || time == 3 || time == 4 || time == 5)
	goto bb;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto aa;
	}

	bb:
	cout<<"From:";
    cin>>from;
	from=toupper(from);
	if (from=='A' || from == 'B' || from == 'C' || from == 'D' || from =='E')
    goto cc;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto bb;
	}

	cc:
	cout<<"To:";
	cin>>to;
	to=toupper(to);
	if ( to =='A' || to == 'B' || to == 'C' || to == 'D' || to == 'E')
    goto dd;
	else
	{
	   cout << "Invalid, try again!" << endl;
	   system("pause>nul");
       goto cc;
	}

	dd:
	cout<<"\nPassenger: ";
	cin>>passenger;
	price=passenger*22;
	cout<<"\nPrice: RM"<<price;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
void adminMenu();
void write_ticketinfo();
void searchRecord(string n);
void editRecord(string n);
void deleteRecord(string n);

int main()
{
customer u;
int uchoice;
bool done;
    do
    {
        u.userMenu();                        //calling the displayMenu function
        cin >> uchoice;                        //user input for choice
        switch (uchoice)                       //choice selection to proceed to the rest of the program
        {
            case 1 :   write_ticketinfo();
                       break;
            case 2 :   adminMenu();
                       break;
            case 3 :   done = true;
                       break;
            default :  cout << "Invalid selection, try again!" << endl;
                       system("pause>nul");
        }
    } while (!done);
    cout << "Good Bye!" << endl;
    cout << endl;
	system("pause>nul");                                               // to pause the system without showing Press any key message
	return 0;
}



void adminMenu()
{
	string num;
	int adchoice;
	bool done02;
	string ic;
do
	{
    system("cls");
    cout << "                +---------------------------------------------+" << endl;
    cout << "                |      ^^Express Bus Ticketing System^^       |" << endl;
    cout << "                |=============================================|" << endl;
    cout << "                | Administrater control panel                 |" << endl;
    cout << "                |                                             |" << endl;
    cout << "                | Select:                                     |" << endl;
    cout << "                | 1 => Add Record                             |" << endl;
    cout << "                | 2 => Search Record                          |" << endl;
    cout << "                | 3 => Edit Record                            |" << endl;
    cout << "                | 4 => Delete Record                          |" << endl;
    cout << "                | 5 => Exit                                   |" << endl;
    cout << "                |                                             |" << endl;
    cout << "                | Request/info/feedback: expressbus@gmail.com |" << endl;
    cout << "                +---------------------------------------------+" << endl;
    cout << endl;
    cout << "Choice => ";
    cin >> adchoice;                        //user input for choice
        switch (adchoice)                       //choice selection to proceed to the rest of the program
        {
            case 1 :   write_ticketinfo();
                       break;
            case 2 :   cout<<"Enter IC no: ";
            	       cin>>ic;
					   searchRecord(num);
            		   break;
            case 3 :   cout<<"Enter IC no: ";
                       cin>>ic;
					   editRecord(num);
            		   break;
            case 4 :   cout<<"Enter IC no: ";
					   deleteRecord(num);
            	       break;
            case 5 :   done02 = true;
                       break;
            default :  cout << "Invalid selection, try again!" << endl;
                       system("pause>nul");
        }
    } while (!done02);
    cout << "Good Bye!" << endl;
    cout << endl;
	system("pause>nul");                                               // to pause the system without showing Press any key message
	return ;
}


void write_ticketinfo()
{
    customer rc;

	ofstream outFile;
	outFile.open("record.dat",ios::app);
	rc.getticket();
	outFile.close();

}


void searchRecord(string n)
{
    admin rc;
	bool flag=false;
	ifstream inFile;
	inFile.open("record.dat");
	if(!inFile)
	{
		cout<<"Not exist !! Press any Key...";
		return;
	}
    	cout<<"\nCUSTOMER DETAILS\n";
    	while(inFile.read(reinterpret_cast<char *> (&rc), sizeof(admin)))
	{
		if(rc.retic()==n)
		{
			rc.show_record(n);
			flag=true;
		}
	}
    inFile.close();
	if(flag==false)
		cout<<"\n\nNot exist";
}

void editRecord(string n)
{
	admin rc;
	bool found=false;

	fstream File;
    File.open("record.dat",ios::in|ios::out);
	if(!File)
	{
		cout<<"Not exist !! Press any Key...";
		return;
	}
	while(!File.eof() && found==false)
	{
		File.read(reinterpret_cast<char *> (&rc), sizeof(admin));
		if(rc.retic()==n)
		{
			rc.show_record(n);
			cout<<"\n\nEnter The new details:"<<endl;
			rc.modify_record();
			int pos=(-1)*static_cast<int>(sizeof(admin));
			File.seekp(pos,ios::cur);
		    File.write(reinterpret_cast<char *> (&rc), sizeof(admin));
		    cout<<"\n\n\t Record Updated";
		    found=true;
		  }
	}
	File.close();
	if(found==false)
		cout<<"\n\n Record Not Found ";
}

void deleteRecord(string n)
{
    admin rc;
	ifstream inFile;
	ofstream outFile;
	inFile.open("record.dat");
	if(!inFile)
	{
		cout<<"Not exist !! Press any Key...";
		return;
	}
	outFile.open("Temp.dat");
	inFile.seekg(0,ios::beg);
	while(inFile.read(reinterpret_cast<char *> (&rc), sizeof(admin)))
	{
		if(rc.retic()!=n)
		{
			outFile.write(reinterpret_cast<char *> (&rc), sizeof(admin));
		}
	}
    inFile.close();
	outFile.close();
	remove("record.dat");
	rename("Temp.dat","record.dat");
	cout<<"\n\n\tRecord Deleted ..";
}
Last edited on
the above comment is the continue of the program!Can anyone help me solve it?why my search function cannot use??
Last edited on
Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

can any one help me solve this problem?i had no idea to solve it!!!and need it fast....

Were you planning on telling us what the problem is? Or are you only looking for help from the telepathic members of this forum?

Last edited on
ok done edit
Topic archived. No new replies allowed.