Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

must use code blocks c++ This assignment demonstrates array of STRUCT (structure

ID: 3699349 • Letter: M

Question

must use code blocks c++

This assignment demonstrates array of STRUCT (structures), two dimensional arrays and the use of index sorting routine.

The problem:

A trucking company charges the customers a fixed amount per pound, based on the following (Zone-Area) table.

       

                        Area code       Area code       Area code

         Zone                   1               2               3

         code

            1                   .40             .55             .68

            2                   .60             .70             .85

            3                   .75             .79             .96

            4                  .90            1.05            1.10

            5                  .99            1.08            1.15

Write a program which will read in the above table into a two dimensional array. The array will be used to calculate the shipping cost. Your program will read in the name of the customer, the zone-area code, and the weight of the item shipped. The zone-area code consists of two digits, the first one indicates the zone, and the second indicates the area.

Assume there are less than 20 records for one truckload.

Print all customers’ information and their shipping charges in a report form. The end of the report must contain the total of all of the customers’ weight and a total of all the shipping charges.

Reproduce the above report in alphabetical order by customers name

Reproduce the above report sorted by weight.

Produce a report of all the companies in area code number two.

        Your test data will be similar to the following:

                3

                Chevrolet                23   750

                Zapata Co.               53   385

                Schlumberger         51 1104

The first line of the data file will contain a header record indicating how many customer records are to follow.

       

The actual test data will be stored under DATA7.txt

The Zone-Area table will be stored under TABLE7.txt

Submit your source code in blackboard and demonstrate your program in lab.

Documentation will be 20% of your grade.

Your source code must contain the following documentation.

Header information: (Source Code and Output)

        Your Name, course & section number, assignment number and due date.

A brief description of your assignment.

Variable dictionary: A brief description of every variable used in your program.

Comments related to input and output of data and all formulas used in your code.

data7.txt

table7.txt

shell

Explanation / Answer

C++ program:

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

     ifstream chargeFile, customerFile;

     string customerNames[20];

     double chargesArray[5][3], weight[20];

     double totalCharge =0, totalWeight = 0, charge;

     int recordCont,code[20];

     chargeFile.open("TABLE7.txt");

     customerFile.open("DATA7.txt");

     if(!chargeFile || !customerFile)

     {

          cout<<"Error in opening the file..."<<endl;

          system("PAUSE");

          exit(0);

     }

     for(int i=0; i<5; i++)

          for(int j=0; j<3; j++)

              chargeFile>>chargesArray[i][j];

     customerFile>>recordCont;

     cout<<"Customer Name "<<"Weight "<<"Charge "<<endl;

     cout<<"------------- "<<"------ "<<"------ "<<endl;

     for(int i=0; i<recordCont; i++)

     {

          customerFile>>customerNames[i]>>code[i]>>weight[i];

          totalWeight+=weight[i];

          charge = chargesArray[(code[i]/10)-1][(code[i]%10)-1]*weight[i];

          cout<<customerNames[i]<<" "<<weight[i]<<" "<<charge<<" "<<endl;

          totalCharge+=charge;

     }

     cout<<endl;

     cout<<"Total Weight : "<<totalWeight<<endl;

     cout<<"Total Charge : "<<totalCharge<<endl;

     system("PAUSE");

     return 0;

}