Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Summer, Year: 2021), B.Sc. in CSE (Day)

Course Title: Structured Programming Lab


Course Code: CSE 104 Section: 211DB

Lab Project Name: TRAIN RESERVATION SYSTEM

Student Details

Name ID
1. Md Kamruzzaman 211002062
2. Rafiul Islam 211002053
3. Bijoy Sarar 2110022002

Submission Date : 12-09-2021


Course Teacher’s Name :Ahmed Iqbal Pritom

[For Teachers use only: Don’t Write Anything inside this box]

Lab Project Status

Marks: ………………………………… Signature: .....................

Comments: .............................................. Date: ..............................


Table of Contents

Chapter 1 Introduction
1.1 Introduction
1.2 Design Goals/Objective

Chapter 2

Implementation of the Project


2.2 Implementations
2.3 Screen shots

Chapter 3 Conclusion
3.1 Learning Outcome
3.2 Future Scope

References

2 | Page
Chapter 1

Introduction

1.1 Introduction
Originally, C language is developed from two previous languages, BCPL and B. BCPL
which were developed in 1967 by Martin Richards as a language for writing operating
systems and compilers. C was evolved from B by Dennis Ritchie at Bell Laboratories and it
was implemented in 1972. It initially became widely known as the development language of
the UNIX operating system. Lots of today’s leading operating systems are written in C and
C++. C language is mostly hardware independent as it is possible to write C programs that
are portable to most computers.

Why we use C language C has been used successfully for every kind of programming
problem thinkable from operating systems to spreadsheets to expert systems - and efficient
compilers are accessible for machines ranging in power from the Apple Macintosh to the
Cray supercomputers. The largest measure of C's success appears to be based on strictly
sensible considerations:

1. The standard library concept;


2. the ease with that applications can be optimized by hand-coding isolated
procedures;
3. a powerful and varied repertoire of operators;
4. the portability of the compiler;

1.2 Design Goals/Objective

The goal of the project is to design an Train Reservation Systems:


This whole system is based on a concept to reserve train tickets of various destinations.Here,
as the program is executed, there’s a login system then the user has to choose between
reserving a ticket, viewing all the available trains and cancelling the reservation. By
choosing the reservation of the ticket, the user has to enter the name, number of tickets and
then choose by which train to travel according to their destination. Then the system will ask
for ticket confirmations. Users can also view a full list of all the trains available. After
reserving a ticket you can also cancel your reservation. This whole project is designed in ‘C’
Programming language & different variables and strings have been used for the
development. It is easy to operate and understand by the users.

3 | Page
Chapter 2
Implementation of the Project
1. Flow Charts

When the program is started, the user will direct to the main menu. The user will be required to select one of the four
options.

Figure1: Flow Chart of Main Menu

