Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-30-2004, 09:12 AM   #1 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
Unhappy Need help with C++

I have problems with my C++ and this is the question. Feel free please write a program of it. I need solution for reference. thanks!
it seems simple but not to a newbie like me Please help.

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 information stored about them in a record;
1. Given name(s) of the license holder. (Not more then 128 characters (may have spaces))
2. Surname of the license holder. (Not more then 128 characters (may have spaces))
3. Driver license number.
4. The sex of the license holder.
5. The residential address of the license holder. (Not more then 256 characters (may have spaces))
6. The registration number of the car the license holder drives. (A combination of characters and numbers. The string must be six long.)

The current system allows users to add new license holders, modify details about pre-existing license holders and remove a license holder by entering the license number.

Your job is to write a C++ program to replace the pre-existing system. In doing so your program must;

1. Allow users to add new license holders to the system.
2. Allow users to remove a license holder from the system.
3. Allow 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 length, therefore the C++ type string cannot be used in the implementation. The first time the program is run, there is no data file in the file system. The file is a random access file used to store a collection of records about license 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 an 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 prompts the user to enter all details relevant 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 corresponding 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 as available.

Users can search/display/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 is 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 times.
ewic is offline   Reply With Quote
Old 09-30-2004, 09:36 AM   #2 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
Have to use fstream for this question. Should i use class or struct?
i'm lost! need a full program example.

fstream file;
file.open(*data.dat*; ios::app:|ios::out|ios::in);
file.read(char*)&d,sizeof(d));


it's some exam question before and I wonder whats the correct solution. I really need help here
ewic is offline   Reply With Quote
Old 09-30-2004, 12:04 PM   #3 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
HELPpppppppppppppppppppppppppppppp.......
ewic is offline   Reply With Quote
Old 09-30-2004, 12:31 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Which part don't you understand? What do you got so far?

Right now I am in the process of testing a complete and highly object oriented program wich closely resembles your exam. It is loaded with Design Patterns (even the famous MVC), and fine examples of how to deal with with file output. I need a few more days. Then you should be able to add file input, name length checking and everything to the application. It is actually ment for a tutorial, planned for december.
Like I mentioned, you will have quite some work left. But the overall structure is there.

However, I am not going to write a complete and exhaustive application like you defined in your post. No one is. Nowhere. Work towards it yourself and ask for help if you can't move on.

Now this:
Don't draw attention like that again. I'm not upset. But it shows a most dramatic version of communicational skills.

You could start already:
What are we talking about?
We are talking about a database filled with LicensedDriver persons and every single LicensedDriver has these properties:
- First names.
- Last names.
- Various ID's like a license number.
- Various standard personal data.

Lets define a LicensedDriver:
Code:
#include <string>

using namespace std;

class LicensedDriver
{
public:
   string FirstName;
   string Surname;
   string LicenseNo;
   bool sex; //true = male
   /* ...etcetera... */
};
One instance is one licensed driver.

We are also talking about a database. This is our real problem domain (= what we are interesting in eventually).
Code:
#include "LicensedDriver.h"
#include <vector>

using namespace std;

class LicDriverDBase
{
public:
   LicDriverDBase();
   void createDB(); //We use this to load the file from disk and store in LD
   vector<LicensedDriver>& getDB(); //So the engine can access the DB.
private:
  vector<LicensedDriver> LD; //We store all the LD instances here.
};
Etcetera.

Now we need a controller. Basically that is a database engine. Controllers/engines do all the smart things once the database has been created.
Code:
#include "LicDriverDBase.h"

class LDEngine
{
public:
   LDEngine();
   void SortAndSearchLDField();
   void DoOtherSmartStuffHere();
};
Etcetera.

These three things are the *core* of what you are talking about. Get them right. Use int main() to test bit by bit. Don't make fancy menus or anything yet. That is the very last step (unless you work in a team).

Your task:
Make the first two classes work. Load a txt file from disk and store all the person data in a the phone book. Do it right, and you have 33% done already.

Ask if you're stuck.
__________________

Last edited by Valmont; 09-30-2004 at 01:01 PM.
Valmont is offline   Reply With Quote
Old 09-30-2004, 07:22 PM   #5 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
well, frankly speaking, I won't bother to ask for solutions if I haven't tried at all.
I'm weak with this file things and I gotta do like what the question asked. I checked the books but still I have no idea. The book have little or too simple of file addin,edit,delete data in files examples so it didnt help much. I'm lost.
ewic is offline   Reply With Quote
Old 09-30-2004, 07:38 PM   #6 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
#include <string>

using namespace std;

class LicensedDriver
{
public:
string FirstName;
string Surname;
string LicenseNo;
bool sex; //true = male
/* ...etcetera... */
};

how come it's not declared in private: ?

also, i only know a little about vector so im pretty lost with what you suggest me to use.
ewic is offline   Reply With Quote
Old 10-01-2004, 04:07 AM   #7 (permalink)
ewic
Registered User
 
Join Date: Sep 2004
Posts: 6
ewic is on a distinguished road
sad that i cant find the help i need here.
ewic is offline   Reply With Quote
Old 10-01-2004, 05:24 AM   #8 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Aren't you even capable of setting up a single class?
Code:
class LicensedDriver
{
public:
string FirstName;
string Surname;
string LicenseNo;
bool sex; //true = male
/* ...etcetera... */
};
Finish this then come back.
I'll show you later why they are public. Or if it feels better, make it a struct where all the fields are public by default. But just finish it and don't tell you don't get it. Just finish the class/struct. All you need to do is define every relevant personal data for now.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 10:43 PM
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 03:36 AM
For those who have Learned C from "The C Programming Lanuage" DemosthenesB Standard C, C++ 5 07-13-2003 01:22 AM
edit? anon Lounge 10 11-21-2002 04:02 PM


All times are GMT -8. The time now is 05:28 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting