C Programming Reportmufti
C Programming Reportmufti
CT018-3-1-ICP
Table of Contents
Page 2 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Acknowledgments
Firstly, Thank You miss for everything. Secondly, we would like to thank our esteemed
university under whose roof we have studied and completed our tasks, without which we would
stand nowhere. Many thanks to our wonderful lecturer, Supriya Singh for guiding us with clear
instructions and always gave constructive feedback. Her involvement in this assignment to help
us out in any issues with regarding to the coding and techniques to write this report resulted in to
this beautifully presented work. However, we would like to thank our parents who have been
consistently supporting us and acting as a backbone of our success. The list cannot be completed
unless we say thanks to our friends who spent their important time for standing beside us
whenever we needed help for our project or even just to cheer us up. They kept supporting us
Page 3 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Introduction
Why we use c language C has been used successfully for each 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:
the ease with that applications can be optimized by hand-coding isolated procedures;
Page 4 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Assumptions
A small airline has just purchased a computer for its new automated reservation system.
The owner has asked to program the new system in C. It is required to write a program to
assign seats on each flight of the airlines only place (capacity: 15 seats). The program
should never assign a seat which is already assigned. If there’s no seat available, then print
the message " the flight is full ".
After the flight is full and someone want to cancel the booking, it is displaying enter you’re
the passport number you want to cancel it so after the passenger cancel it, the system
directly free that place id someone want to book that seat.
Moreover, the system should bring a boarding pass indicating the persons' name, passport
number and seat number as each seat is assigned, set the corresponding elements of array
to 1 to indicate that seat is no longer available.
Page 5 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Design
Main menu
Start
Declare Choice
Print
“welcome to
our airlines”
Print
“Airline Seat
Selection
1.Reservation
2.Cancel
3.Dispaly layout
4.Exit
accept choice
NO NO
NO NO PRINT
choice = 2
choice = 1 choice = 3 choice = 4 "INVALID
CH"
YES
YES YES YES
R C D E
STOP
Page 6 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
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.
Declare seats = 10
,firstname,lastname Declare
,passport.no passport.no
Print "Enter
your
Sorry no NO passport.no:"
seats If seats <10
available
Accept passport
YES number
Seats = seats+1
YES print"not
Enter firstname End of records
found"
Enter lastname
Enter
passport.no
NO
Accept NO passport.no=
Read next record
Firstname,Lastname, record_passport.no?
passport.no
print
"booked Delete record
successfully"
YES
RTN
RTN
Figure 2 functions
Page 7 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
NO
End of records? Display seats read next record
YES
RTN
Page 8 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Pseudocode
Begin
Declare Choice Repeat
repeat
display “welcome to our airlines”
display “Airline Seat Selection
1.Reservathion
2.Cancel
3.Dispaly layout
4.Exit
Enter your choice”
Accept choice
If (choice = 1)
Call R ()
Else
If (choice = 2)
Call C ()
Else
If (choice = 3)
Call D ()
Else
If (choice = 4)
Call E ()
Else
Page 9 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
End-If
End-If
End-If
End
Function reservation ()
Accept name
Accept email
IF (seats >15)
Page 10 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
ELSE
IF
(Seats <=15)
END-IF
END-IF
END-FOR
Return
Function Cancel ()
Delete record
Return
END-IF
END-do
Page 11 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Return
Display Record
End -do
Return
Page 12 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Implementation
(Header file )
{
char passport[6]; (Declaring)
char name[15];
int seat_num;
char email[15];
struct mufti_airline *following;
}
*begin, *stream;
struct mufti_airline *dummy;
Page 13 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
// ************************************GOOD LUCK
MUFTI************************************
void details();
void reserve(int x) (int x the reservation part is only for 15 seats so I use x
instead of 15 because if I want to change the seat number I will change only x)
{
stream = begin; (this is for first user want to register)
if (begin == NULL)
Page 14 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
{
// first user
begin = stream = (struct mufti_airline*)malloc(sizeof(struct
mufti_airline));
(memory allocation/ allocates the requested memory and returns a pointer to it)
details();
stream->following = NULL; (checking if the next node is empty book
it )
printf("\n\t Seat booking successful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x; (same as I mentioned up x for seats number up
to 15 seats )
return; (go back)
}
else if (x > 15) // FULL SEATS
{
printf("\n\t\t Seat Full.");
return;
}
else
{ ( it is registering the next users )
// next user
while (stream->following)
stream = stream->following;
stream->following = (struct mufti_airline *)malloc(sizeof(struct
mufti_airline));
stream = stream->following;
details();
stream->following = NULL;
printf("\n\t Seat booking succesful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x;
return;
}
}
// ************************GOOD LUCK MUFTI********************************
void savefile()
{
FILE *fpointer = fopen("mufti records", "w");
(where I store the
records in mufti record file)(opening the file)
if (!fpointer)
{
printf("\n Error in opening file!");
return;
Sleep(800); (delays program execution for a given number of seconds)
}
stream = begin;
while (stream)
{
fprintf(fpointer, "%-6s", stream->passport);
fprintf(fpointer, "%-15s", stream->name);
fprintf(fpointer, "%-15s", stream->email);
stream = stream->following;
Page 15 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
}
printf("\n\n\t Details have been saved to a file (mufti records)");
fclose(fpointer); (closing the file)
}
//********************************GOOD LUCK
MUFTI***************************************
void display() (it is displaying the all the records that I registered)
{
stream = begin;
while (stream)
{
printf("\n\n Passport Number : %-6s", stream->passport);
printf("\n name : %-15s", stream->name);
printf("\n email address: %-15s", stream->email);
printf("\n Seat number: A-%d", stream->seat_num);
printf("\n\n+
+*=====================================================*++");
stream = stream->following; (it is displaying one by one up to
15 seats)
}
}
//*****************************GOOD LUCK
MUFTI*************************************
void cancel()
{
stream = begin; ( deleting the first user)
system("cls");
char passport[6];
printf("\n\n Enter passort number to delete record?:"); (asking for the
passport you want to delete)
gets(passport); fflush(stdin);
if (strcmp(begin->passport, passport) == 0)
{
dummy = begin;
begin = begin->following;
free(dummy); ( it is freeing the place)
printf(" booking has been deleted");
Sleep(800);
return;
Page 16 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
stream = stream->following;
}
printf("passport number is wrong please check your passport");
(if user enter wrong passport number)
}
// ************************************GOOD LUCK
MUFTI**********************************
Page 17 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Screenshots
When the program is executed, the user will be directed to the main menu interface. The
program is introduced with a few lines of texts. Then four selections are made for the
user as the user can choose to reserve, cancel, display or exit the program.
Page 18 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
. If the user accidentally enters an invalid input, an interface will be shown to notify the
user to choose again and it notify the user again to enter from 1-4.
reservation function
The program is asking the user to enter passport number, name, and the email address to
reserve a seat for the user and the seat cannot be book for anyone else.
Page 19 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
As shown in the interface the seat reservation has been booked successfully, after the user
has entered the details.
15 is the maximum seats number the program could not book any more seat
After registering 15 users in the system now the flight supposed to be full and cannot
except anymore.
Page 20 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Figure it is displaying the no more seat available that cannot book any seat
The system will pop out to notify the user that there’s no seat available, the flight
contains only 15 seat after that it is displaying it is full sorry we cannot register anymore.
cancel function
After the passenger entered 3 and want to cancel the record, after that, the program
requires the user to enter which passport number to delete it. For example, that mufti
registered the seat in the flight and he wants to cancel it.
Page 21 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
The system asking mufti to enter his passport number to cancel it from the system without any
problems and in efficient way. After mufti entered his passport number the system pop in your
record has been deleted from the system.
If mufti entered the wrong passport number by mistake the system pop in hey ahmed
passport number is wrong, please check your passport number and enter it again.
Page 22 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
The interface is displaying all the users record that now you have two seats ahmed with
his details and mufti with his details as well. There’s line between the users to make it
clear to read and do not misunderstand it.
Page 23 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
display function
After mufti cancel his seat from the system, the interface is showing that only ahmed in
the system and mufti’s seat already deleted.
Page 24 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
after entered 4 which is exit function, it is storing all the records into file with all the passenger’s
details in mufti record.
The interface is showing the record in notepad which is the storing part and it is displaying
ahmed and his details after mufti cancel his record.
Page 25 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
C source code
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<Windows.h>
struct mufti_airline
{
char passport[6];
char name[15];
int seat_num;
char email[15];
struct mufti_airline *following;
}
*begin, *stream;
struct mufti_airline *dummy;
void main()
{
void reserve(int x), cancel(), display(), savefile(); //function
prototypes
int choice;
begin = stream = NULL; //initialize the struct pointers to NULL
int num = 1;
do
{
printf("\n\n\t\t
********************************************************************");
printf("\n\t\t welcome to mufti's airline system
");
printf("\n\t\t
*******************************************************************");
printf("\n\n\n\t\t Please enter your choice from below (1-4):");
printf("\n\n\t\t 1. Reservation");
printf("\n\n\t\t 2. Cancel");
printf("\n\n\t\t 3. DISPLAY RECORDS");
printf("\n\n\t\t 4. EXIT");
printf("\n\n\t\t feel free to ask us");
printf("\n\n\t\t Enter your choose ");
Page 26 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
cancel();
break;
case 3:
display();
break;
case 4:
{
savefile();
break;
}
default:
printf("\n\n\t SORRY INVALID CHOICE!");
printf("\n\n\t PLEASE CHOOSE FROM 1-4");
printf("\n\n\t Do not forget to chose from 1-4");
}
getch();
} while (choice != 4);
}
// ************************GOOD LUCK MUFTI*****************************
void details()
{
printf("\n\t Enter your passport number:");
gets(stream->passport); fflush(stdin); //reads a line from stdin and
stores it into the string pointed
printf("\n\t Enter your name:");
gets(stream->name); fflush(stdin);
printf("\n\t Enter your email address:");
gets(stream->email); fflush(stdin);
// ************************************GOOD LUCK
MUFTI************************************
void details();
void reserve(int x)
{
stream = begin;
if (begin == NULL)
{
// first user
begin = stream = (struct mufti_airline*)malloc(sizeof(struct
mufti_airline));
details();
stream->following = NULL;
printf("\n\t Seat booking successful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x;
return;
}
else if (x > 15) // FULL SEATS
{
printf("\n\t\t Seat Full.");
return;
}
else
Page 27 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
{
// next user
while (stream->following)
stream = stream->following;
stream->following = (struct mufti_airline *)malloc(sizeof(struct
mufti_airline));
stream = stream->following;
details();
stream->following = NULL;
printf("\n\t Seat booking succesful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x;
return;
}
}
// ************************GOOD LUCK MUFTI********************************
void savefile()
{
FILE *fpointer = fopen("mufti records", "w");
if (!fpointer)
{
printf("\n Error in opening file!");
return;
Sleep(800);
}
stream = begin;
while (stream)
{
fprintf(fpointer, "%-6s", stream->passport);
fprintf(fpointer, "%-15s", stream->name);
fprintf(fpointer, "%-15s", stream->email);
stream = stream->following;
}
printf("\n\n\t Details have been saved to a file (mufti records)");
fclose(fpointer);
}
//********************************GOOD LUCK
MUFTI***************************************
void display()
{
stream = begin;
while (stream)
{
printf("\n\n Passport Number : %-6s", stream->passport);
printf("\n name : %-15s", stream->name);
printf("\n email address: %-15s", stream->email);
printf("\n Seat number: A-%d", stream->seat_num);
printf("\n\n+
+*=====================================================*++");
stream = stream->following;
}
Page 28 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
//*****************************GOOD LUCK
MUFTI*************************************
void cancel()
{
stream = begin;
system("cls");
char passport[6];
printf("\n\n Enter passort number to delete record?:");
gets(passport); fflush(stdin);
if (strcmp(begin->passport, passport) == 0)
{
dummy = begin;
begin = begin->following;
free(dummy);
printf(" booking has been deleted");
Sleep(800);
return;
while (stream->following)
{
if (strcmp(stream->following->passport, passport) == 0)
{
dummy = stream->following;
stream->following = stream->following->following;
free(dummy);
printf("has been deleted ");
getch();
Sleep(800);
return;
}
stream = stream->following;
}
printf("passport number is wrong please check your passport");
Page 29 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Conclusion
The Airline reservation system is designed for users to reserve a seat, cancel,
display seat and exit the system. A formula is included in the function to calculate the
seats are reserved. Pseudocode is written for some important codes. A few flow charts are
also created for explaining the process of the Airline reservation system.
From this assignment, I have learnt to implement a few C concepts in the future
projects such as functions, switch statement and do…while statement, arrays, pointers
and structures in the program. I have also learnt to create flow charts for explaining the
program using Microsoft Visio 2013.
Page 30 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
References
References
Anon., n.d. C functions. [Online]
Available at: https://www.tutorialspoint.com/cprogramming/c_functions.htm
[Accessed 2016].
Anon., n.d. C library function - gets(). [Online]
Available at: https://www.tutorialspoint.com/c_standard_library/c_function_gets.htm
[Accessed 2016].
Anon., n.d. Clrscr() and Getch() in C. [Online]
Available at: http://www.sitesbay.com/cprogramming/c-clrscr-and-getch
[Accessed 2016].
Anon., n.d. Do...while loop in C. [Online]
Available at: https://www.tutorialspoint.com/cprogramming/c_do_while_loop.htm
[Accessed 2016].
Anon., n.d. Linked list program in C. [Online]
Available at:
https://www.tutorialspoint.com/data_structures_algorithms/linked_list_program_in_c.ht
m
[Accessed 2016].
Anon., n.d. Pointers in C. [Online]
Available at: https://www.tutorialspoint.com/cprogramming/c_pointers.htm
[Accessed 2016].
Anon., n.d. Strings in C. [Online]
Available at: https://www.tutorialspoint.com/cprogramming/c_strings.htm
[Accessed 2016].
Page 31 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Page 32 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Marking Scheme
Coding 0 - 10 11 – 14 15 – 19 20 – 23 24 - 30
(Imple Not done Basic coding done Coding solution done Coding Coding solution
Unresolved Program – able to covering all basic C solution contains basic,
mentat compilation compile and execute concepts contains basic intermediate and
ion) errors Less than 50% of Common solution and advanced C
Program not basic requirements Program – able to intermediate C concepts
(30%) executable are met compile and execute concepts Unique solution
Less than Poor coding styles Between 50% - 65% Unique Program – able to
20% of No validation. of the basic solution compile and
basic Little or no mapping requirements are met Program – able execute
requirement between design and Basic coding styles to compile and More than 75% of
s are met. program solution Minor validations for execute the basic
The coding menu options Between 65% - requirements of
solution Some mapping 75% of the the system runs
lacks proper between design and basic Excellent coding
structure program solution requirements styles
Program of are met Excellent
solution Good coding validation
does not styles Excellent mapping
map with Good between design
Page 33 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
Page 34 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
0-3 4 5-6 7 8 - 10
Did not turn up for Most questions Some questions Most questions All questions posed
test posed were not posed were answered posed were answered were answered
Test Not able to answer answered correctly correctly correctly
(10%) all/most of the correctly
questions posed
0-1 2 3 4 5
Did not turn up for Barely able to Able to trace some Able to trace the In depth
presentation trace the codes / codes / work done codes and work done understanding of the
Not able to t ace any work done with hesitation Able to execute the codes / work done
of the codes / work Had difficulty in Able to execute the program Able to execute the
Demonstrati done executing the system Able to explain and program
on Did not know how to system shows a good Able to explain and
execute the system understanding of argues the work
(5%) how the system submitted.
works. Show additional
concepts / new ideas
used in the solution
Remarks:
Page 35 of 36
CT018-3-1-ITCP AIRLINE RESERVATION SYSTRM
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
______________
Page 36 of 36