please i just a hint in how to start doing this home work

Notes: There is no need to make use of arrays. In fact using arrays to store all customers' records is a bad design.
Interstate Motorway Pty Limited requires you to design a program that will produce customer statements for passing through E-way checkpoints of four toll stations (denoted by A, B, C and D respectively) distributed on the nationwide motorway. The charge of each pass is specified as follows
StationABCDCharge$2.20$2.80$2.30$3.80
These statements will be calculated from the checkpoint log file of the format 3435344 A 2005/02/22/08:22:414749038 A 2005/02/25/14:16:355186936 C 2005/02/28/08:34:533873242 D 2005/03/02/02:40:594749038 A 2005/03/05/14:16:354092191 A 2005/03/08/23:49:083435344 C 2005/03/11/08:22:414092191 C 2005/03/14/23:42:084749038 D 2005/03/17/14:16:353435344 A 2005/03/20/08:22:41...where the first column contains customer ids, the second column contains the toll stations and the last column contains the timestamps. Hence the first record in the above, for instance, indicates that the vehicle with tag number (i.e. customer id) 3435344 passed through toll station A at time 08:22:41 on 22nd February 2005.

In order that each statement carries also the customer's name and address, the address file will be provided in the form of 3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 21343873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 32054092191 @ T Peachey,32 Evan Street,Penrith NSW 27504749038 @ D Merritt,70 Albert Street,Werrington NSW 27474967987 @ R Bailey,102-47 Pardalote Avenue,Glenmore Park NSW 27455186936 @ S Galloway,8-121 Coreen Road,Scoresby VIC 3179...For the convenience of processing the log file for the statements, the address file and the log file will be first merged and then sorted line by line alphabetically to generate the toll data file, which will thus look like
3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 21343435344 A 2005/02/22/08:22:413435344 A 2005/03/20/08:22:413435344 B 2005/03/23/18:22:413435344 B 2005/04/10/28:22:413435344 C 2005/03/11/08:22:413435344 C 2005/05/10/14:22:413435344 C 2005/05/19/06:22:433435344 D 2005/05/01/01:26:413873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 32053873242 B 2005/03/29/02:40:593873242 B 2005/05/16/02:40:593873242 C 2005/04/07/22:40:593873242 D 2005/03/02/02:40:59...For instance, if an address file address.txt is mergered with a log file logfile.txt into a combined file combined.txt, then sorting the combined file will generate the needed toll data file tolldata.txt. Hence in this assignment, we will always assume that the input data are in the form of toll data file and simply forget about the existence of the log file and the address file.

In this assignment, you are required to design an algorithm in pseudocode for the solution of the problem and get it implemented in C++. Your implemented C++ program toll.cpp will read data in the format of the toll data file, i.e.

  • customer id as a word
  • toll station or '@' as a character
  • customer address or timestamp as the rest of the line

calculate the total toll charged for each customer, and produce an invoice statement for each customer who has a non-zero balance. A statement for each customer should include the following information

  1. Heading
  2. Customer's id, name and address
  3. Column heading: Date, Time, Station, Amount
  4. All records charged to the customer
  5. Total amount the customer owned in the statement

We note that if your program toll.cpp is compiled into toll.exe and the toll data file is tolldata.txt, then using piping toll.exe < tolldata.txt > statements.txtshould generate precisely the list of toll statements satisfying the above requirements. This means if you are using prompts for interative data input, you need to make sure that the prompts are sent to standard error device using cerr (instead of cout). This way, the prompts will not be piped into the output file statement.txt.
and thx

Recommended Answers

All 9 Replies

Welcome to Daniweb. The first hint will be to first start doing the assignment. Looks like you are intimidated by the assignment size, and are afraid to start. Once you start doing, you may find dead-ends, and then pose a specific question here.
Since this looks like an assignment on string handling, and file handling, you will have to look them up in your lecture notes and C++ reference book. You will have to read a single string, process it, do the calculations and move to the next string. Also since the use of arrays are discouraged, that means there should be little need to store the values of the toll-fee and you should be able to calculate the value and print it before continuing to the next customer.
Good luck.

thx for your reply
can i get you to answer me how to get the toll data print it out in my program from tolldata.txt
and thx

That will be asking me to do the file reading part of your assignment.

You Open the file
Do the following until the file is finished.
     Read a line
     Print the line
     Go to the Next line.

that's what i've done but i still need help because the output doesn't produce what i really need:sad: :sad: :sad:

#include <iostream>
using namespace std;
int main() {
 
    string id, id2, tp;
    char gate;
    int i=0, j=0, temp=0;
    float a , b,c,d, total =0;
    string adress, name, heading;
 
 
   heading = " Interstate Mototrway Pty Ltd invoice statements";
   cout << heading<<endl;
   cout <<"________________________________________________"<<endl;
 
   for (i=0; i< 36; i++)
   {
 
            if (i=0)
            {
                    cerr << "Cutomer id:";
                    cin >> id;
                    if(cin.fail())
                    break;
                    cerr << " Station gate:";
                    cin >> gate;
                    if (cin.fail())
                    break;
                    cerr << "Comments: ";
                    cin >> ws;;
                    getline(cin, name);
                    getline(cin, adress);
                    if (cin.fail()) 
                    break;
                    cout << " 1. Customer ID:"<<id<<endl;
                    cout << " 2. Full Name:"<< name<<endl;
                    cout << " 3. Adress:" << adress<< endl;
            }
            else
            {
 
                 cerr << "Cutomer id:";
                    cin >> id;
                    if(cin.fail())
                    break;
                    cerr << " Station gate:";
                    cin >> gate;
           if ( gate == '@')
           {
                cerr << "Comments: ";
              cin >> ws;;
                         getline(cin, name);
                    getline(cin, adress);
                    if (cin.fail()) 
                    break;
                    cout << " 1. Customer ID:"<<id<<endl;
                    cout << " 2. Full Name:"<< name<<endl;
                    cout << " 3. Adress:" << adress<< endl;
           }
            else if (gate =='A')
            {
                 cerr << "Comments: ";
              cin >> ws;;
                    getline(cin, adress);
                    if (cin.fail()) 
                    break;
                    cout << " Adress:"<< adress<<endl;
                    cout << "          " << gate<< endl; 
                    a++;
            }
            else if (gate == 'B')
                         {
                             cerr << "Note: ";
              cin >> ws;;
                             getline(cin, adress);
                    if (cin.fail()) 
                    break;
                    cout << " Adress:"<< adress<<endl;
                    cout << "          " << gate<< endl; 
                    b++;
            }
 
            else if (gate == 'C')
            {
                 cerr << "Comments: ";
                 cin >> ws;;
                             getline(cin, adress);
                    if (cin.fail()) 
                    break;
                    cout << " Adress:"<< adress<<endl;
                    cout << "          " << gate<< endl; 
                    c++;
            }
            else if (gate == 'D')
            {
                 cerr << "Comments: ";
                 cin >> ws;;
                getline(cin, adress);
                    if (cin.fail()) 
                    break;
                   cout<< "              :"<< a<< "   * $2.20 = " << "$"<< (a*2.20)<<endl;
                   cout<< "              :"<< b<< "   * $2.80 = " << "$"<< (b*2.20)<<endl;
                   cout<< "              :"<< c<< "   * $2.30 = " << "$"<< (c*2.20)<<endl;
                   cout<< "              :"<< d<< "   * $3.80 = " << "$"<< (d*2.20)<<endl;
                   cout<< " TOTAL IS" << "$"<< a+b+c+d<< endl;
                   cout<<"____________________________________________________"<<endl;
                   cout<<" please make payment as soon as possible"<< endl;
            }
     }
}
}

so plz try to figure out with me what should i change to get it right

Here is a complete program that reads from cin, and prints to cerr. Now you should be able to modify this to read from a text file. It is fairly simple to do it with file reading. Just open the file to a file object and replace cin with that file object. After the processing close the file at the end of the program.The format of textfile was assumed to be like.

3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3435344 A 2005/02/22/08:22:41
3435344 A 2005/03/20/08:22:41
3435344 B 2005/03/23/18:22:41
3435344 B 2005/04/10/28:22:41
3435344 C 2005/03/11/08:22:41
3435344 C 2005/05/10/14:22:41
3435344 C 2005/05/19/06:22:43
3435344 D 2005/05/01/01:26:41
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
3873242 B 2005/03/29/02:40:59
3873242 B 2005/05/16/02:40:59
3873242 C 2005/04/07/22:40:59
3873242 D 2005/03/02/02:40:59

#include <iostream>
#include <string>
using namespace std;
int main() 
{
    string  id, 
            rest_of_the_line,
            name_and_address;

    // sub_header is a flag that indicates the sub header should be output
    bool sub_header = true;
    char gate;
    float total =0;
    const float amount_gate_A = 2.20;
    const float amount_gate_B = 2.80;
    const float amount_gate_C = 2.30;
    const float amount_gate_D = 3.80;
 
    while ( cin >> id >> gate )
    {
        getline(cin, rest_of_the_line);
        if ( gate == '@' )
        {
            if ( total > 0 )
            {
                // output the total
                cerr << "Total = " << total << endl;
            }
            // save the address as it will be overwritten in the next cin
            name_and_address = rest_of_the_line;
            // clear values of total and sub_header
            total = 0 ;
            sub_header = true;
        }
        else 
        {
            if ( sub_header )
            {
                cerr << " 1. Customer ID:"      << id               << endl;
                cerr << " 2. Name and Address:" << name_and_address << endl;
                cerr << " 3. Date        Time     Station    Amount"<< endl;
                sub_header = false;
            }


            // use substr to extract the date and time
           // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0, 11 ) << "    " 
                 << rest_of_the_line.substr(12)  << "    " 
                 << gate << "        " ;

            if (gate == 'A')
            {
                cerr    << amount_gate_A;
                total   += amount_gate_A;
            }
            else if (gate == 'B')
            {
                cerr    << amount_gate_B;
                total   += amount_gate_B;
            }
            else if (gate == 'C')
            {
                cerr    << amount_gate_C;
                total   += amount_gate_C;
            }
            else if (gate == 'D')
            {
                cerr    << amount_gate_D;
                total   += amount_gate_D;
            }
            cerr << endl; 
        }
    }

    if ( total > 0 )
    {
        // output the total
        cerr << "Total = " << total << endl;
    }
    return 0;
}

i've done that but i still have troubledhooting please help me fix it

#include <iostream>
#include <string>
using namespace std;
int main() 
{
    
    string  id, 
            rest_of_the_line,
            name_and_address;
    // sub_header is a flag that indicates the sub header should be output
    bool sub_header = true;
    char gate;
    float total =0;
    float amount_gate_A = 2.20;
     float amount_gate_B = 2.80;
    float amount_gate_C = 2.30;
    float amount_gate_D = 3.80;
    string heading;
    heading = " Interstate Mototrway Pty Ltd invoice statements";
    
       
   cout << heading<<endl;
   cout  <<" ----------------------------------------------"<<endl;
cout << " customer id : " <<id;
 cin >> id;
 cout << " station gate : ";
 cin >> gate;
    while (true)
    {
          cout << "adress and name : "; 
        cin >> rest_of_the_line;
      switch(gate) {
        
        case [EMAIL="'@'"]'@'[/EMAIL]:
        
            if ( total > 0 )
            {
                // output the total
                cerr << "Total = " << total << endl;
           
            // save the address as it will be overwritten in the next cin
            name_and_address = rest_of_the_line;
            
            // clear values of total and sub_header
            total = 0 ;
            sub_header = true;
            }
            
        else 
        {
            if ( sub_header )
            {
                cerr << " 1. Customer ID:"      << id               << endl;
                cerr << " . Name and Address:" << rest_of_the_line << endl;
                cerr << " 3. Date        Time     Station    Amount"<< endl;
                sub_header = false;
                }
            
            // use substr to extract the date and time
           // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,35 ) << "    " 
                 << rest_of_the_line.substr(36)  << "    " 
                 << gate << "        " ;

            case 'A': 
                cerr    << amount_gate_A;
                total = total+  amount_gate_A;
            break;
            case'B':
                cerr    << amount_gate_B;
                total   = total +  amount_gate_B;
            break;    
            case 'C':
                cerr    << amount_gate_C;
                total   = total + amount_gate_C;
            break;
            case 'D':
                cerr    << amount_gate_D;
                total   = total + amount_gate_D;
            break;
cerr << endl; 
        
                  }
               
                  
    if ( total > 0 )
    {
        // output the total
        cerr << "Total = " << total << endl;
        cout << " please make payments as sonn as possible"<< endl;
    }
}
}
    return 0;
}

