This assignment is an extension of Assignments 3, 4 and 5. You will implement a
ID: 3852266 • Letter: T
Question
This assignment is an extension of Assignments 3, 4 and 5. You will implement a program called "call_stats4.cpp" to process customer call records. You will read the records in a datafile into an array of call records, then process each call record in the array, and finally print the array of call records to a datafile. Remember, 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 once. Following are the descriptions of the functionality of each function:
1. The void function “Input” will have two parameters: the call record array called “call_DB”, and the count. call_DB, and count should be initialized in your main program. The global integer constant SIZE should be set to 200. count should be initialized to 0. The function will read the cell_number, relays, and call_length (in minutes) into the a call record in call_DB (call_DB[i] is an individual call record) from the input data file. Remember, count should be passed by reference. 2. The function “Process will have two parameters: call_DB and count. 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 tax_rate = 1%; 6<= relays <=11 then tax_rate = 3%; 12<= relays<=20 then tax_rate = 5%; 21<= relays <=50 then tax_rate = 8%; relays >50 then tax_rate =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 tax_rate (divide by 100 if tax rate was not converted into a decimal earlier). 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
hint: call_DB[i].net_cost = (call_DB[i].relays/50.0)*0.40* (call_DB[i].call_length); 3. The function “Output” will have two parameters: call_DB and count. Note that call_DB and count will not change inside this function. Output will print every field of every call record stored in call_DB to the file “weekly6_call_info.txt”. 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")”.
hint: cout<<call_DB[i].cell_number<<” ”<<call_DB[i].relays<<” ”<<call_DB[i].call_length<<endl;
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_stats4.cpp).
Input Stream: In the assignment you will declare one ifstream to bind your input to the file "call_data.txt" and one ofstream to bind your output to the file “weekly6_call_info.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_stats4.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)
Format of Output (output filename is "weekly6_call_info.txt"): (the order of the columns is as follows: cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost)
Chegg Study Guided Sollx Assignment6.pdf 1.65 3.53 0.03 0.05 3051234567 7542346622 8 24 7 17 3.26 3.78 43.20 0.18 3054432762 9544321011 0.08 40.00 57.07 100 9042224556 7877176590 5617278899 9546321555 5612971340 3051234567 7542346622 3054432762 9544321011 8776219988 9042224556 7.56 0.05 0.12 0.08 54.35 23.00 0.12 0.12 7877176590 5617278899 Handing in your program Electronically submit the source file "call stats4.cpp" in the Assignments area of blackboard before the due date and time. Remember, submit your assignment on time no matter if it is incorrect and/or incomplete!Explanation / Answer
call_stats4.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int SIZE = 200;
/*********************************************************
//Following is the declaration of a call record
**********************************************************/
class call_record
{
public:
string cell_number;
int relays;
int call_length;
double net_cost;
double tax_rate;
double call_tax;
double total_cost;
};
//Prototypes for your functions: Input, Output, and Process will go here
void Input(call_record(&call_DB)[SIZE], int &count, ifstream &in);
void Process(call_record(&call_DB)[SIZE], int count);
void Output(call_record(&call_DB)[SIZE], int count, ofstream &out);
void Input(call_record(&call_DB)[SIZE], int &count, ifstream &in) {
in.open("call_data.txt");
count = 0;
while (!in.eof() && count < SIZE) {
in >> call_DB[count].cell_number;
in >> call_DB[count].relays;
in >> call_DB[count].call_length;
count++;
}
in.close();
}
void Process(call_record(&call_DB)[SIZE], int count) {
for (int i = 0; i < count; i++){
if ((call_DB[i].relays >= 0) && (call_DB[i].relays <= 5)) {
call_DB[i].tax_rate = 0.01;
}
else if ((call_DB[i].relays >= 6) && (call_DB[i].relays <= 11)) {
call_DB[i].tax_rate = 0.03;
}
else if ((call_DB[i].relays >= 12) && (call_DB[i].relays <= 20)) {
call_DB[i].tax_rate = .05;
}
else if ((call_DB[i].relays >= 21) && (call_DB[i].relays <= 50)) {
call_DB[i].tax_rate = .08;
}
else {
call_DB[i].tax_rate = 0.12;
}
call_DB[i].net_cost = call_DB[i].relays / 50.0 * .40 * call_DB[i].call_length;
call_DB[i].call_tax = call_DB[i].net_cost*call_DB[i].tax_rate;
call_DB[i].total_cost = call_DB[i].net_cost + call_DB[i].call_tax;
}
}
void Output(call_record(&call_DB)[SIZE], int count, ofstream &out) {
out.setf(ios::fixed);
out.setf(ios::showpoint);
out.precision(2);
out.open("weekly4_call_info.txt");
for (int i = 0; i < count; i++) {
out << right << setw(10) << call_DB[i].cell_number << " ";
out << right << setw(10) << call_DB[i].relays << " ";
out << right << setw(10) << call_DB[i].call_length << " ";
out << right << setw(10) << call_DB[i].net_cost << " ";
out << right << setw(10) << call_DB[i].tax_rate << " ";
out << right << setw(10) << call_DB[i].call_tax << " ";
out << right << setw(10) << call_DB[i].total_cost << endl;
}
out.close();
}
int main(){
call_record call_DB[SIZE];
int count;
ifstream in;
ofstream out;
Input(call_DB, count, in);
Process(call_DB, count);
Output(call_DB, count, out);
}
call_data.txt
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.