/*===================================================================*
*NAME : TrainMaster *
*PURPOSE : This program is developed as a task of an assignment *
* of HND-IT of ICBT City Campus. It is used to record *
* the seat reservations for a long distant train. *
*AUTHOR : Sandeep Ellawala *
*CONTACT : sandeep.ellawala@gmail.com *
* +94(0)774055644 *
*NOTE : This program does not use any files or databases to *
* store any kind of data. It simply uses an arrray to *
* keep track of data being manipulated. Every time the*
* program runs, it starts fresh. *
*===================================================================*/
/*This program can be compiled only with a Turbo C compiler due to *
*the fact that some of the functions used in this program are only *
*available with Borland Turbo C compiler package. We are to handle *
*this before the code is compiled. */
# ifndef __TURBOC__
# error Only Turbo C compiler is compatible with this code!
# endif
/*-------------------------------------------------------------------*
* INCLUDED HEADER FILES *
*-------------------------------------------------------------------*/
# include <conio.h>
# include <stdio.h>
# include <stdlib.h>
/*-------------------------------------------------------------------*
* DEFINED CONSTANTS *
*-------------------------------------------------------------------*/
# define TRUE 1
# define FALSE 0
# define NOT_RESERVED 0 /*00000000*/
# define RESERVED 1 /*00000001*/
# define BERTH 2 /*00000010*/
# define FOOD 4 /*00000100*/
# define SEAT_COUNT 16
# define COMP_COUNT 15
# define FIRST_COUNT 3
# define SECOND_COUNT 5
/*-------------------------------------------------------------------*
* TYPES DEFINED *
*-------------------------------------------------------------------*/
typedef unsigned short int BOOL;
typedef unsigned short int RES_TYPE;
/*-------------------------------------------------------------------*
* GLOBAL VARIABLES *
*-------------------------------------------------------------------*/
RES_TYPE seatStruc[COMP_COUNT][SEAT_COUNT];
/*-------------------------------------------------------------------*
* FUNCTION PROTOTYPES *
*-------------------------------------------------------------------*/
int main(int, char**);
void prepareScreen(void);
void getPrompt(void);
void invalidStartup(void);
void welcomeScreen(void);
void initSeats(void);
void mainMenu(void);
void makeReservation(void);
void reservationMenu();
void firstClassReservation(void);
void secondClassReservation(void);
void thirdClassReservation(void);
void cancelReservation(void);
void clearReservations(void);
void viewReservations(void);
void invalidOption(void);
void exitMessage(void);
/*-------------------------------------------------------------------*
* FUNCTION: main() *
*-------------------------------------------------------------------*/
int main(int argc, char **argv) {
char opt;
BOOL mustContinue = TRUE;
if (argc > 1) {
/*This program does not accept any command line args *
*to function. So it terminates the system in case *
*if any such are found. */
invalidStartup();
return EXIT_FAILURE;
}
welcomeScreen();
do {
mainMenu();
fflush(stdin);
opt = (char)getch();
switch (opt) {
case 'm':
case 'M':
makeReservation();
break;
case 'd':
case 'D':
cancelReservation();
break;
case 'c':
case 'C':
clearReservations();
break;
case 'v':
case 'V':
viewReservations();
break;
case 'h':
case 'H':
//helpInformation();
break;
case 'x':
case 'X':
mustContinue = FALSE;
break;
default:
invalidOption();
break;
}
} while (mustContinue == TRUE);
exitMessage();
return EXIT_SUCCESS;
}
/*-------------------------------------------------------------------*
* FUNCTION: prepareScreen() *
*-------------------------------------------------------------------*/
void prepareScreen(void) {
int ctr;
/*Set the screen mode to Text Mode with a character matrix of*
*80 x 25 so that the screen can be designed properly. */
textmode(C80);
/*Rest of the screen properties are set here. */
textcolor(GREEN);
textbackground(BLACK);
_setcursortype(_NOCURSOR);
clrscr();
/*The horizontal lines of the screen are drawn here. */
for (ctr = 3; ctr < 79; ctr++) {
gotoxy(ctr, 2);
cprintf("%c", 205);
gotoxy(ctr, 24);
cprintf("%c", 205);
gotoxy(ctr, 22);
cprintf("%c", 205);
}
/*The verticle lines on the screen are drawn here. */
for (ctr = 3; ctr < 24; ctr++) {
gotoxy(2, ctr);
cprintf("%c", 186);
gotoxy(79, ctr);
cprintf("%c", 186);
}
/*The four corners are drawn on the screen here. */
gotoxy(2, 2);
cprintf("%c", 201);
gotoxy(2, 24);
cprintf("%c", 200);
gotoxy(79, 2);
cprintf("%c", 187);
gotoxy(79, 24);
cprintf("%c", 188);
/*The two connectors are drawn here. */
gotoxy(2, 22);
cprintf("%c", 204);
gotoxy(79, 22);
cprintf("%c", 185);
gotoxy(3, 23);
cprintf("CMD >> ");
/*The static text drawn on the screen giving credits to the *
*developer are done here. */
textcolor(LIGHTGREEN);
gotoxy(2, 1);
cprintf("ICBT HND-32 (2009)");
gotoxy(64, 1);
cprintf("Sandeep Ellawala");
gotoxy(2, 25);
cprintf("sandeep.ellawala@gmail.com");
gotoxy(65, 25);
cprintf("+94(0)774055644");
}
/*-------------------------------------------------------------------*
* FUNCTION: getPrompt() *
*-------------------------------------------------------------------*/
void getPrompt(void) {
fflush(stdin);
while (getch() != '\r') {
; /*NULL statement */
}
}
/*-------------------------------------------------------------------*
* FUNCTION: invalidStartup() *
*-------------------------------------------------------------------*/
void invalidStartup(void) {
prepareScreen();
gotoxy(27, 12);
textcolor(LIGHTRED);
cprintf("ERROR: System Startup Error!");
gotoxy(3, 23);
cprintf(" ");
textcolor(YELLOW);
gotoxy(3, 23);
cprintf("Press [ENTER] to exit");
textcolor(YELLOW | BLINK);
cprintf("... ");
getPrompt();
}
/*-------------------------------------------------------------------*
* FUNCTION: welcomeScreen() *
*-------------------------------------------------------------------*/
void welcomeScreen(void) {
prepareScreen();
textcolor(YELLOW);
gotoxy(37, 7);
cprintf("WELCOME");
gotoxy(37, 8);
cprintf("-------");
gotoxy(20, 11);
cprintf("You are using TrainMaster 1.0v, a software");
gotoxy(34, 12);
cprintf("developped by");
gotoxy(25, 13);
cprintf("Sandeep Ellawala (HND Batch 32).");
gotoxy(15, 14);
cprintf("Please reffer to the help information if you do not");
gotoxy(
评论0