4 | Page
2. Implementation
C source code
3. //Train Reservation System.
4. #include<stdio.h>
5. #include<conio.h>
6. #include<stdlib.h>
7. #include<string.h>
8.
9.
10. typedef struct{
11. char name[50];
12. int train_num;
13. int num_of_seats;
14. }pd;
15.
16. void reservation(void);
17. void viewdetails(void);
18. void cancel(void);
19. void printticket(char name[],int,int,float);
20. void specifictrain(int);
21. float charge(int,int);
22. void login();
23.
24. int main()
25.
26.
27. {
28.
29.
30. login();
31. int menu_choice,choice_return;
32. start:
33. system("cls");
34. printf("\n=================================\n");
35. printf(" TRAIN RESERVATION SYSTEM");
36. printf("\n=================================");
37. printf("\n1>> Reserve A Ticket");
38. printf("\n------------------------");
39. printf("\n2>> View All Available Trains");
40. printf("\n------------------------");
41. printf("\n3>> Cancel Reservation");
42. printf("\n------------------------");
43. printf("\n4>> Exit");
44. printf("\n------------------------");
45. printf("\n\n-->");
46. scanf("%d",&menu_choice);
47. switch(menu_choice)
48. {
49. case 1:
50. reservation();
51. break;
52. case 2:
53. viewdetails();
54. printf("\n\nPress any key to go to Main Menu..");
55. getch();
5 | Page
56. break;
57. case 3:
58. cancel();
59. break;
60. case 4:
61. return(0);
62. default:
63. printf("\nInvalid choice");
64. }
65. goto start;
66. return(0);
67. }
68.
69.
70. /
*********************************************VIEWDETAILS()******************************
*******************/
71.
72. void viewdetails(void)
73. {
74. system("cls");
75.
printf("-----------------------------------------------------------------------------");
76. printf("\nTr.No\tName\t\t\tDestinations\t\tCharges\t\tTime\n");
77.
printf("-----------------------------------------------------------------------------");
78. printf("\n7001\tSubarna Express\t\tChittagong to Dhaka\tTK.400\t\t6.40am");
79. printf("\n7002\tAkota Express\t\tDhaka to Dinajpur\tTK.550\t\t10am");
80. printf("\n7003\tparabat Express\t\tDhaka to sylhet\t\tTk.500\t\t6.40am");
81. printf("\n7004\tRangpur Express\t\tRangpur to Dhaka\tTk.500\t\t8am");
82. printf("\n7005\tNilsagor Express\tNiphamari to Dhaka\tTk.500\t\t9pm");
83. printf("\n7006\tUpukol Express\t\tNoakhali to Dhaka\tTk.400\t\t6.20am");
84. printf("\n7007\tMeghna Express\t\tChandpur to Chitagong\tTk.500\t\t5am");
85. printf("\n7008\tDolonchapa Express\tSantahar to Dinajpur\tTk.200\t\t5.40");
86. printf("\n7009\tTista Express\t\tDhaka to Dewangonj\tTk.500\t\t7.20am");
87. printf("\n7010\tLalmoni Express\t\tDhaka to Lalmonirhat\tTk.550\t\t8.10pm");
88.
89.
90. }
91.
92.
93. /
*********************************************RESERVATION()******************************
*******************/
94.
95.
96. void reservation(void)
97. {
98. char confirm;
99. int i=0;
100. float charges;
101. pd passdetails;
102. FILE *fp;
103. fp=fopen("seats_reserved.txt","a");
104. system("cls");
105.
106.
107. printf("\nEnter Your Name:> ");
108. fflush(stdin);
109. gets(passdetails.name);
110. printf("\nEnter Number of seats:> ");
111. scanf("%d",&passdetails.num_of_seats);
112. printf("\n\n>>Press Enter To View Available Trains<< ");
113. getch();
114. system("cls");
115. viewdetails();

6 | Page
116. printf("\n\nEnter train number:> ");
117. start1:
118. scanf("%d",&passdetails.train_num);
119. if(passdetails.train_num>=7001 && passdetails.train_num<=7010)
120. {
121. charges=charge(passdetails.train_num,passdetails.num_of_seats);
122.
printticket(passdetails.name,passdetails.num_of_seats,passdetails.train_num,charges);
123. }
124. else
125. {
126. printf("\nInvalid train Number! Enter again--> ");
127. goto start1;
128. }
129.
130.
131. printf("\n\nConfirm Ticket (y/n):>");
132. start:
133. scanf(" %c",&confirm);
134. if(confirm == 'y')
135. {
136. fprintf(fp,"%s\t\t%d\t\t%d\t\t%.2f\
n",&passdetails.name,passdetails.num_of_seats,passdetails.train_num,charges);
137. printf("==================");
138. printf("\n Reservation Done\n");
139. printf("==================");
140. printf("\nPress any key to go back to Main menu");
141. }
142. else
143. {
144. if(confirm=='n'){
145. printf("\nReservation Not Done!\nPress any key to go back to
Main menu!");
146. }
147. else
148. {
149. printf("\nInvalid choice entered! Enter again-----> ");
150. goto start;
151. }
152. }
153. fclose(fp);
154. getch();
155. }
156.
157.
158. /
*********************************************CHARGE()***********************************
**************/
159.
160.
161. float charge(int train_num,int num_of_seats)
162. {
163. if (train_num==7001)
164. {
165. return(400.0*num_of_seats);
166. }
167. if (train_num==7002)
168. {
169. return(550.0*num_of_seats);
170. }
171. if (train_num==7003)
172. {
173. return(500.0*num_of_seats);
174. }
175. if (train_num==7004)
176. {

7 | Page
177. return(500.0*num_of_seats);
178. }
179. if (train_num==7005)
180. {
181. return(500.0*num_of_seats);
182. }
183. if (train_num==1006)
184. {
185. return(400.0*num_of_seats);
186. }
187. if (train_num==7007)
188. {
189. return(500.0*num_of_seats);
190. }
191. if (train_num==7008)
192. {
193. return(200.0*num_of_seats);
194. }
195. if (train_num==7009)
196. {
197. return(500.0*num_of_seats);
198. }
199. if (train_num==7010)
200. {
201. return(550.0*num_of_seats);
202. }
203. }
204.
205.
206. /
*********************************************PRINTTICKET()******************************
*******************/
207.
208.
209. void printticket(char name[],int num_of_seats,int train_num,float charges)
210. {
211. system("cls");
212. printf("-------------------\n");
213. printf("\tTICKET\n");
214. printf("-------------------\n\n");
215. printf("Name:\t\t\t%s",name);
216. printf("\nNumber Of Seats:\t%d",num_of_seats);
217. printf("\nTrain Number:\t\t%d",train_num);
218. specifictrain(train_num);
219. printf("\nCharges:\t\t%.2f",charges);
220. }
221.
222.
223. /
*********************************************SPECIFICTRAIN()****************************
*********************/
224.
225.
226. void specifictrain(int train_num)
227. {
228.
229.
230. if (train_num==7001)
231. {
232. printf("\nTrain:\t\t\tSubarna Express");
233. printf("\nDestination:\t\t Chittagong to Dhaka");
234. printf("\nDeparture:\t\t6.40am ");
235. }
236. if (train_num==7002)
237. {
238. printf("\nTrain:\t\t\tAkota Express");

8 | Page
239. printf("\nDestination:\t\tDhaka");
240. printf("\nDeparture:\t\t10am");
241. }
242. if (train_num==7003)
243. {
244. printf("\nTrain:\t\t\tparabat Express");
245. printf("\nDestination:\t\tDhaka to Sylhet");
246. printf("\nDeparture:\t\t6.40am");
247. }
248. if (train_num==7004)
249. {
250. printf("\nTrain:\t\t\tRangpur Express");
251. printf("\nDestination:\t\tDhaka to Rangpur");
252. printf("\nDeparture:\t\t8am ");
253. }
254. if (train_num==7005)
255. {
256. printf("\nTrain:\t\t\tNilsagor Express");
257. printf("\nDestination:\t\tNilphamari to Dhaka");
258. printf("\nDeparture:\t\t9pm");
259. }
260. if (train_num==7006)
261. {
262. printf("\ntrain:\t\t\tUpukol Express");
263. printf("\nDestination:\t\tNoakhali to Dhaka");
264. printf("\nDeparture:\t\t6.20am ");
265. }
266. if (train_num==7007)
267. {
268. printf("\ntrain:\t\t\tmeghna Express");
269. printf("\nDestination:\t\tChandpur to Chittagong");
270. printf("\nDeparture:\t\t5am ");
271. }
272. if (train_num==7008)
273. {
274. printf("\ntrain:\t\t\tDolonchapa Express");
275. printf("\n Destination:\t\tSantahar to Dinajpur");
276. printf("\nDeparture:\t\t5.40am ");
277. }
278. if (train_num==7009)
279. {
280. printf("\ntrain:\t\t\tTista Express");
281. printf("\nDestination:\t\tDhaka to Dewangonj");
282. printf("\nDeparture:\t\t7.20am ");
283. }
284. if (train_num==7010)
285. {
286. printf("\ntrain:\t\t\tLalmoni Express");
287. printf("\nDestination:\t\tLalmonirhat to Dhaka");
288. printf("\nDeparture:\t\t8.10pm ");
289. }
290. }
291.
292.
293. void login()
294. {
295. int a=0,i=0;
296. char uname[10],c=' ';
297. char pword[10],code[10];
298. char user[10]="user";
299. char pass[10]="pass";
300. do
301. {
302.
303.
304. printf("\n ======================= LOGIN FORM =======================\n ");

9 | Page
305. printf(" \n ENTER USERNAME:-");
306. scanf("%s", &uname);
307. printf(" \n ENTER PASSWORD:-");
308. while(i<10)
309. {
310. pword[i]=getch();
311. c=pword[i];
312. if(c==13) break;
313. else printf("*");
314. i++;
315. }
316. pword[i]='\0';
317. i=0;
318. if(strcmp(uname,"KBR")==0 && strcmp(pword,"pass")==0)
319. {
320. printf(" \n\n\n WELCOME TO BD TRAIN SERVICE !! YOUR LOGIN IS
SUCCESSFUL");
321. printf("\n\n\n\t\t\t\tPress any key to continue...");
322. getch();
323. break;
324. }
325. else
326. {
327. printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL TRY AGAIN….!!");
328. a++;
329.
330.
331. getch();
332. system("cls");
333. }
334. }
335. while(a<=2);
336. if (a>2)
337. {
338. printf("\nSorry you have entered the wrong username and password for
four times!!!");
339.
340.
341. getch();
342.
343.
344. }
345. system("cls");
346. }
347.
348.
349. void cancel(void)
350. {
351.
352.
353. system("cls");
354. int trainnum;
355. printf("-----------------------\n");
356. printf("Enter the train number: \n");
357. printf("-----------------------\n");
358. fflush(stdin);
359. scanf("%i",&trainnum);
360. printf("\n\nCancelled");
361. getch();
362. }
363.
364.
365.
366.
367.
368.

10 | Page
Screenshots

Figure 1: login form interface

When the program is executed, the user will be directed to the main menu interface. The program is introduced with a
Login Form. Then input enter username and password for Login into the main menu.

Figure 2: Invalid value entered (login form)

. If the user accidentally enters an invalid username or password, an interface will be shown to notify the user to
SORRY!!! LOGIN IS UNSUCCESSFUL. TRY AGAIN….!!

Figure 3: LOGIN FORM (ENTER WRONG INPUT FOUR TIME)

11 | Page
If a user logs 4 times with the wrong username and password, then it will notify him/ her-Sorry you have entered the
wrong username and password for four times!!!

Figure 4-5:After successfully enter username and password

As shown in the interface, “welcome to BD train service, your login is successful” after the user has entered the main
menu.

12 | Page
Figure 6: to reserve a ticket.

to reserve a ticket just reply 1 and it will go to this interface . then users can easily go to train details by
input their name and seat name.

Figure 7: Details of all trains, schedule and time.

customers can view all the available train and train destinations. so they can easily pick up a ticket for their journey.

13 | Page
After choosing a train, the user should input the train number to go to the next step. a passenger can book a
train ticket by input train number and follow the next step.

Figure 8: details of train, destination, charge

The system will show all the details of the train. for confirm the ticket just type “y/yes” otherwise “n”.

14 | Page
Figure 8: after successfully booking a ticket

15 | Page
Figure 9:after cancel journey

After the passenger entered n/no it will notify them with this interface.

16 | Page
Figure 10: Details of all trains.

Passengers can also check all available trains and details of all trains . such as journey time, ticket price, destination,
train number. so they can book a ticket by train number from the reservation section. They can also see the all
available train.

Figure 11: cancel ticket


Passengers can also cancel train tickets. simply inter train number , ticket will be cancelled.

17 | Page
Figure 12: Exit

passengers can exit by using the exit menubar.

Chapter 3

Conclusion

Learning Outcome

18 | Page
Future Scope
● We can use graph theory to include route map in this project
● We can add database to our project to store all employee and passenger information of the Airlines system.

References
[1] Author Initial. Author Surname, Title. City: Publisher, Year Published, p. Pages
Used.

[2] A. Rezi and M. Allam, ”Techniques in array processing by means of transforma-


tions, ” in Control and Dynamic Systems, Vol. 69, Multidemsional Systems, C. T.
Leondes, Ed. San Diego: Academic Press, 1995, pp. 133-180.

[3] O. B. R. Strimpel, ”Computer graphics,” in McGraw-Hill Encyclopedia of Science


and Technology, 8th ed., Vol. 4. New York: McGraw-Hill, 1997, pp. 279-283.

[4] K. Schwalbe, Information Technology Project Management, 3rd ed. Boston: Course
Technology, 2004.

19 | Page

You might also like