Question
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;
1. Given name(s) of the license holder.(not more than 128 char (may
have spaces)).
2. Surname of the license holder.(Not more then 128 same like above).
3. Driver license number.
4. The sex of the license holder.
5. The residental address of the license holder.(Not more then
128)same.
6. The registration number of the car the license holder drivers.(A
combination of char and numbers. The string must be six long.)
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.
Your job is to write a C++ program to replace the pre-existing system.
In doing so your program must;
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. 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.
Jul 22 '05
20 2689
"osmium" <r1********@com cast.net> wrote in message
news:c0******** *****@ID-179017.news.uni-berlin.de... Mike Wahler writes:
"osmium" <r1********@com cast.net> wrote in message news:c0******** *****@ID-179017.news.uni-berlin.de... Mike Wahler writes:
> Hmm, I own four automobiles, and drive each at various times. > I wonder how that's supposed to be handled ? :-)
There are very few countries that have only 500 citizens. So might
this be for an imaginary country, perhaps????
> > Records a fixed [length], therefore the C++ type string cannot be used > > in the implementation.
> I see nothing in this specification that would prevent using the > std::string type to represent textual data.
I see *HUGE* problems in using a C++ string!
I don't, unless a bit of thought is a 'huge problem' :-)
You can not do random access to a file with variable length records.
Using std::string doesn't require variable length records.
That is *very clearly* the intent of the problem!
const std::streamsize name_width(20); std::string name("Mike"); std::fstream fs("filename") ; fs << std::left << std::setw(name_ width) << name;
You were saying? :-)
-Mike P.S. Alternatively, if using fstream::read / fstream::write, one can build the character buffer by e.g. << into a stringstream and passing its 'str().c_str()' member, or sprintf() into the buffer directly, using an appropriate length specifier in the format string.
You obviously have a fondness for complexity that I do not share. Tools
are there to *help* you. If you have to apply a work-around, pick up another tool instead of applying a patch.
I would not call it a 'patch'.
Exploit std::string's ease of use and robustness everywhere
in the code, apply a single 'setw()' manipulator for persistence
in a fixed-length-record file.
Mucking around with arrays when 'std::string' is so obviously superior,
is what I'd call a 'patch' in C++.
But I suppose we all have our own philosophies and opinions ...
-Mike
In article <c0************ *@ID-179017.news.uni-berlin.de>, r124c4u102
@comcast.net says...
[ ... ] I see *HUGE* problems in using a C++ string! You can not do random access to a file with variable length records.
Nonsense!
That is *very clearly* the intent of the problem!
The original statement of the problem does specifically say that records
are to be of a fixed length, and "therefore the C++ string type can't be
used."
If student does succeed in getting somebody to solve his homework for
him, he will apparently have done his homework just as well as (if not
better than) the ignorant boob who's teaching this nonsense.
--
Later,
Jerry.
The universe is a figment of its own imagination.
"titi" <ww****@yahoo.c om> wrote in message
news:bf******** *************** ***@posting.goo gle.com... Question
The road and traffic authority for a small country currently uses a system to store information about all 'currently' licensed drivers. Your program should perform the appropriate checks to ensure valid input at ALL time.
Everyone assumes this is a homework assignment. I'll give you the
benfit of the doubt and assume you have read the FAQ and would not ask
other to do your assignment for you.
I conclude that you have been hired by a very small impoverished
country which cannot afford an experienced programmer. Which country
are you working for? Be sure they pay you in advance!
Jonathan ww****@yahoo.co m (titi) writes: Question
Where!?
--
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jerry Coffin writes:
[Osmium writes:] [ ... ]
I see *HUGE* problems in using a C++ string! You can not do random
access to a file with variable length records. Nonsense!
That is *very clearly* the intent of the problem!
The original statement of the problem does specifically say that records are to be of a fixed length, and "therefore the C++ string type can't be used."
If student does succeed in getting somebody to solve his homework for him, he will apparently have done his homework just as well as (if not better than) the ignorant boob who's teaching this nonsense.
I agree that the exercise could have been worded more elegantly. But how
many of us can write a perfect document of that length? You are not doing
the student any favor by making a post such as this. When there are two
sentences and then a blanket "nonsense" it is hard for a novice to figure
out exactly *what* is nonsense. You can not (or at the very least should
not) do random access to a file with variable length records. That is not
nonsense. And the exercise does explicitly state that it is a random access
file. (I hadn't really noted that when I made my earlier post, I deduced it
from the content.) I assume you knew what the instructor meant, why
purposely misunderstand him and then call him an ignorant boob, besides?
To the OP: the instructor does not mean that you can't converse with the
user via the C++ string, he means you should not save *that C++ string* to a
file. Or a C string either, for that matter. The records on the external
medium must be fixed length. Strictly speaking, he was not entitled to use
the word "therefore" .
I would replace this:Records [are] fixed [length], therefore the C++ type string cannot be used in the implementation
with this:
Records are fixed length on the external medium. Thus you should not
directly store variable length fields, such as C or C++ strings, in the
file.
"osmium" <r1********@com cast.net> wrote You can not (or at the very least should not) do random access to a file with variable length records.
Hogwash! Random access on variable-length records has existed since the early
days of computing, continues to this day, and is taught in the very first data
file management classes in any reputable university. All you need is an index
that gives you the start of the record and you can seek to it and retrieve it.
Here's a naively implemented snippet (without noisy error-checking):
int VRL::readRecord (const KEY_T & key, void * result, long maxLen)
{
long bytePos = getBytePos(key) ;
if (0 > bytePos) {
return -1;
}
fseek(m_f, bytePos, SEEK_SET);
long recLen;
fread(&recLen, sizeof(recLen), 1, m_f);
fread(result, min(recLen, maxLen), 1, m_f);
return 0;
}
Please don't assert that something is possible or impossible unless you
understand the field on which you're commenting.
Claudio Puviani
In article <c0************ *@ID-179017.news.uni-berlin.de>, r124c4u102
@comcast.net says...
[ ... ] I agree that the exercise could have been worded more elegantly. But how many of us can write a perfect document of that length? You are not doing the student any favor by making a post such as this. When there are two sentences and then a blanket "nonsense" it is hard for a novice to figure out exactly *what* is nonsense. You can not (or at the very least should not) do random access to a file with variable length records.
This is what is nonsense -- you can, and many people DO use random
access on files with variable length records on an extremely regular
basis. Saying otherwise is nothing short of pure, unadulterated
nonsense.
That is not nonsense.
Repeating the same nonsense won't change it into something else. Look
at any decent database and you'll find that 1) it will support variable
length records, and 2) it will be able to do random access on those
records.
This isn't any sort of magic -- it's the simple result of a perfectly
normal thing called an index. It works pretty much the way an index in
a book does: you look something up in the index, and it tells you were
that data resides. You then do a seek directly to that point (i.e.
random access).
And the exercise does explicitly state that it is a random access file. (I hadn't really noted that when I made my earlier post, I deduced it from the content.) I assume you knew what the instructor meant, why purposely misunderstand him and then call him an ignorant boob, besides?
Because somebody teaching a course in programming who doesn't know that
strings can be written as fixed-width fields and also doesn't know about
how to index a file is clearly ignorant should be restricted to teaching
small children how to tie their shoes, or some other subject of which he
has at least some grasp of the most basic facts.
with this: Records are fixed length on the external medium. Thus you should not directly store variable length fields, such as C or C++ strings, in the file.
This is still pure nonsense. It still ignores the possibilities of
indexing and/or writing a string out in a fixed-width field. If you
want to say "variable-length records are beyond what we're covering
right now", so be it.
At least IMO, simplifying a problem to the point that it's approachable
is perfectly reasonable. Lying is a drastically different story.
--
Later,
Jerry.
The universe is a figment of its own imagination.
"Claudio Puviani" <pu*****@hotmai l.com> wrote in message
news:79******** ************@ne ws4.srv.hcvlny. cv.net... "osmium" <r1********@com cast.net> wrote You can not (or at the very least should not) do random access to a file with variable length records. Hogwash! Random access on variable-length records has existed since the
early days of computing, continues to this day, and is taught in the very first
data file management classes in any reputable university. All you need is an
index that gives you the start of the record and you can seek to it and retrieve
it. Here's a naively implemented snippet (without noisy error-checking):
int VRL::readRecord (const KEY_T & key, void * result, long maxLen) { long bytePos = getBytePos(key) ;
if (0 > bytePos) { return -1; }
fseek(m_f, bytePos, SEEK_SET);
long recLen;
fread(&recLen, sizeof(recLen), 1, m_f);
fread(result, min(recLen, maxLen), 1, m_f);
return 0; }
Please don't assert that something is possible or impossible unless you understand the field on which you're commenting.
Your reply seems a little harsh to me.
The general usage of the term "random access" for files usually means the
direct access of records, usually by relative record number. Since the
location of a logical record may include deblocking andcalculation of track,
sector location, it is done by having fixed length records and calculating
the track, sector location, reading the block, and locating the record
within the block.
The use of an index for each record in order to seek to the record's
starting location is not usually called "random access." Rather, it is an
indexed file.
Consider the early IBM implementations : BDAM (basic direct access method) is
a "random access" method. ISAM (Indexed sequential access method) uses the
indexed file technique.
It would be better to identify the fact that the use of "random access" has
unclear meaning and should be clarified by using some different term
depending on what was meant. I'd have said direct access, myself (any
program that randomly accesses records won't be all that useful, except
possibly for statistical applications).
Would you jump on me if I said arrays cannot be extended by adding elements
to them? (You can allocate a new, larger array, copy the elements to that
and it has been "extended." Followed by: "Please don't assert that something
is possible or impossible unless you understand the field on which you're
commenting.")
--
Gary
"Gary" <gl*******@comc ast.net> wrote
"osmium"> You can not (or at the very least should not) do random access
"osmium"> to a file with variable length records.
"Claudio Puviani"> Hogwash!
"Gary> Your reply seems a little harsh to me."
I'm open to a more politically-correct adjective, but I stand by my statement. The general usage of the term "random access" for files usually means the direct access of records, usually by relative record number.
That's a seriously incomplete definition. The term "random access" describes the
ability to jump to any part of the file, as opposed to "sequential access" which
forces you to read through unrelated data before accessing what you need.
Whether the byte position or record number is derived from an absolute value, a
hash, an index lookup, or any other mechanism is completely irrelevant.
It would be better to identify the fact that the use of "random access" has unclear meaning and should be clarified by using some different term depending on what was meant. I'd have said direct access, myself
You're talking about two different things. "Direct/indirect access" and
"random/sequential access" are orthogonal concepts.
Would you jump on me if I said arrays cannot be extended by adding elements to them? (You can allocate a new, larger array, copy the elements to that and it has been "extended." Followed by: "Please don't assert that something is possible or impossible unless you understand the field on which you're commenting.")
That's quite the non sequitur. Ok, I'll play along. No I won't jump on you for
saying that "2+2=4"desp ite the fact that I jumped on someone for asserting that
the earth is flat.
Claudio Puviani
Claudio Puviani <pu*****@hotmai l.com> wrote in message
news:4k******** ************@ne ws4.srv.hcvlny. cv.net... "Gary" <gl*******@comc ast.net> wrote
"osmium"> You can not (or at the very least should not) do random access "osmium"> to a file with variable length records. "Claudio Puviani"> Hogwash! "Gary> Your reply seems a little harsh to me."
I'm open to a more politically-correct adjective, but I stand by my
statement. The general usage of the term "random access" for files usually means
the direct access of records, usually by relative record number. That's a seriously incomplete definition. The term "random access"
describes the ability to jump to any part of the file, as opposed to "sequential access"
which forces you to read through unrelated data before accessing what you need. Whether the byte position or record number is derived from an absolute
value, a hash, an index lookup, or any other mechanism is completely irrelevant.
It would be better to identify the fact that the use of "random access"
has unclear meaning and should be clarified by using some different term depending on what was meant. I'd have said direct access, myself You're talking about two different things. "Direct/indirect access" and "random/sequential access" are orthogonal concepts.
Claudio Puviani
If the instructor had meant the use of an index, the following would not
have made any sense:
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.
If he was talking about an indexed file he would simply have said "Remove
the entry from the index". This paragraph makes his intent crystal clear,
regardless of the fact that he may have used an imperfectly chosen word
here or there. The elements are munged to provide
privacy/security/whatever. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: the_proud_family |
last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com
I can't get the ball to go up right side and then I need it to turn
around and keep turning until velocity=0 I have been at it for the
past 2 weeks now i give up and call for help. Please if anyone can
gide me through i will be so grateful!! I have pasted my code below
|
by: stu_gots |
last post by:
I have been losing sleep over this puzzle, and I'm convinced my train
of thought is heading in the wrong direction. It is difficult to
explain my circumstances, so I will present an identical make-believe
challenge in order to avoid confusing the issue further.
Suppose I was hosting a dinner and I wanted to invite exactly 12 guests
from my neighborhood. I'm really picky about that... I have 12 chairs
besides my own, and I want them all...
|
by: Alfonso Morra |
last post by:
Hi,
I have some code from an example, that I want to retrofit into my
project. The code from the example has the following line:
SharedAppenderPtr myAppender( new RollingFileAppender("MyAppender"))
I want to move this line of code to a constructor in a wrapper class, so
that I can determine the appropriate Appender name during the object's
|
by: Tito Brezovacki via .NET 247 |
last post by:
Hi.
The problem is very simple to describe, but tough to solve :(
I have a printer that doesn't print on win98 using the usualprocedures (print() in C#) . I could barely get it to work on xpby the way. (the xpsp2b helped).
Then I realized I could use a com port manipulation to send infothrough to it ! Of course, .net doesn't have what i need so ihad to use .
Everything worked fine on XP but all hell broke on Win98. Irealized that the...
|
by: Adrian |
last post by:
This is off topic - however, I badly need to solve this problem.
A program has been installed in Program Files of an W98 machine.
Subsequently the program was removed from Program Files, not in the proper
way though, it was just deleted.
Trying to install a new version of the program, a message is returned to the
effect that the program already exists, which it does not.
Trying to remove the program with the the proper installer...
| |
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and efficient
navigating within Visual Studio 2005. Let's say your project (or
solution) has dozens of forms and hundreds or even thousands of
routines.
Two Questions:
1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
|
by: c |
last post by:
Hi everybody.
I'm working on converting a program wriiten on perl to C, and facing a
problem with concatenate strings.
Now here is a small program that descripe the problem, if you help me
to solve in this small code, I can solve it on my own program...you
don't want to have head-ache :-)
So, the problem excatly is, I built an array..just like this one.
|
by: Dhananjay |
last post by:
hello everyone
Do you have any information how to generate a tool using .net which is
used to translate the web page contents to html format.
Plz reply me asap
Thanks in advance
Dhananjay
|
by: SanjaiGandhi |
last post by:
Hi ...i am new to programing....pls help to overcome this program..
The Program is..:
if a = 557..using for loop or while or dowhile ..we have to get the
answer for 5+5+7..that is what ever numbers we entered to a..that
should be added..
for eg if a = 34 the answe should be 7 that is 3+4
using % and / we can solve this problem..pls help me to get the
problems
|
by: Kyote |
last post by:
I'm trying to make, what I thought, would be a simple application.
This application will help me organize files I have a lot of, on my
computer(ebooks, pictures, etc..). I'm currently dealing with over
25,000 files in a couple hundred directories.
I'm currently trying to collect the list using this
Try
For Each foundfile As String In
My.Computer.FileSystem.GetFiles(mySource,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |