58127 Programming in C - excercises 1. Word counter Create a program that reads one text file. The user must be able to select the input method for the file; either input the file name as a command line parameter, or the program may assume that the information comes from a stdin file. The program must output the words (at least two characters in a row) from the file and the number of their occurrences in alphabetical order. Each word and the number of its occurrences should be output on their own line. The name of the output file is handled in the same way as the input-file name. Use a binary tree as your data structure. Implement the binary tree with pointers and dynamicity. Your tree implementation should use the basic tree operations taught at the course Data structures. * 2. Simulating a checkout point Write a program that simulates (but does not mime) the functions of a checkout point in a store. Customers arrive in the store, and we only have one checkout point that the customers have to stand in queue for. When the checkout has finished with the previous customer, the following in the queue is served. You may presume that the customers arrive at the checkout at intervals that randomly vary between 1 and 4 minutes. The time spent with each customer also varies between 1 and 4 minutes. Be prepared to change this variable (from both ends). The simulation happens as follows: randomly draw the time of arrival of the first customer and place this customer in the queue. The event queue contains all the events (customer arrives in queue, customer leaves checkout) in chronological order. The first event is taken from the queue (and the time up to that point) 1) the customer arrived - add the customer to the queue - draw the arrival time of the following customer and insert it into the event queue 2) the customer leaves the checkout ? take the first customer in the queue ? draw the time it takes to serve the customer and insert the time the customer leaves into the event queue. Your program has to output all the events and their times in a file. In addition, simulators will gather different kinds of statistical data, so the program also has to report: how much the checkout is used (total of service times/total time), average waiting time (sum of waiting times / number of customers), longest queue at any moment, longest waiting time. When creating your program, be prepared to add more checkout points and to vary the distribution (or at least the variation) of arrival times and service times as e.g. command line parameters. In your implementation, use a dynamic queue data structure and its basic operations. You can implement the queue as e.g. a linked list. * 3. Flight-booking system The airline FlyCheap has recently started operations and it needs a flight-booking system with which their clerks (or their customers themselves) can book flights. The company only owns three planes and flies two routes no more than three times a day. Each plane takes a maximum of 30 passengers. For this airline, make a simple program with which it is possible to book a seat for a certain passenger, for a certain route and time. The calendar you create can cover three days, for example, or one week or a whole month. It is not necessary to use real dates. The passenger also needs to have a say in the seating number. This means that your program has to keep track of the booking situation for each plane. The information has to remain stored between running the program. The airline is especially interested in serving returning customers, so make the storage structure for customer information very fast (e.g. a binary tree). The program has to be able to output all the reservations of each named passenger very quickly. However, some more time may be spent on searching for a vacant seat on one of the flights, if you cannot think of a good data-structure solution. Use dynamic data structures to implement your system, so that the company may easily substitute their planes with larger ones without having to change their software. You can implement the limits as command line parameters, for example, so that they can be changed for each run time without compiling. * 4. Register of employees Write a program that keeps a register over the employees of a company. You can assume that the names of the employees only contain letters, and that there are no two employees by the same name on the payroll. In addition to their names, the register contains the salaries of the employees and the year they started working at the company. Your program has to offer the following features: o ? adding an employee to the register If there is already a person by the same name in the register, the new employee is not added and the user receives a warning to that effect. o ? removing an employee from the register. If the employee cannot be found, the user is warned, but do not stop the program. o ? searching for an employee by their name. Output the employee?s salary and starting year. o ? saving employee data into a text file. o ? reading the data in the file. o ? end. If no changes have been saved, ask the user to accept and if necessary, save the data. Use a hash table according to the employees? names in your solution. * 5. Simulating a restaurant Implement a queue structure with linked lists. (Solutions using only arrays will not be accepted.) Use the structure to write a program that simulates the operations of a restaurant in the following way: there is a menu, from which patrons can order the dish they want. Each dish has its own preparation time. You can read the menu from e.g. a file. There are four chefs in the restaurant, and each of them can prepare two different dishes at the same time. Allow at least the number of chefs to vary as a command line parameter. When a patron orders a dish, his or her order is placed last in the order queue. When one of the chefs becomes available (has one or no dishes to prepare), he starts to prepare the first order in the order queue, and it is removed from the queue. The user of the program makes new orders and can move the clock of the simulation system e.g. one minute forward at a time, with a suitable command. The program shows when each dish is ready. Check exercise 3 ?Simulating a checkout point? for more simulation instructions. * 6. Family tree Write a program with which the user can store a family tree. The following data can be added to the family tree: people (name, date of birth, date of death), their relations with each other (both official marriages and unofficial liaisons ? the latter in order to keep track of the parents of children) and the children born out of each relationship. For simplicity?s sake, you can write the system so that each family member has a different name. Your program has to offer at least the following features: o ? adding a person (they can be added ?independently? or as someone?s child) o ? changing personal data o ? adding a relationship o ? outputting all the descendants of a given person o ? outputting all the ancestors of a given person o ? outputting all the registered relationships of a given person Your program may trust the sensibility of the input data. It does not have to check that no one is married to two people at once, for example, or that someone?s child is not older than the parents. The program must use dynamic memory reservation ? solutions based on only arrays will not be accepted. * 7. Help for a chef A friend of yours has decided to become a master chef, but he is always having trouble with his raw materials. Which is why last Sunday?s lasagne meal turned into tuna sandwiches, because there was no minced meat. No one could take this for very long, so help your friend by writing a program with which he can store recipes and foodstuffs, as well as check how much there is left of any given foodstuff. The user interface of the program may be line-based, it does not have to be a menu system that fills the whole screen. The database structure has to be based on dynamic memory allocation and use of pointers. A pure table implementation will not pass.