Using C COP2220 – Assignment 4 Solution



Since this is the last assignment, there will be no late submission.


With this assignment you will start to learn how to write a practical menu driven program that manages a list of data and implements a rudimentary database. You will use an array of structs to organize the data and you will read and save the information in a text.

The assignment is to write a menu driven program that manages a hotel registration system. You will use a structure to store the following customer information:

Customer First Name
Customer Last Name
Customer ID
Room #
Customer Current Charges (dollars and cents)
Customer Room Charge Limit (dollars and cents)

(Please remember that your structure must define member types that are appropriate for the given data!)

Your menu commands will include:
C) Customer Check-in
O) Customer Check-out
L) Customer List (to the screen)
D) Delete all customers
A) Add a Customer Room Charge
Q) Quit

Implementation Details:
• When the program begins, it will read the customer data list from the database (text file)
• When a new customer checks in, the program will ask the user for each of the fields on a separate line. The program must check to make sure a customer with the same ID does not already exist!
• When a customer checks out, the program will ask you for the customer id of the customer who is checking out. Locate the entry in the array and remove all of the data for that entry. The list does not need to be sorted – to remove an entry, you may move the last item in the list to the location of the deleted entry. The program must handle if the customer is not found.
• When you display the customer list on the screen, all of the information stored for each customer will be labeled and displayed.
• Deleting all customers “deletes” all of the information in the array by resetting each value to an appropriate default value. Remember this means setting the customer id to -1.

• When adding a customer charge, the program will ask for the customer id whose account the charge will be added to. The program should add the new charges to the old one and update the current room charges for the given customer (don’t worry about going over the room’s charge limit!). The program must handle if it cannot find the given customer id.
• When the program exits, it will write the current list to the database (text file).




Instructions:

• You should use at least 10 user-defined functions (plus main) to appropriately break the problem up into smaller pieces.
• You need to begin the program by reading the records from the database and displaying the number of records read in. After this the menu should be shown.
• You must use function prototypes and NO global variables.
• You must use a #define to set the upper bound of the list to at least 20 entries.
• Your code should be well designed, well commented and written with good style.

Other Important Hints and Reminders:
• Start work on this as soon as possible. We will work on it in class but DO NOT rely on this – we most likely will get sidetracked in discussions as they arise.
• You are expected to receive as much help as you need for the basic assignment.
• It is your responsibility to request this help in the form of specific questions.
• You may ask these questions by sending them via email to me or the lab TAs.
• When you ask a question, it should be specific, and you should provide the current version of your program.
• The current version of your program should be neatly formatted and commented. It should also be properly indented and use meaningful variable and function names. This will make it easier for anyone helping you to understand what you are trying to do.

NOTE: there will probably be no assistance with this assignment on the last weekend before the assignment or the morning it is due so DON’T leave this assignment to the last minute.

Sample output

Loading customers...

0 customers added to list

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 0 customers checked in
----------------------------------

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? c

Please enter the Last Name: Falcone
Please enter the First Name: John
Please enter the Customer ID: 112
Please enter the Room Number: 200
Please enter the Current Charges: 13.50
Please enter the Current Limit: 100

Customer with ID 112 has been checked in

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 1 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $13.50

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? q

Storing customers...

1 customers stored in db


Loading customers...

1 customers added to list

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 1 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $13.50

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? a

Enter the customer ID to add charge to: 10
Customer 10 was not found

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? a

Enter the customer ID to add charge to: 112

Enter the amount to charge customer John Falcone: 10

Customer John Falcone was charged 10.00, total charges are now 23.50

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 1 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $23.50

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? c

Please enter the Last Name: Jones
Please enter the First Name: Fred
Please enter the Customer ID: 123
Please enter the Room Number: 119
Please enter the Current Charges: 0
Please enter the Current Limit: 500

Customer with ID 123 has been checked in

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? c

Please enter the Last Name: Tyson
Please enter the First Name: Mike
Please enter the Customer ID: 123
Please enter the Room Number: 1
Please enter the Current Charges: 0
Please enter the Current Limit: 1000

A customer with ID 123 already exists in database

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 2 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $23.50

Customer ID: 123
Customer Name: Fred Jones
Room #: 119
Credit Limit: $500.00
Current Charges: $0.00

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? c

Please enter the Last Name: Tyson
Please enter the First Name: Mike
Please enter the Customer ID: 999
Please enter the Room Number: 911
Please enter the Current Charges: 0
Please enter the Current Limit: 5000

Customer with ID 999 has been checked in

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 3 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $23.50

Customer ID: 123
Customer Name: Fred Jones
Room #: 119
Credit Limit: $500.00
Current Charges: $0.00

Customer ID: 999
Customer Name: Mike Tyson
Room #: 911
Credit Limit: $5000.00
Current Charges: $0.00

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? q

Storing customers...

3 customers stored in db

Loading customers...

3 customers added to list

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 3 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $23.50

Customer ID: 123
Customer Name: Fred Jones
Room #: 119
Credit Limit: $500.00
Current Charges: $0.00

Customer ID: 999
Customer Name: Mike Tyson
Room #: 911
Credit Limit: $5000.00
Current Charges: $0.00

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? o

Enter the customer ID to check out: 123

Customer 123 has been checked out

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 2 customers checked in
----------------------------------

Customer ID: 112
Customer Name: John Falcone
Room #: 200
Credit Limit: $100.00
Current Charges: $23.50

Customer ID: 999
Customer Name: Mike Tyson
Room #: 911
Credit Limit: $5000.00
Current Charges: $0.00

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? d

All records have been deleted!

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? l

There are 0 customers checked in
----------------------------------

----------------------------------

Customer Registration System
----------------------------

C) Customer Check-in
O) Customer Check-out
L) Customer List
D) Delete All Customers
A) Add Customer Room Charge
Q) Quit

What would you like to do? q

Storing customers...

0 customers stored in db
Powered by