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

This assignment is an extension of Assignment#1. You will implement a program ca

ID: 3889489 • Letter: T

Question

This assignment is an extension of Assignment#1. You will implement a program called "call_stats.cpp" to process customer call records. Each customer call record contains seven fields, which are as follows: 1) a ten digit cell phone number (string, no dashes), 2) the number of relay stations used in making the call (integer), 3) the length of the call in minutes (integer), 4) the net cost of the call (double), 5) the tax rate (double), 6) the call tax (double) and 7) the total cost of the call (double). Your program will have 3 functions: Input, Process and Output. Your main program will call each function until the end of the datafile has been read. Following are the descriptions of the functionality of each function: 1. The void function “Input” will have two parameters: an input file stream called “in”, and a customer call record called “call_records”. The function will read the cell_number, relays, and call_length, in minutes, into the a call record from the data file. 2. The function "Process" will calculate the net cost of a call (net_cost), the tax on a call (call_tax) and the total cost of the call (total_cost) using the number of relay stations (relays) and the length in minutes of the call (call_length) for a call record. Please consider the following: a. The tax rate on a call (call_tax) is simply based on the number of relay stations (relays) used to make the call (0<= relays <=5 then call_tax = 1%; 6<= relays <=11 then call_tax = 3%; 12<= relays<=20 then call_tax = 5%; 21<= relays <=50 then call_tax = 8%; relays >50 then call_tax =12%) . b. The net cost of a call is calculated by the following formula: net_cost = ( relays / 50 x 0.40 x call_length). c. The tax on a call is equal to net_cost x call_tax / 100. d. The total cost of a call (rounded to the nearest hundredth) is calculated by the following formula: total_cost = net_cost + call_tax . All tax and cost calculations should be rounded to the nearest hundredths. 3. The function "Output" will print every field of a call record. The fields should be printed in the following order: 1) cell phone number, 2) number of relay stations, 3) length of the call in minutes, 4) net cost, 5) tax rate, 6) call tax, 7) total cost of call. See the sections below called "Input Stream" and "Format of Output" for more information. See the section “Format of the input data file(input filename is "call_data.txt")”. You may implement more functions if you find it necessary. Please start the assignment ASAP and ask questions to make sure you understand what you must do. Remember to follow all style rules and to include all necessary documentation (consistent, indentation, proper variable names, pre/post condition, program header, function headers, and so forth.) Finally, your input data file (call_data.txt) should be in the same directory as your program source file (call_Stats.cpp). Output Format for the Function "Output": Consider the following sample output table when designing and implementing the function "Output". (The output is in the following order: cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost) 9546321555 0 0 0.00 0.01 0.00 0.00 9546321555 15 30 3.60 0.05 0.18 3.78 9546321555 4 3 0.10 0.01 0.00 0.10 Input Stream: In the assignment you will declare one ifstream to bind your input to the file "call_data.txt" / Whenever a program performs file i/o you must include the "fstream" library. Add the following statements to your program: For source file, "call_stats.cpp": Add "#include " to your # include statements in your source file. Add "include to your # include statements in your source file. Format of the input data file(input filename is "call_data.txt"): Do not include column titles (The order of the columns are as follows: cell phone number, relays, minutes) 9546321555 0 0 5612971340 5 50 3051234567 8 25 7542346622 24 17 3054432762 15 30 9544321011 50 100 8776219988 87 82 9042224556 4 5 7877176590 11 1 5617278899 20 45 9546321555 4 3 5612971340 79 86 3051234567 8 25 7542346622 24 118 3054432762 115 25 9544321011 43 10 8776219988 265 22 9042224556 2 5 7877176590 89 67 5617278899 40 56 Format of Output: (cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost) 9546321555 0 0 0.00 0.01 0.00 0.00 5612971340 5 50 2.00 0.01 0.02 2.02 3051234567 8 25 1.60 0.03 0.05 1.65 7542346622 24 17 3.26 0.08 0.26 3.53 3054432762 15 30 3.60 0.05 0.18 3.78 9544321011 50 100 40.00 0.08 3.20 43.20 8776219988 87 82 57.07 0.12 6.85 63.92 9042224556 4 5 0.16 0.01 0.00 0.16 7877176590 11 1 0.09 0.03 0.00 0.09 5617278899 20 45 7.20 0.05 0.36 7.56 9546321555 4 3 0.10 0.01 0.00 0.10 5612971340 79 86 54.35 0.12 6.52 60.87 3051234567 8 25 1.60 0.03 0.05 1.65 7542346622 24 118 22.66 0.08 1.81 24.47 3054432762 115 25 23.00 0.12 2.76 25.76 9544321011 43 10 3.44 0.08 0.28 3.72 8776219988 265 22 46.64 0.12 5.60 52.24 9042224556 2 5 0.08 0.01 0.00 0.08 7877176590 89 67 47.70 0.12 5.72 53.43 5617278899 40 56 17.92 0.08 1.43

Explanation / Answer

//Assignment : call_stats.cpp

//Explanation : In this program, we are using call_record which //has various member fields and uses data of input file

//We get input from user like cell number, relays, call length //and process these data with field members of call_record

//Finally,result is displayed

//Include headers

#include <iostream>

#include <string>

#include <fstream> //for file manipulations

using namespace std;

//call record function

class callrecord

{

public:

int relay;

int calllength;

string cellnumber;

double taxrate;

double totalcost;

double netcost;

double calltax;

};

//Input is obtained from text file, calldata.txt that includes //cell number, relays and call length values

void input_data(ifstream &, callrecord &);

//Now the members of callrecord are used to calculate values of //non-members like taxrate,netcost,totalcost and calltax

void processes(callrecord &);

//To display the record members

void output_data(const callrecord &);

//FUNCTION Explanation//

//Name of the method: input_data()

//Pre-condition:Members such as calllength, relay and cellnumber //are obtained from callrecord class

//not taken from input file named calldata.txt.

//Post-condition: Input is taken from calldata.txt file that //includes mambers like cell number, relay and calllength

//Function description: The input_data function reads cellnumber, calllength,and relay into callrecord from file calldata.txt.

//Method Name: processes()

//Pre-condition: The callrecord data members like netcost, calltax, taxrate and totalcost of callrecord are not calculated using input fields that are got from data file

//Post-condition: The data members such as //taxrate,netcost,toatlcost as well as call tax of callrecord //are being calculated with the help of specific formulae using //data fields that are read from input_data file.

//Method Description:The method uses relay station numbers and //the call length

//call callrecord, then manipulate net call cost, total call cost and tax on each call

//Method Name: Output_data

//Pre-condition: The data from input file as well as calculated //data are not yet displayed in the screen

//Post-condition: The inpiut data as well as calculated data are //being displayed in screen

//Method Description: The output_data method displays or prints calculated as well as input data of callrecord class

//**************************************************************

int main()

{

callrecord customerrecord;

ifstream inf; //inf is object of input file stream

inf.open("calldata.txt");

if (inf.fail())

{

cout << "failed to open input file" << " ";

}

else

{

while (!inf.eof())//upto end of file

{

input_data(inf, customerrecord);

processes(customerrecord);

output_data(customerrecord);

}

}

inf.close();

return(0);

}

//Obtain input from text file, calldata.txt that includes value //of relays,call length and cell number

void input_data(ifstream & inf, callrecord & customerrecord)

{

inf >> customerrecord.cellnumber;

inf >> customerrecord.relay;

inf >> customerrecord.calllength;

}

//Using members of callrecord class to manipulate non-members of //callrecord

void processes(callrecord & customerrecord)

{

if ((0 <= customerrecord.relay) && (customerrecord.relay <= 5))

{

customerrecord.taxrate = .01;

}

else if ((6 <= customerrecord.relay) && (customerrecord.relay <= 11))

{

customerrecord.taxrate = .03;

}

else if ((12 <= customerrecord.relay) && (customerrecord.relay <= 20))

{

customerrecord.taxrate = .05;

}

else if ((21 <= customerrecord.relay) && (customerrecord.relay <= 50))

{

customerrecord.taxrate = .08;

}

else if (customerrecord.relay>50)

{

customerrecord.taxrate = .12;

}

customerrecord.netcost = (customerrecord.relays / 50.0)*(customerrecord.calllength*0.4);

customerrecord.calltax = customerrecord.netcost*(customerrecord.taxrate);

customerrecord.totalcost = customerrecord.calltax+customerrecord.netcost;

}

//Displaying the output

void output_data(const callrecord & customerrecord)

{

cout.setf(ios::showpoint);

cout.setf(ios::fixed);

cout.precision(3);

cout << customerrecord.cellnumber;

cout << customerrecord.relay << " ";

cout<< customerrecord.calllength << " "; cout<< customerrecord.netcost << " ";

cout<< customerrecord.taxrate << " "; cout<< customerrecord.calltax << " ";

cout<< customerrecord.totalcost <<" ";

}