titi wrote:[color=blue]
> Question[/color]
Since your a newbie and this is to demonstrate simple C++,
I will show you how using advanced C++ techniques.
DO YOUR OWN HOMEWORK.
[color=blue]
> The road and traffic authority for a small country currently uses a
> system to store information about all 'currently' licensed drivers.
>
> A licensed driver has the following info stored about them in a
> record;[/color]
The above sentence is a clue that some information will always
be represented together as a unit. In C++ we would place that
in a structure or class. Search the index of your text book
for "struct" and "class". Learn the differences between the
two.
[color=blue]
> 1. Given name(s) of the license holder.(not more than 128 char (may
> have spaces)).[/color]
In the above sentence, the keywords "name", "char" and "spaces"
indicates you are using a text variable. The "not more than 128
char" implies a maximum length of text. Your options are:
array of 128 chars.
pointer to a char
std::string.
I choose the std::string type since it is easy to use. Your
mileage may differ.
The above sentence is decribing a unit of information in the
structure, often called a "field".
[color=blue]
> 2. Surname of the license holder.(Not more then 128 same like above).[/color]
The keyword "Surname" indicates a text variable. See above.
[color=blue]
> 3. Driver license number.[/color]
Hmm, tricky. The "number" implies either an integer or a
floating point variable. Typically, driver license numbers
are unsigned integer. However, if the "numbers" contain
"-" (dashes), periods, or spaces, they may better be represented
as a text field. Your choice here.
I'll choice text which implies std::string.
[color=blue]
> 4. The sex of the license holder.[/color]
Another field with possibilities. The sex or gender of
a person is either male or female. This can be represented
as:
bool (let male == true, female == false or vice-versa).
integer (ex. 1 == male, 2 == female).
char ('m' == male, 'f' = female)
enumeration (enum Gender {MALE, FEMALE};)
class; (search the web for "class" and "enumeration")
I'll choose enumeration: enum Gender {MALE, FEMALE};
[color=blue]
> 5. The residental address of the license holder.(Not more then
> 128)same.[/color]
Addresses are ususally represented as text fields.
I'll choose std::string.
[color=blue]
> 6. The registration number of the car the license holder drivers.(A
> combination of char and numbers. The string must be six long.)[/color]
In requirements, the term "string" denotes a text field.
Here the requirement says that there must be 6 chars in each
field. One could interpret this as "at least 6", in which
a std::string could be used as long as the length is 6 or less.
In summary:
/* 4 */ enum Gender {MALE, FEMALE};
/* 6 */ const unsigned int MAX_REGISTRATION_LENGTH = 6;
class License_Info
{
/* 1 */ std::string given_name;
/* 2 */ std::string surname;
/* 3 */ std::string id; // identifier or number
/* 4 */ Gender sex;
/* 5 */ std::string resident_addr;
/* 6 */ std::string registration;
};
The numbers in C style comments refer to the requirement
number in the assignment.
[color=blue]
>
> The current system allow users to add new license holders, modify
> details about prexisting license holders and remove a license holder
> by entering the license number.[/color]
The above sentence lists the functionalities of the program:
add new license holder
modify existing license holder's information
remove a license holder
_You_ will have to create a user-interface (often called a menu)
to allow the user to select one of the above actions, and perhaps
an extra one to exit or stop the program.
[color=blue]
> Your job is to write a C++ program to replace the pre-existing system.
> In doing so your program must;[/color]
This is not really clear given the requirements.
Were you given an existing program to modify?
Or are the next set of function to be added to your new program?
I would clarify this with the instructor or the one who handed
out the requirements. ALWAYS CLARIFY ANY AMBIGUITIES IN
REQUIRMENTS BEFORE CODING.
[color=blue]
> 1.Allow user to add new license holders to the system.
> 2.Allow user to remove the license holder from the system.
> 3. Allow the users to search on a license number, display and
> potentially modify a matched record.
>
> The program is an interactive and menu driven. A user can choose from
> a set of options to perform a particular action. It also to has
> persistent storage.Each license holder has one record in the system.
> Records a fixed lenght, therefore the C++ type string cannot be used
> in the implementation.[/color]
Bummer, can't use std::string because of the restriction above.
Oh well, just use fixed length arrays of char.
[color=blue]
> The first time the program is run, there is no
> data file in the file system. The file is a randoom access file used
> to store a collection of records about liccense holders. The name of
> this file is data.dat.
>
> If the file already exists when the program starts, you are to read
> the all records from the file, into array of records. You can assume
> the maximum size of the array is 500. That is at any given time, your
> system can hold a maximum of 500 license holders.
>
> During runtime a user may add new license records.When a user adds a
> new record, the program prompt the user to enter all details relevent
> to the record. The record is inserted into the first available slot in
> the array of records and written to the file immediately at the
> correseponding record location. If there are no available records an
> error is to be printed.
>
> When a user removes a record, all elements of the record are cleared
> and the record is marked as available. The corresponding record in the
> file is then marked available.
>
> Users can search/dispaly/modify a record. The search key is the
> license number. If there is a record with the license number matching
> the specified key, the record is displayed and the user given the
> option of modifying the record. A user can search for a record and
> display it without performing any modifications.
>
> Your program should perform the appropriate checks to ensure valid
> input at ALL time.[/color]
So, what is your issue with the assignment?
If there are any parts you don't understand, don't hesitate
clearifying them with your instructor. I have some instructors
where you need to get the clarifications in writing and notorized.
That way, when he/she changes his/her mind, you have proof.
Sorry, but I don't have the time now to write your program for
free. If you pay me, then I will write it for you.
My terms are $200.00 USD, payed in advance. Since you don't want
to write it, I'll assume you want me to deliver it too. So I
will need your instructor's email address and postal address to.
Many instructors require hard-copy in addition to an electronic
version.
Please let me know soon, as I have many current uses for the money.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library