You have done what?
You need troubleshooting on what?
Care to be more specific? Tell us where you are getting it wrong. We can't compile and run the program for you.

the program compile and run but i cant get the calculation right as soon as i input the stationgate i dont get anything after it

Although I dont understand why you decided to change the program I gave, which is working perfectly, here is a partly corrected version of your program.

#include <iostream>
#include <string>
using namespace std;
int main() 
{
    
    string  id, 
            rest_of_the_line,
            name_and_address;
    // sub_header is a flag that indicates the sub header should be output
    bool sub_header = true;
    char gate;
    float total =0;
    float amount_gate_A = 2.20;
     float amount_gate_B = 2.80;
    float amount_gate_C = 2.30;
    float amount_gate_D = 3.80;
    string heading;
    heading = " Interstate Mototrway Pty Ltd invoice statements";
    
       
    cerr << heading<<endl;
    cerr  <<" ----------------------------------------------"<<endl;
    while (true)// How do you intend to break this loop?
    {
        cerr << " customer id : ";
        cin >> id;
        cerr << " station gate : ";
        cin >> gate;
        cin.ignore();
        cerr << "adress and name : "; 
        getline( cin, rest_of_the_line );

        switch(gate) 
        {
        
        case '@':
            if ( total > 0 )
            {
                // output the total
                cerr << "Total = " << total << endl;

                // save the address as it will be overwritten in the next cin
                name_and_address = rest_of_the_line;

                // clear values of total and sub_header
                total = 0 ;
                sub_header = true;
            }
            else 
            {
                if ( sub_header )
                {
                    cerr << " 1. Customer ID:"      << id               << endl;
                    cerr << " . Name and Address:" << rest_of_the_line << endl;
                    cerr << " 3. Date        Time     Station    Amount"<< endl;
                    sub_header = false;
                }

            }
            break;
        case 'A': 
            // use substr to extract the date and time
            // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,11 ) << "    " 
                    << rest_of_the_line.substr(12)  << "    " 
                    << gate << "        " ;
            cerr    << amount_gate_A;
            total = total+  amount_gate_A;
            break;
        case'B':
            // use substr to extract the date and time
            // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,11 ) << "    " 
                    << rest_of_the_line.substr(12)  << "    " 
                    << gate << "        " ;
            cerr    << amount_gate_B;
            total   = total +  amount_gate_B;
            break;    
        case 'C':
            // use substr to extract the date and time
            // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,11 ) << "    " 
                    << rest_of_the_line.substr(12)  << "    " 
                    << gate << "        " ;
            cerr    << amount_gate_C;
            total   = total + amount_gate_C;
            break;
        case 'D':
            // use substr to extract the date and time
            // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,11 ) << "    " 
                    << rest_of_the_line.substr(12)  << "    " 
                    << gate << "        " ;
            cerr    << amount_gate_D;
            total   = total + amount_gate_D;
            break;
        
        }
        cerr << endl; 
    }
               
                  
    if ( total > 0 )
    {
        // output the total
        cerr << "Total = " << total << endl;
        cout << " please make payments as sonn as possible"<< endl;
    }
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.