Help me to solve this C++ problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • titi

    Help me to solve this C++ problem

    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.
  • Sumit Rajan

    #2
    Re: Help me to solve this C++ problem


    "titi" <wwwtay@yahoo.c om> wrote in message
    news:bfd7b308.0 402080651.325ec 547@posting.goo gle.com...[color=blue]
    > Question
    >
    > The road and traffic authority for a small country currently uses a
    > system to store information about all 'currently' licensed drivers.[/color]

    <SNIP>

    Please do not post homework questions.



    Regards,
    Sumit.


    Comment

    • Matthew Burgess

      #3
      Re: Help me to solve this C++ problem

      On 8 Feb 2004 06:51:41 -0800
      wwwtay@yahoo.co m (titi) wrote:

      Did you read the question before you posted it? Specifically:
      [color=blue]
      > Your job is to write a C++ program to replace the pre-existing system.[/color]
      ^^^^

      When you have a specific problem with *your* program then post the
      smallest relevant snippet of compilable code that you're having problems
      with, along with the input, expected output and actual output you're
      getting. We don't do homework here!

      Regards,

      Matt.

      Comment

      • osmium

        #4
        Re: Help me to solve this C++ problem

        titi writes:
        [color=blue]
        > The road and traffic authority for a small country currently uses a
        > system to store information about all 'currently' licensed drivers.[/color]
        <snip>

        This is going to take some time. I think a common mistake of beginners is
        trying to do it "right" in the first attempt. This results in a lot of
        typing, a lot of syntax errors, and a lot of fussing over details of things
        that eventually get thrown away; with the result of wasting huge amounts of
        time. (For example the warning about checking for valid data.) I would
        start with only a minimal subset of data fields. Last name, simple one part
        name such as Smith (as distinct from von Neuman) and license number might
        be enough. BTW the thing about the old existing program seems to be mainly
        noise to confuse you. Get the simple thing working to establish confidence
        that the paths and methods will work, then start fleshing it out with
        details. Note that a surname can change when a woman marries. I see a
        menu, a class to hold the data and an ordinary array of these classes in
        *main*. Note that C++ often defaults to do the opposite of what you expect
        WRT white space.

        This program is going to be 90% bulk and 10% useful and interesting "stuff".


        Comment

        • John Harrison

          #5
          Re: Help me to solve this C++ problem


          "osmium" <r124c4u102@com cast.net> wrote in message
          news:c05ncd$12q 0a3$1@ID-179017.news.uni-berlin.de...[color=blue]
          > titi writes:
          >[color=green]
          > > The road and traffic authority for a small country currently uses a
          > > system to store information about all 'currently' licensed drivers.[/color]
          > <snip>
          >
          > This is going to take some time. I think a common mistake of beginners is
          > trying to do it "right" in the first attempt. This results in a lot of
          > typing, a lot of syntax errors, and a lot of fussing over details of[/color]
          things[color=blue]
          > that eventually get thrown away; with the result of wasting huge amounts[/color]
          of[color=blue]
          > time.[/color]

          It's no use, no only do newbies always make this mistake, they never, ever
          listen to anyone who tells them to do different. At least that's my
          experience from this newsgroup.

          john



          Comment

          • Mike Wahler

            #6
            Re: Help me to solve this C++ problem


            "titi" <wwwtay@yahoo.c om> wrote in message
            news:bfd7b308.0 402080651.325ec 547@posting.goo gle.com...[color=blue]
            > Question[/color]

            The below is not a question, but apparently simply a
            reproduction of your assignment.

            Go ahead and try to do it (break it down into small pieces,
            then you won't be overwhelmed).

            I've inserted a few general remarks below.
            [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;
            > 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.[/color]
            [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]

            Hmm, I own four automobiles, and drive each at various times.
            I wonder how that's supposed to be handled ? :-)
            [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.
            >
            > 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.[/color]
            [color=blue]
            > Records a fixed lenght, therefore the C++ type string cannot be used
            > in the implementation.[/color]


            I see nothing in this specification that would prevent using the
            std::string type to represent textual data.
            [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.[/color]

            The preferred "C++ way" of storing such 'collections' of same-type
            objects is to use a container (e.g. std::vector) rather than an
            array. But I suppose you should go ahead and use an array, if
            it's required by the assignment.

            [color=blue]
            >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.[/color]

            Note: using a container would eliminate the need for such an
            arbitrary restriction. (Yes, an array could be dynamically
            allocated, and expanded as needed, but that gets to be a mess
            rather quickly.) Containers Are Cool. :-)
            [color=blue]
            > 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.[/color]

            Hmmm, no requirment or check that a driver's license number be
            unique?
            [color=blue]
            >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]

            As should any program. Validating input is very often a large
            part of a program's code.

            -Mike


            Comment

            • Thomas Matthews

              #7
              Re: Help me to solve this C++ problem

              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 "enumeratio n")
              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_REGISTRATIO N_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:

              C++ Faq: http://www.parashift.com/c++-faq-lite
              C Faq: http://www.eskimo.com/~scs/c-faq/top.html
              alt.comp.lang.l earn.c-c++ faq:

              Other sites:
              http://www.josuttis.com -- C++ STL Library book
              http://www.sgi.com/tech/stl -- Standard Template Library

              Comment

              • osmium

                #8
                Re: Help me to solve this C++ problem

                Mike Wahler writes:
                [color=blue]
                > Hmm, I own four automobiles, and drive each at various times.
                > I wonder how that's supposed to be handled ? :-)[/color]

                There are very few countries that have only 500 citizens. So might this be
                for an imaginary country, perhaps????
                [color=blue][color=green]
                > > Records a fixed [length], therefore the C++ type string cannot be used
                > > in the implementation.[/color][/color]
                [color=blue]
                > I see nothing in this specification that would prevent using the
                > std::string type to represent textual data.[/color]

                I see *HUGE* problems in using a C++ string! You can not do random access
                to a file with variable length records. That is *very clearly* the intent
                of the problem!


                Comment

                • Mike Wahler

                  #9
                  Re: Help me to solve this C++ problem


                  "osmium" <r124c4u102@com cast.net> wrote in message
                  news:c065ls$131 iik$1@ID-179017.news.uni-berlin.de...[color=blue]
                  > Mike Wahler writes:
                  >[color=green]
                  > > Hmm, I own four automobiles, and drive each at various times.
                  > > I wonder how that's supposed to be handled ? :-)[/color]
                  >
                  > There are very few countries that have only 500 citizens. So might this[/color]
                  be[color=blue]
                  > for an imaginary country, perhaps????
                  >[color=green][color=darkred]
                  > > > Records a fixed [length], therefore the C++ type string cannot be used
                  > > > in the implementation.[/color][/color]
                  >[color=green]
                  > > I see nothing in this specification that would prevent using the
                  > > std::string type to represent textual data.[/color]
                  >
                  > I see *HUGE* problems in using a C++ string![/color]

                  I don't, unless a bit of thought is a 'huge problem' :-)
                  [color=blue]
                  > You can not do random access
                  > to a file with variable length records.[/color]

                  Using std::string doesn't require variable length records.
                  [color=blue]
                  > That is *very clearly* the intent
                  > of the problem![/color]

                  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.


                  Comment

                  • osmium

                    #10
                    Re: Help me to solve this C++ problem

                    Mike Wahler writes:
                    [color=blue]
                    > "osmium" <r124c4u102@com cast.net> wrote in message
                    > news:c065ls$131 iik$1@ID-179017.news.uni-berlin.de...[color=green]
                    > > Mike Wahler writes:
                    > >[color=darkred]
                    > > > Hmm, I own four automobiles, and drive each at various times.
                    > > > I wonder how that's supposed to be handled ? :-)[/color]
                    > >
                    > > There are very few countries that have only 500 citizens. So might this[/color]
                    > be[color=green]
                    > > for an imaginary country, perhaps????
                    > >[color=darkred]
                    > > > > Records a fixed [length], therefore the C++ type string cannot be[/color][/color][/color]
                    used[color=blue][color=green][color=darkred]
                    > > > > in the implementation.[/color]
                    > >[color=darkred]
                    > > > I see nothing in this specification that would prevent using the
                    > > > std::string type to represent textual data.[/color]
                    > >
                    > > I see *HUGE* problems in using a C++ string![/color]
                    >
                    > I don't, unless a bit of thought is a 'huge problem' :-)
                    >[color=green]
                    > > You can not do random access
                    > > to a file with variable length records.[/color]
                    >
                    > Using std::string doesn't require variable length records.
                    >[color=green]
                    > > That is *very clearly* the intent
                    > > of the problem![/color]
                    >
                    > 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.[/color]

                    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.


                    Comment

                    • Mike Wahler

                      #11
                      Re: Help me to solve this C++ problem


                      "osmium" <r124c4u102@com cast.net> wrote in message
                      news:c06dfq$132 3cn$1@ID-179017.news.uni-berlin.de...[color=blue]
                      > Mike Wahler writes:
                      >[color=green]
                      > > "osmium" <r124c4u102@com cast.net> wrote in message
                      > > news:c065ls$131 iik$1@ID-179017.news.uni-berlin.de...[color=darkred]
                      > > > 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[/color][/color][/color]
                      this[color=blue][color=green]
                      > > be[color=darkred]
                      > > > for an imaginary country, perhaps????
                      > > >
                      > > > > > Records a fixed [length], therefore the C++ type string cannot be[/color][/color]
                      > used[color=green][color=darkred]
                      > > > > > 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![/color]
                      > >
                      > > I don't, unless a bit of thought is a 'huge problem' :-)
                      > >[color=darkred]
                      > > > You can not do random access
                      > > > to a file with variable length records.[/color]
                      > >
                      > > Using std::string doesn't require variable length records.
                      > >[color=darkred]
                      > > > That is *very clearly* the intent
                      > > > of the problem![/color]
                      > >
                      > > 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.[/color]
                      >
                      > You obviously have a fondness for complexity that I do not share. Tools[/color]
                      are[color=blue]
                      > there to *help* you. If you have to apply a work-around, pick up another
                      > tool instead of applying a patch.[/color]

                      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


                      Comment

                      • Jerry Coffin

                        #12
                        Re: Help me to solve this C++ problem

                        In article <c065ls$131iik$ 1@ID-179017.news.uni-berlin.de>, r124c4u102
                        @comcast.net says...

                        [ ... ]
                        [color=blue]
                        > I see *HUGE* problems in using a C++ string! You can not do random access
                        > to a file with variable length records.[/color]

                        Nonsense!
                        [color=blue]
                        > That is *very clearly* the intent of the problem![/color]

                        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.

                        Comment

                        • Jonathan Turkanis

                          #13
                          Re: Help me to solve this C++ problem

                          "titi" <wwwtay@yahoo.c om> wrote in message
                          news:bfd7b308.0 402080651.325ec 547@posting.goo gle.com...[color=blue]
                          > Question
                          >
                          > The road and traffic authority for a small country currently uses a
                          > system to store information about all 'currently' licensed drivers.
                          >[/color]
                          [color=blue]
                          >
                          > Your program should perform the appropriate checks to ensure valid
                          > input at ALL time.[/color]

                          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


                          Comment

                          • Roger Leigh

                            #14
                            Re: Help me to solve this C++ problem

                            wwwtay@yahoo.co m (titi) writes:
                            [color=blue]
                            > Question[/color]

                            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! =-----

                            Comment

                            • osmium

                              #15
                              Re: Help me to solve this C++ problem

                              Jerry Coffin writes:

                              [Osmium writes:]
                              [color=blue]
                              > [ ... ]
                              >[color=green]
                              > > I see *HUGE* problems in using a C++ string! You can not do random[/color][/color]
                              access[color=blue][color=green]
                              > > to a file with variable length records.[/color]
                              >
                              > Nonsense!
                              >[color=green]
                              > > That is *very clearly* the intent of the problem![/color]
                              >
                              > 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.[/color]

                              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:[color=blue]
                              >Records [are] fixed [length], therefore the C++ type string cannot be used
                              >in the implementation[/color]

                              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.




                              Comment

                              Working...