Top Banner
Introduction to C Programming (CT018-3-1) Table of Contents Acknowledgement...................................................... 2 Introduction......................................................... 3 Assumption........................................................... 4 Programming Concepts................................................. 7 Program Design....................................................... 6 Sample Outputs...................................................... 21 Main menu........................................................... 21 Conclusion.......................................................... 28 1
33

C Programming

Jul 22, 2016

Download

Documents

xdsxsxcsc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: C Programming

Introduction to C Programming (CT018-3-1)

Table of ContentsAcknowledgement.......................................................................................................................................2

Introduction.................................................................................................................................................3

Assumption..................................................................................................................................................4

Programming Concepts...............................................................................................................................7

Program Design...........................................................................................................................................6

Sample Outputs.........................................................................................................................................21

Main menu................................................................................................................................................21

Conclusion.................................................................................................................................................28

1

Page 2: C Programming

Introduction to C Programming (CT018-3-1)

ACKNOWLEDGEMENTS

Firstly we would like to thank our lecturer for all the help and guidance given to us while doing

this assignment. Especially for guiding us on this module in such a way that we were able to

learn this C programming in a greater way.

Although this is an individual assignment there are few of my classmates give a great hand on

supporting this assignment. I would like to thank our university APU for their assistance on

many resources at required times. And last but not least our friends, parents and the well-wishers

without whose moral support and encouragement, we would not have been able to do a good job.

2

Page 3: C Programming

Introduction to C Programming (CT018-3-1)

INTRODUCTION

This C Programing that was assigned to us is regarding the customer reservation. We are

required to develop a system to manage customer reservation where it will be able to add new

reservation, cancel or update existing reservation, view existing and search for available table

and room. Below are the descriptions for the individual assignment.

Yums Cafe just opened their new branch near Bukit Jalil. Customer can reserve a table for

maximum 5 customers or a private room that can accommodate up to 10 customers. There are 20

tables and 3 private rooms available at the cafe. Yums Cafe wants to improve their customer

service by automating the reservation service, which will increase the efficiency of the business

operations.

The guidelines that will use when execute will be based on the objectives such as make a quick

and easy customer reservation. Generates accurate database for the restaurant report. Make the

system easy and simple for the user. The main key success is to complete the project within the

time limit. This assignment should met all the objectives. The system should not have any error

when user uses it. This system needs a C compiler to execute such as Visual studio 2012.

3

Page 4: C Programming

Introduction to C Programming (CT018-3-1)

ASSUMPTION

Compiler Warning (level 3) C4996

C4996 may occur because compiler encountered a function that was marked with deprecated. The function may no longer be supported in a future release. You can turn this warning off with the warning pragma (example below).Some CRT and Standard C++ Library functions have been deprecated in favor of new, more secure functions. For more information on which function to use instead, see the documentation for the deprecated function in the error message. To turn off CRT deprecation warnings, define _CRT_SECURE_NO_WARNINGS. For more information about deprecated functions, see Security Features in the CRT and Safe Libraries: C++ Standard Library.You will see C4996 if you are using members of the <hash_map> and <hash_set> header files in the std namespace. See The stdext Namespace for more information.C4996 can also occur if you use MFC or ATL functions that were deprecated for security reasons. To suppress these warnings, see _AFX_SECURE_NO_WARNINGS and _ATL_SECURE_NO_WARNINGS.C4996 can also occur when you use the marshaling library. In this case C4996 is an error, not a warning. This error will occur when you use marshals’ to convert between two data types that require a marshal context Class. You will also receive this error when the marshaling library does not support a conversion. For more information about the marshaling library, see Overview of Marshaling in C++.In the first example, C4996 is generated for the line on which the function is declared and for the line on which the function is used.

At early of this development via Visual Studio 2012 there will be some error prompting out when generates C Programming. That is error C4996. This error saying that the function or variable may be unsafe. This need to consider using scanf_s instead. To disable deprecation we need to use CRT_SECURE_NO_WARNINGS. Below are the steps to avoid this common error.

4

Page 5: C Programming

Introduction to C Programming (CT018-3-1)

STEP 1

Go the Project option and select properties.

STEP 2

After choosing properties under C/C++ choose advance. It will direct you to list as shown above.

5

Page 6: C Programming

Introduction to C Programming (CT018-3-1)

STEP 3

After it shown the list above. Change the compile as to compile as C code. Lastly key in the disable specific warnings which is 4996

6

Page 7: C Programming

Introduction to C Programming (CT018-3-1)

PROGRAMMING CONCEPT

When you write a program, you can store data and manipulate it with a series of instructions. Data and data storage containers are the basic building blocks in programs, and you use commands, functions, and operators to manipulate data and data storage containers. Concept programming is initially a very simple idea your code should reflect the concepts in your application.

As simple as this idea is, it is not easy to implement, nor is it easy to fully understand the implications. As a matter of fact, I believe that this would give well enough material for an entire book. But I will try to quickly brush over the subject here

A concept is something from the application environment that matters to your program. A "window" displaying some information may be a concept. Most algorithms are derived from some mathematical concept. A "function" may be a concept. Programming is the art of turning concepts into code.

Consider the concept of addition as an example. Across different languages, not only can the addition of A and B can be written in a variety of ways (different syntax), but it can also behave very differently (different semantics)

The concepts discussed on this page are essential knowledge to anyone who wants to become skilled in computer programming. While some are not universal, these concepts are present in the majority of computer programming languages and/or are a fundamental part of the programming process

7

Page 8: C Programming

Introduction to C Programming (CT018-3-1)

PROGRAM DESIGN

/*Introduction to C programming Customer Reservation SystemDesigned by Gunaseelan (TP028706)ASIA PACIFIC UNIVERSITY*/

//header#include <stdio.h>#include <stdlib.h>#include <conio.h>

//Declarationint Input;int cnt=0; // record counterint cnt_del=0; // deleted record counter

/*Global Variable*/FILE *Guna,*temp;

int timez[20];int time[20][2];int day[20][2], month[20][2], year[20][2];int dayz[20], monthz[20], yearz[20];

//prototypeschar name[20][100]; // first namechar gender[20][100]; // gender either male or femalechar ic_Number[20][100]; // Identification Card Numberchar telnum[20][100];// mobile numberchar numof_cus[20][100];//no of customer

int num = 0;int roomLeft = 3, room = 0;int tableLeft = 20, table = 0;

//int menu(), // Exit();

int main(){ menu();

return 0;// return type functions}

int menu()//main menu body{

system("cls");

8

Page 9: C Programming

Introduction to C Programming (CT018-3-1)

printf("\n\t\t\t %c",2);printf(" Welcome to Yums Cafe ");printf("%c",2);printf("\n\t\t\t%c ",2);printf("Customer reservation System ");printf("%c",2);

printf("\n\n\n\n\n\n\t\t\t1. Reserve a room");printf("\n\t\t\t2. Reserve a table");

printf("\n\t\t\t3. view existing and available room");printf("\n\t\t\t4. view existing and available table");

printf("\n\t\t\t5. Cancel room reservation ");printf("\n\t\t\t6. Cancel table reservation ");

printf("\n\t\t\t7. Update room reservation");printf("\n\t\t\t8. Update table reservation");

printf("\n\t\t\t9. Exit \n"); printf("\n\t\t\tEnter the choice: ");

scanf("%i", &Input); fflush(stdin);

switch(Input) { case 1:

if(room < 3 ) reserve(); else printf("No rooms are available, sorry... \n"); menu(); break;

case 2:if(table < 20)

reserve_table(); else printf("No tables are available, sorry... \n"); menu(); break; case 3: view_room(); break;

case 4: view_table(); break; case 5: cancel_room(); break;

case 6: cancel_table(); break;

case 7:if(room == 0)

{ printf("\nThere are no room has reserve!\n"); menu(); }

9

Page 10: C Programming

Introduction to C Programming (CT018-3-1)

else { update_room(); } break;

case 8: if(table == 0) { printf("\nThere are no table has reserve!\n"); menu(); } else { update_table(); } break;

case 9: printf("\n\t\t\t\tAre you sure want to exit?"); printf("\n\t\t\t\t[1]Yes");

printf("\n\t\t\t\t[2]No\n"); scanf("%d",&exit);

if(exit=="1"){

return(0);}else (exit=="2");

{ return main(); }

break;default:

printf("\nInvalid input entered"); getch(); return main(); }}

int reserve()// to register new customer for booking room or input a new customer's detail into the system{ num++;

system("cls");printf("\

n****************************************************************************"); printf("\t\t\t\t\tAdd New Customer"); printf("\n****************************************************************************");

Guna=fopen("Guna.dat","a");temp=fopen("temp.dat","w");

printf("\n\nName: ");

scanf("%[^\n]s", name[num]); fflush(stdin);

printf("\n\nGender: "); //male or female// scanf("%[^\n]s", gender[num]); fflush(stdin);

10

Page 11: C Programming

Introduction to C Programming (CT018-3-1)

printf("\n\nCustomer's IC No: "); scanf("%[^\n]s", ic_Number[num]); fflush(stdin);

printf("\n\nNumber of customer's: "); scanf("%[^\n]s", numof_cus[num]); fflush(stdin);

printf("\n\nCustomer's Contact No: "); scanf("%[^\n]s", telnum[num]); fflush(stdin);

do{ printf("\nTime (24-Hour Format, no minute allow!):"); fflush(stdin); scanf("%i", time[room]); timez[room] = *time[room]; }while(timez[room] >= 24 || timez[room] < 0);

do { printf("Booking date (This session can't be update!):-\n"); printf("Date: "); fflush(stdin); scanf("%i", day[room]); dayz[room] = *day[room]; printf("Month: "); fflush(stdin); scanf("%i", month[room]); monthz[room] = *month[room]; printf("Year (2 digit only): "); fflush(stdin); scanf("%i",year[room]); yearz[room] = * year[room]; }while((monthz[room] == 2 && dayz[room] > 29) || dayz[room] > 31 || monthz[room] > 12);

//print the input into the external data filefprintf(Guna,"\n %s\n %s\n %s\n %s\n %s\n %s\

n",name[num],gender[num],ic_Number[num],numof_cus[num],telnum[num],time[num], day[num], month[num], year[num]); fclose(Guna);

room++; roomLeft--; menu();

return 0;}

int reserve_table()// to register new customer for booking table or input a new customer's detail into the system{ num++;

system("cls");printf("\

n****************************************************************************");

11

Page 12: C Programming

Introduction to C Programming (CT018-3-1)

printf("\t\t\t\t\tAdd New Customer"); printf("\n****************************************************************************");

Guna=fopen("Guna.dat","a");temp=fopen("temp.dat","w");

printf("\n\nName: ");

scanf("%[^\n]s", name[num]); fflush(stdin);

printf("\n\nGender: "); //male or female// scanf("%[^\n]s", gender[num]); fflush(stdin);

printf("\n\nCustomer's IC No: "); scanf("%[^\n]s", ic_Number[num]); fflush(stdin);

printf("\n\nNumber of customer's: "); scanf("%[^\n]s", numof_cus[num]); fflush(stdin);

printf("\n\nCustomer's Contact No: "); scanf("%[^\n]s", telnum[num]); fflush(stdin);

do{ printf("\nTime (24-Hour Format, no minute allow!):"); fflush(stdin); scanf("%i", time[table]); timez[table] = *time[table]; }while(timez[table] >= 24 || timez[table] < 0);

do { printf("Booking date (This session can't be update!):-\n"); printf("Date: "); fflush(stdin); scanf("%i", day[table]); dayz[table] = *day[table]; printf("Month: "); fflush(stdin); scanf("%i", month[table]); monthz[table] = *month[table]; printf("Year (2 digit only): "); fflush(stdin); scanf("%i",year[table]); yearz[table] = * year[table]; }while((monthz[table] == 2 && dayz[table] > 29) || dayz[table] > 31 || monthz[table] > 12);

//print the input into the external data filefprintf(Guna,"\n %s\n %s\n %s\n %s\n %s\n %s\

n",name[num],gender[num],ic_Number[num],numof_cus[num],telnum[num],time[num], day[num], month[num], year[num]); fclose(Guna);

table++; tableLeft--;

12

Page 13: C Programming

Introduction to C Programming (CT018-3-1)

menu();

return 0;}int view_room()// to view room customer's detail by type the customer's first name{ int x, cOrder;

system("cls"); printf("\t\t\t\tAvailable Rooms: %d \n", roomLeft); printf("\t\t\t\tOccupied Rooms: %d \n", room); printf("\n\nCustomer List: \n");

Guna=fopen("Guna.dat","r"); // open the file for(x = 0; x < room; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

if(room == 0) { printf("\nselect customer please!\n"); menu(); } else { printf("\nTo view the customer information, please enter the number: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder <= room) {

system("cls"); printf("\n******************\n"); printf("Name: %s\n", name[cOrder]);

printf("\n******************\n");printf("Gender: %s\n", gender[cOrder]);printf("\n******************\n");

printf("Customer's Ic No: %s\n", ic_Number[cOrder]);printf("\n******************\n");printf("Number of Customer's: %s\n",

numof_cus[cOrder]);printf("\n******************\n");

printf("Customer's contact No: %s\n", telnum[cOrder]); printf("\n******************\n"); printf("Press any key to continue."); getch(); printf("\n"); } else { printf("\nYou are allow to enter the available number only, re-enter please.\n"); view_room();

fclose(Guna); } }

13

Page 14: C Programming

Introduction to C Programming (CT018-3-1)

menu();

return 0;}

int view_table()// to view table customer's detail by type the customer's first name{ int x, cOrder;

system("cls"); printf("\t\t\t\tAvailable Rooms: %d \n", tableLeft); printf("\t\t\t\tOccupied Rooms: %d \n", table); printf("\n\nCustomer List: \n");

Guna=fopen("Guna.dat","r"); // open the file for(x = 0; x < table; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

if(table == 0) { printf("\nselect customer please!\n"); menu(); } else { printf("\nTo view the customer information, please enter the number: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder <= table) {

system("cls"); printf("\n******************\n"); printf("Name: %s\n", name[cOrder]);

printf("\n******************\n");printf("Gender: %s\n", gender[cOrder]);printf("\n******************\n");

printf("Customer's Ic No: %s\n", ic_Number[cOrder]);printf("\n******************\n");printf("Number of Customer's: %s\n",

numof_cus[cOrder]);printf("\n******************\n");

printf("Customer's contact No: %s\n", telnum[cOrder]); printf("\n******************\n"); printf("Press any key to continue."); getch(); printf("\n"); } else { printf("\nYou are allow to enter the available number only, re-enter please.\n"); view_table();

fclose(Guna); } }

14

Page 15: C Programming

Introduction to C Programming (CT018-3-1)

menu();

return 0;}int cancel_room() //cancel room booking{ int x, y, z, cOrder;

system("cls");Guna=fopen("Guna.dat","w");

temp=fopen("temp.dat","w"); printf("\n******************************************************************"); printf("\n\t\t\t CANCEL A CUSTOMER'S RESERVATION"); printf("\n******************************************************************\n"); if(room > 0) { for(x = 0; x < room; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

printf("\nWhich customer's reservation you want to terminate? \nEnter: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder > 0 && cOrder <= room) { for(y = cOrder; y < room; y++) { for(z = 0; z < 100; z++) { name[y][z]=name[y+1][z]; ic_Number[y][z]=ic_Number[y+1][z]; telnum[y][z]=telnum[y+1][z]; } }

printf("\nThe customer room has been terminated.\n"); } else { printf("\nInvalid Value!\n"); cancel_room(); } num--; room--; roomLeft++;

} else { printf("\nNo available room to cancel!\n"); } menu();

fclose(Guna);

15

Page 16: C Programming

Introduction to C Programming (CT018-3-1)

fclose(temp);remove("Guna.dat");rename("temp.dat","Guna.dat");

return 0;}

int cancel_table() //Cancel table booking{ int x, y, z, cOrder;

system("cls");Guna=fopen("Guna.dat","w");

temp=fopen("temp.dat","w"); printf("\n******************************************************************"); printf("\n\t\t\t CANCEL A CUSTOMER'S RESERVATION"); printf("\n******************************************************************\n"); if(table > 0) { for(x = 0; x < table; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

printf("\nWhich customer's reservation you want to terminate? \nEnter: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder > 0 && cOrder <= table) { for(y = cOrder; y < table; y++) { for(z = 0; z < 100; z++) { name[y][z]=name[y+1][z]; ic_Number[y][z]=ic_Number[y+1][z]; telnum[y][z]=telnum[y+1][z]; } }

printf("\nThe customer table has been terminated.\n"); } else { printf("\nInvalid Value!\n"); cancel_table(); } num--; table--; tableLeft++;

} else { printf("\nNo available table to cancel!\n"); }

16

Page 17: C Programming

Introduction to C Programming (CT018-3-1)

menu();fclose(Guna);fclose(temp);remove("Guna.dat");rename("temp.dat","Guna.dat");

return 0;}int update_room() // Update room cutomer's detail{ int x, cOrder, input;

system("cls");Guna=fopen("Guna.dat","a"); //open file

temp=fopen("temp.dat","w"); //delete functionprintf("\

n******************************************************************"); printf("\n\t\t\t MODIFY A CUSTOMERS'S INFORMATION"); printf("\n******************************************************************"); printf("\n\nCustomer List: \n");

for(x = 0; x < room; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

printf("\nWhich customer information you want to update? \nEnter: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder > room) { printf("Invalid Value! Re-enter please! \n"); update_room(); }

printf("\nWhich line you want to change 1-4 \n1. Name \n2. gender.\n3. Ic No.\n4. Number of Customer's. \n5. Mobile No. \nEnter: "); //accept number from user. fflush(stdin); scanf("%d", &input);

switch(input) { case 1: printf("Name: "); scanf("%s", name[cOrder]); break;

case 2: printf("Gender: "); scanf("%s", gender[cOrder]); break;

case 3: printf("Customer's Ic No: "); scanf("%s", ic_Number[cOrder]); break;

17

Page 18: C Programming

Introduction to C Programming (CT018-3-1)

case 4: printf("Number of customer's: "); scanf("%s", numof_cus[cOrder]); break;

case 5: printf("Customer's Contact No: "); scanf("%s", telnum[cOrder]); break;

//print the input into the external data filefprintf(Guna,"\n %s\n %s\n %s\n %s\n %s\n %s\

n",name[num],gender[num],ic_Number[num],numof_cus[num],telnum[num],time[num], day[num], month[num], year[num]); fclose(Guna);

default: printf("Invalid Value!"); }

printf("\n customer Information has updated.\n"); fclose(Guna);

fclose(temp); remove("Guna.dat"); rename("temp.dat","Guna.dat"); return 0;}

int update_table() // Update table cutomer's detail{ int x, cOrder, input;

system("cls");Guna=fopen("Guna.dat","a"); //open file

temp=fopen("temp.dat","w"); //delete functionprintf("\

n******************************************************************"); printf("\n\t\t\t MODIFY A CUSTOMERS'S INFORMATION"); printf("\n******************************************************************"); printf("\n\nCustomer List: \n");

for(x = 0; x < table; x++) { printf("%d. Name: %s\n", x+1, name[x+1]); }

printf("\nWhich customer information you want to update? \nEnter: "); fflush(stdin); scanf("%d", &cOrder);

if(cOrder > table) { printf("Invalid Value! Re-enter please! \n"); update_table(); }

18

Page 19: C Programming

Introduction to C Programming (CT018-3-1)

printf("\nWhich line you want to change 1-5 \n1. Name \n2. gender.\n3. Ic No.\n4. Number of Customer's. \n5. Mobile No. \nEnter: "); //accept number from user. fflush(stdin); scanf("%d", &input);

switch(input) { case 1: printf("Name: "); scanf("%s", name[cOrder]); break;

case 2: printf("Gender: "); scanf("%s", gender[cOrder]); break;

case 3: printf("Customer's Ic No: "); scanf("%s", ic_Number[cOrder]); break;

case 4: printf("Number of customer's: "); scanf("%s", numof_cus[cOrder]); break;

case 5: printf("Customer's Contact No: "); scanf("%s", telnum[cOrder]); break;

//print the input into the external data filefprintf(Guna,"\n %s\n %s\n %s\n %s\n %s\n %s\

n",name[num],gender[num],ic_Number[num],numof_cus[num],telnum[num],time[num], day[num], month[num], year[num]); fclose(Guna);

default: printf("Invalid Value!"); }

printf("\n customer Information has updated.\n"); fclose(Guna);

fclose(temp); remove("Guna.dat"); rename("temp.dat","Guna.dat"); return 0;}

19

Page 20: C Programming

Introduction to C Programming (CT018-3-1)

SAMPLE OUTPUTS

This is the main menu for the Yums Café. There are few options that are listed above such as reserve a room, reserve a table, view existing and available room, , view existing and available table, cancel room reservation, cancel table reservation, update room reservation, update table reservation and exit. Thus user can choose the following option to make reservation accordingly.

Looking into the first option which is to reserve a room, user should key in their Name, Gender,

IC No, and Number of customer, Customer contact number, Time, Date, Month and Year. Right

after the user key in their data, it will direct the user to the main menu.

20

Page 21: C Programming

Introduction to C Programming (CT018-3-1)

This will be the second option which is to reserve a table, user should key in their Name,

Gender, IC No, and Number of customer, Customer contact number, Time, Date, Month and

Year. Right after the user key in their data, it will direct the user to the main menu. The design is

most likely to the reservation of room.

This will be third option for the user to view their room. In order to view their room, the customer should enter the following number that is listed in customer list.

21

Page 22: C Programming

Introduction to C Programming (CT018-3-1)

After the customer clicked on the following number it will direct them to this menu. Here they can view all the details that have been key in during reservation.

This will be third option for the user to view their table. In order to view their table, the customer should enter the following number that is listed in customer list.

22

Page 23: C Programming

Introduction to C Programming (CT018-3-1)

This menu basically can cancel the customer reservation on a table. When the user enters the number 1 it will automatically cancel the table reservation.

This will be one of the options where the customer can update their info if they wish to. By entering the following number in the customer list, it will direct them to another menu.

23

Page 24: C Programming

Introduction to C Programming (CT018-3-1)

Here the customer can update their details. For an example they can modify their Name, gender, IC No, Number of Customer and mobile no.

This will be last option in the menu. After the customer done with the room or table reservation they can enter the number 9 to exit the system. When the user chooses number 1 during exit it will exit system. If the enter number 2 they will be still accessing this system

24

Page 25: C Programming

Introduction to C Programming (CT018-3-1)

CONCLUSION

This project has been full filled successfully within the time frame that was allocated for the

system. Throughout this assignment there are many difficulties that I faced. One of them will be

on correcting this system and solving all the errors, this is including time management. We have

faced this hard time on time due to many group assignment. However I have planned and tackle

the entire problem in order to complete all the assignment. Some problem we have even

discussed with our seniors. They have guided us correctly in this assignment by showing the

correct steps. I would like to appreciate the resources that my university provided in order to

fasten my assignment such as relevant book in library and internet in labs. It shows that without

all this I wouldn’t be completing my assignment with the given time period. Thank you from the

bottom of my heart to my lecturer MR MOHAMAD FIRDAUS BIN CHE ABDUL RANI and

my fellow classmates.

25

Page 26: C Programming

Introduction to C Programming (CT018-3-1)

REFERENCES

Livecode.byu.edu, (2014). Basic Programming Concepts. [online] Available at:

http://livecode.byu.edu/programmingconcepts/ControlStruct.php [Accessed 4 Jun. 2014].

Msdn.microsoft.com, (2014). Compiler Warning (level 3) C4996. [online] Available at:

http://msdn.microsoft.com/en-us/library/ttcz0bys.aspx [Accessed 4 Jun. 2014].

Msdn.microsoft.com, (2014). Exception Specifications. [online] Available at:

http://msdn.microsoft.com/en-us/library/wfa0edys.aspx [Accessed 4 Jun. 2014].

26