For all of these questions, you can choose whether to create your own functions in your solution. However, no extra credit will be given if functions are used.
The owner of "Seng Moi Huat" provision store (let's call him Ah Seng) runs a thriving business in the heartlands of Singapore. The reason behind the success of his business is due to the fact that the store charges customers to the nearest dollar, thus absorbing all coin denominations. He reasons that for every customer, the amount of losses incurred can only be between 0 to 99 cents. So at the end of a typical day, his losses will come to less than a dollar per customer. Moreover, customers may purchase more goods in order to take advantage of the pricing scheme, so it is a win-win situation for both the customers and store owner.
Though Ah Seng sees more and more customers frequenting his store everyday (which he says is probably due to the good name of the store), he feels that he is making losses, and suspects that his store assistants are helping themselves to the till. He has since installed security cameras in the store, but have so far found no suspicious activity behind the cash register.
Ah Seng is getting desperate and the last thing he suspects is the in-house retail software. He has engaged you, the software failure analyst, to help verify and validate the workings of the system. He is a demanding person and wants the problem rectified in three days time (by Friday, 23:59:59 to be exact), and is prepared to pay you $10,000.
You will realize that the system does not keep a log of the customer transactions. Your first task is to update the system to include the transaction history which will be output to a log file. The log file will include the specific quantity and amounts of different items, and also some important data values. As an example, consider the following transaction:
New Customer? (1 for yes; 0 for no): 1 Enter quantity and amount (-1 -1 to quit): 1 1.50 Enter quantity and amount (-1 -1 to quit): 2 3.30 Enter quantity and amount (-1 -1 to quit): -1 -1 The total purchase is : $8. New Customer? (1 for yes; 0 for no): 1 Enter quantity and amount (-1 -1 to quit): 1 4.60 Enter quantity and amount (-1 -1 to quit): -1 -1 The total purchase is : $4. New Customer? (1 for yes; 0 for no): 1 Enter quantity and amount (-1 -1 to quit): 3 2.50 Enter quantity and amount (-1 -1 to quit): 1 12.50 Enter quantity and amount (-1 -1 to quit): 2 0.50 Enter quantity and amount (-1 -1 to quit): -1 -1 The total purchase is : $21. New Customer? (1 for yes; 0 for no): 0The transactions log file (log.out) will be
1 1.50 2 3.30 -1 -1 8 8.10 0.10 1 4.60 -1 -1 4 4.60 0.60 3 2.50 1 12.50 2 0.50 -1 -1 21 21.00 0.00 |
The name of your C program file must be called lab5q1.c, files with any other name will not be marked.
$ gcc -Wall lab5q1.c -o lab5q1 $ ./lab5q1 < key.outExpect to see a huge chunk of printout when executing the program. You can ignore these, as they are the merely the printf statements of your program when running. If you are using sunfire, you can execute the program in the following way.
$./lab5q1 < key.out > /dev/nullNow inspect the log.out file generated by your program and check for inconsistencies. Pay particular attention to the losses made. Remember that the losses should be between 0 to 99 cents.
As a guide, here is the correct log that you must generate as the new log.out
The name of your C program file must be called lab5q2.c, files with any other name will not be marked.
A total of 23 different hosts have accessed this document in the last 444 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 10 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.