CEG220: Introduction to C
Programming for Engineers – I
Section 2
Project 5: Object Modeling
Program Background:
This program will give you a “crash course” in data object modeling – representing real-life objects as elements in a computer program. For example, a bicycle can be represented as the following:
enum
BicycleDesignType { BAD_DESIGN, ENGLISH_RACING,
MOUNTAIN, ANTIQUE };
enum
GenderType { BAD_GENDER, UNISEX, FEMALE, MALE };
struct
BicycleType {
signed mIsValid : 2; // set to 0 if invalid, 1
if all of its members are
// correctly set, and -1 if any members are
incorrectly set
unsigned mExists : 1; // state characteristic –
does the pencil exist?
unsigned mIsBroken : 1; // state characteristic –
is the bicycle broken?
unsigned mHeight : 6; // physical characteristic
– height, in inches
unsigned mNumGears : 6;
// physical characteristic – number of gears
unsigned mHasTrainingWheels : 1; // state characterisitic
unsigned char *mColor; // physical characteristic - color field
BicycleDesignType mType;
// physical characteristic – type of bicycle based on design
GenderType mGender;
// physical characteristic – the gender
//
the bicycle was designed for
};
The entire structure provides a means of describing a bicycle; knowing each bit of information (no pun intended) inside the structure helps you visualize the bicycle. This structure models the characteristics of a bicycle. If you continue in the field of computer science, you will use object oriented programming languages, where libraries are built with this style of structure. Every object has a structure (similar to that of a struct) and a behavior (similar to the functions that you write that use this struct) integrated into a class.
Program Description:
Your task is to design a complex object, populate its structures with information from the user, do error-handling in case the user inputs bad values, and then put them into an array of pointers to this structure. (You may ask the user in advance how many objects will be added.) This array should be sorted according to one of the primary defining characteristics of your object (if the object is a Person, then the sort should be according to Last Name, then First Name). Before and after sorting, you should output the list of objects to a log file with a .txt extension, making sure to list in the log file which list of objects is which (sorted or unsorted).
Program Requirements:
1) Your program must comply with the class programming standard
2) You must submit a hand-written program specification detailing (1) your approach to solving the problem, (2) the algorithm(s) you used, and (3) justifying the data types and loops you have used
Grading Standard:
This project is worth 100 points. Please note that programs that do not compile or do not link will lose all points related to run-time requirements (examples of run-time requirements includes but is not limited to correct run output, handling certain cases adequately, etc.). Grading standard will be followed strictly:
25 points: Preparatory Requirements
· Compliance with class coding standard (15 points: 5 points each)
· adequate comments – clear, concise, useful; not excessive
· please note my structure above is commented, detailing what each component is; this is required under the class coding standard. If you reuse the structure as part of a library, you’ll know what the structure is by its name, its state variables by its members, and what the members are by their comments! The other reason to do so: in Visual C++ if you type an instance of a structure and use the . operator to dereference it, a list of all the members will pop up; if you write comments right after your variable names, the comments will also appear, saving you time.
· well-named identifiers
· follows program specification
· hand-written document / program specification (10 points)
· all algorithms designed properly and included in the spec
· Uses pseudo-code to express the problem and how to solve it
75 points: Run-time Requirements
· Structure is an adequate representation of the object (15 points)
· Dynamically allocated memory is deleted when no longer needed– NO MEMORY LEAKS (10 points)
· Has a default “constructor” function that initializes all values to valid values (ie. all integers to 0, all char * variables to NULL, etc.) (5 points)
· Uses qsort() correctly (5 points)
· Implements comparison operators correctly (5 points)
· Code is modularized (10 points)
· Run output (10 points)
Due Date:
This project is due on 11/17 at the beginning of class. This
program will not be accepted late, barring an emergency.