Discussion in 'Software' started by xusan, Nov 10, 2013.

  1. xusan


    Oct 30, 2013
    Likes Received:
    Problem statement

    A car journey consists of a set of towns and distances (nodes) that are visited in a particular sequence. We require a C++ program that ‘manages’ a collection of nodes and reports the total distance for a given journey. To achieve this the program will request the user to enter each town name and its distance from the last point entered. The first town name entered is ‘start’. When a town name entry of ‘end’ is encountered the program will output to the screen each of the towns visited and the total distance covered by the current journey. The following listing provides an example of how the program is to operate:

    Enter town> staRT
    Enter town> starT
    Enter town> west wyalong
    Enter distance from start> 140
    Enter town> forbes
    Enter distance from west wyalong> 110
    Enter town> paRKes
    Enter distance from forbes> 60
    Enter town> end

    Towns visited> west wyalong, forbes, parkes
    Distance travelled> 310

    Enter town> dubbo
    Enter distance from parkes> 110
    Enter town> end

    Towns visited> west wyalong, forbes, parkes, dubbo
    Distance travelled> 420

    Enter town> halt

    Towns visited> west wyalong, forbes, parkes, dubbo
    Distance travelled> 420

    Program Terminated.

    If ‘start’ is entered at any point for the town name it will cause the logging of towns and distances to be re-initialised. Thus if ‘start’ (any lower or upper case combination accepted) was the provided entry for the last prompt above it would cause the commencement of a new journey.

    An entry of ‘halt’ causes your program to terminate. Prior to terminating your program will list the towns in the current journey and the total accumulated distance via the linked structure. In effect an entry of ‘halt’ has the same effect as entering ‘end’ and then terminating.

    If an entry other than ‘start’, ‘halt’ or ‘end’ was provided then the new entry would be appended to those shown. Refer carefully to the example to note some potential entries that need to be handled by your program.

    In completing this assignment you must create a dynamically linked structure. The nodes in your linked structure will store as data a town name and a distance. In addition each node will need to maintain a pointer to the next node. If there is no next node, a null will be stored
    xusan, Nov 10, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.