CMSC 106 | Project #7 - Sim Car Dealer | Spring 2003 |
In this project you will write a program using structures and structures which contain other structures as members, arrays of structures, and functions with structure parameters, using both call-by-value and call-by-reference.
Your Car Configurator has been a great success with Monolithic Motors, so they have asked you to write a program to manage their car sales. Your program will keep track of the car sales at several dealers, managing the inventory of cars and the quotas for the salespeople.
The program begins by reading in a list of car dealers. Next it will read in a series of commands to stock the dealers with cars, hire salespeople and assign them quotas, and sell cars. Finally, it will print out the dealer inventories and the salespeople's sales figures.
The input file will be divided into two sections: the list of car dealers, and the list of commands. A description of each of these sections of the input file appears below.
####
".
Below is a list which could appear as the first section of
an input file.
The actual primary_input
file will be posted in the class posting
account.
Friendly_Fred Generous_George Courteous_Carl Honest_Hal Decent_Dan Frugal_Frieda Haggling_Harry Bargain_Bill Easy_Eddie ####
Assumptions:
Below is a list of commands which could appear
in the second section of an input file.
The actual primary_input
file will be posted in the class posting account.
THIS IS FOR FORMAT REFERENCE ONLY. ACTUAL PRIMARY DATA WILL BE POSTED. stock Friendly_Fred Road_Hog LX blanched_almond 18000 20700 stock Courteous_Carl Gas_Guzzler DX lemon_chiffon 15000 17800 hire Friendly_Fred 1249379516 5000 stock Generous_George Crash_Wagon EX light_salmon 16000 18000 stock Honest_Hal Heap_Mobile DX papaya_whip 17000 19000 stock Friendly_Fred Road_Hog DX blanched_almond 17000 19700 hire Friendly_Fred 3474317595 6000 stock Courteous_Carl Gas_Guzzler EX lemon_chiffon 15000 17800 stock Generous_George Crash_Wagon LX light_salmon 16000 18000 stock Honest_Hal Heap_Mobile EX papaya_whip 19000 22000 hire Friendly_Foo 4565358402 3000 stock Friendly_Fred Gas_Guzzler DX blanched_almond 18000 20700 stock Courteous_Carl Road_Hog EX lemon_chiffon 25000 27800 sell Friendly_Fred Gas_Guzzler DX lemon_chiffon 16000 sell Friendly_Foo Gas_Guzzler DX lemon_chiffon 16000 sell Friendly_Fred Crash_Wagon DX lemon_chiffon 16000 sell Honest_Hal Heap_Mobile DX lemon_chiffon 16000 sell Friendly_Fred Road_Hog DX blanched_almond 19000 sell Friendly_Fred Road_Hog DX blanched_almond 21700 stock Friendly_Fred Road_Hog DX blanched_almond 18500 20700.95 sell Friendly_Fred Road_Hog DX blanched_almond 21700
Assumptions:
Please notice that there is no limit to the number of commands that may be listed in this section, so you must process them one at a time rather than trying to read them all into an array and then process them. This section does not terminate with any special symbols.
Important: Individual cars must be stored using a Car structure. A dealer's inventory must be stored using an array of Model structures.
The stock command has 6 parameters:
The hire command has 3 parameters:
The sell command has 5 parameters:
In order to give the maximum opportunity for each salesperson to reach his or her quota, the salesperson with the lowest amount of sales credits vs. quota is selected. In other words, the program looks at the result of subtracting the quota from the sales credits for each salesperson at the dealer. The salesperson with the minimum value of this difference is selected. If there are no salespeople at this dealer, then the program prints the message:
No salesperson for dealer d.where d is the name of the dealer, and goes on to the next command.
After the salesperson is selected, the program searches the dealer's inventory for the car to be sold. The program looks at the array of Cars for the specified model type, trying to find a Car with the right trim and color. If there is more than one Car in the dealer's inventory with the right characteristics, then the one which was stocked first is selected. If there is no car in this dealer's inventory which matches the car to be sold, then the program prints a message of the form:
Car m t c not found at dealer d.where m is the model, t is the trim type, c is the color, and d is the name of the dealer, and goes on to the next command.
The salesperson receives a sales credit based on the relationship between the selling price, retail price, and invoice price.
After the sales credit has been computed for this sale, it is added to the total credit for this salesperson.
After the car has been sold, it is removed from the dealer's inventory.
If any command contains a dealer name which doesn't exist, the program prints a message of the form:
Dealer d not found.where d is the name of the dealer, and goes on to the next command.
The program continues reading and processing commands until the end of the input. After all of the commands have been processed, the program prints a report containing the inventory and quota information for each dealer. The dealers are listed in the order in which they were originally read in. For each dealer, the cars in the inventory are listed by model, with the models listed in the order in which they were originally stored. The cars are listed in the order in which they were originally put in stock. The salespeople are listed in the order in which they have achieved their quota, with the best performer listed first. Quota achievement is defined as the difference between the sales credit amount and the quota amount. Each salesperson ID is listed with the amount by which the sales credit is greater or less than the quota (negative value). If 2 salespeople have the same quota achievement, then the one with the smaller ID value is listed first. All of the items in the report must be aligned neatly in columns, as shown in the primary output file.
primary_output
file will be posted in the class posting account.
As usual, it is
important for you to check your output against ours using the diff
command.
Your program must contain (and use) at least eight separate structure functions. A structure function either has a structure as a parameter, a structure as its return value, or has a pointer to a structure as a parameter. To get more practice using functions with structures, and to make your program easier to develop and test, it is highly recommended that you write more than eight structure functions (that you write as many as possible). At least two of your structure functions must use call-by-value for their structure parameter(s) or must have a structure as their return value. At least two of the functions must use call-by-reference for their structures, so they must have pointers to structures as parameters, and they must access the structures through the pointers.
If your program doesn't contain, and call, at least eight structure functions, of the types indicated, it will be graded as if it does not work on the primary input- even if its output is correct.
All your C programs in this course should be written in ANSI C, which
means they must compile and run correctly with cc -std1 -trapuv
on the OIT
UNIX Class Cluster. You will lose credit if your program generates any
warning messages when it is compiled. Prototypes must appear for all
functions used, listed at the top of the program file.
You may use any ANSI C language features we have discussed in the course so far, plus anything we will discuss between now and the end of the semester, with the following exceptions:
goto
nor the continue
statement may be
used, and the break
statement may not be used in any loop.
exit()
library function may not be used at all, and at
most one return
statement may be used in any function,
including main
.
mem
can be used
Using any of these disallowed C features will result in losing credit.
Your program must have a comment near the top which contains your name, login ID, student ID, your section number, your TA's name, and an original description of the action and operation of the program. In addition, you must have a comment before each function, explaining its action and operation. Your program should be written using good programming style and formatting, as discussed in class and throughout your textbook. For this project, style is considered to consist of:
return
statements in any function
You may want to skip this section at first, read the rest of the project, and come back to study it carefully when you are about to begin writing your program.
The more you write functions to perform various manipulations on structures, the easier your code becomes to test. It is really recommended you use functions for each separate, discrete operation to be performed on any structure.
Here are some suggestions for possible functions. You do not have to use these, and you may use as many other functions as you want:
Do not use a global structure variable or array, like your book does in its example in Chapter 16! You will lose substantial credit if you use global variables in your project.
If you get an error from the first line of your first function involving a particular structure type, which identifies a syntax error right after the name of the structure type, you probably have declared the structure type after this function which uses it. All structure type definitions must precede the first use of a variable or parameter of that structure type.
Here are several other common compilation errors having to do with structures produced by the cc compiler on our class machines and what they mean:
Structure fields cannot be initialized in a structure type definition. See your class notes or text for the proper way to declare a structure variable with an initializer.
(where X is the name of a structure variable)
You are using the ->
operator with something which is a
structure, not a pointer to a structure. The ->
operator
only operates upon a pointer to a structure. Carefully draw a
picture of your structure variables, and look at how the statement
with the error is referencing them.
(where X is the name of a pointer variable)
This is the opposite of the above problem. You are using the . operator with something which is a pointer to a structure, not a structure.
You are using the .
operator directly in front of an array
subscript (i.e., x.[y]
). The .
operator selects a
field of a structure, so it must be followed by a field name, not a
subscript. Perhaps you are trying to refer to an element within an
array field, but you forgot the array field name after the .
and before the subscript.
(where X is the name of an array variable)
You are trying to assign something to the name of an array.
Perhaps you are trying to copy one character string to another, but
you have to use strcpy
since you cannot assign arrays.
(where X is the name of a variable being used as a function's return value)
You are probably trying to return an int from a function whose return type is a structure, not a number.
(where X is the name of a structure variable)
This is the opposite of the above problem. You are probably trying to return a structure from a function whose return type is int, not a structure.
(where X is the name of a structure variable)
You are trying to pass a structure to a call-by-reference structure function, which is expecting an argument which is a pointer to a structure.
(where X is the name of a structure variable)
This is the opposite of the above problem. You are trying to pass a pointer to a structure to a call-by-value structure function, which is expecting an argument which is a structure, not a pointer to a structure.
printf
statements if your code isn't
working, to find out where! You need to know this before you can
find out why the problem is occurring.
Frequently save backup copies of your program under different names or in different subdirectories, so even if you inadvertently delete your file or change things which you realize you shouldn't have, it's easy to recover a recent version.
Any evidence of unauthorized use of computer accounts or cooperation on projects will be submitted to the Student Honor Council, which could result in an XF for the course, suspension, or expulsion from the University. Projects are to be written INDIVIDUALLY. For academic honesty purposes, projects are to be considered comparable to a take-home exam. Any cooperation or exchange of ideas which would be prohibited on an exam is also prohibited on a project assignment, and WILL BE REPORTED to the Honor Council.
VIOLATIONS OF ACADEMIC HONESTY INCLUDE:
|
IT IS THE RESPONSIBILITY, UNDER THE UNIVERSITY HONOR POLICY, OF ANY STUDENT WHO LEARNS OF AN INCIDENT OF ACADEMIC DISHONESTY TO REPORT IT TO THEIR INSTRUCTOR.
Your project must be electronically submitted by the date above, to avoid losing credit as described on the syllabus. No projects more than two days late will be accepted for credit without prior permission or a valid medical excuse, as described on your syllabus. Only the project which you electronically submit, according to the procedures provided, can be graded; it is your responsibility to test your program and verify that it works properly before submitting. Lost passwords or other system problems do not constitute valid justifications for late projects, so do not put off working on your program or wait to submit it at the last minute!
Turn in your assignment using the ``submit'' program as before, except
using ``7'' for the project number. You are to submit only the .c file
containing your source code, not the executable version of your program!
If your program is in a file named ``p7.c'', submit would be run as
submit 7 p7.c
.
Before you submit your project, you must exactly follow the specific submission checklist in the ``Testing projects before submitting'' handout separately posted by your instructor!