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

Hi I need a Pro C++ helper here.. I have this assignment that I need help with.

ID: 3594601 • Letter: H

Question

Hi I need a Pro C++ helper here.. I have this assignment that I need help with.

1.. (nnew)) Read the contents of a datafile one record at a time in an array ;

2.. (nnew)) Process the data that was read from the datafile one record at a time ,

into an array ; 3.. (nnew)) Print the record s in an array to a datafile using an ofstream object;;

4.. Be able to use the fstream library;;

5.. (nnew)) Be able to use an array of record records ;

6.. Be able to use an ifstream object;;

7.. Be able to use an ofstream object;;

This assignment is an extension of Assignment s 3,, 4 and 5 . Y ou will implement a program called "ccall_stats 4 .ccpp"" 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,, e ach customer call record contains seven fields,, which are as f ollows:: 1)) a ten digit cell phone number (sstring,, no dashes)),, 2)) the number of relay stations used in making the call (iinteger)),, 3)) the length of the call in minutes (iinteger)),, 4)) the net cost of the call (ddouble)),, 5)) the tax rate (ddouble)),, 6)) the call tax (ddouble)) and 7)) the total cost of the call (ddouble)).. 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 “ccall_DB””,, and the count.. call_DB , and count should be initialized in your main program.. The global integer constant SIZE shou ld be set to 20 0 . 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 (ccall_DB[[ii]] is an individual call record)) from the input data file.. Remember,, count should be passed by reference..

2.. The function “PProcess will have two parameters:: call_DB and count.. The function "PProcess " will calculate the net cost of a call (nnet_cost)) , the tax on a call (ccall_tax)) and the total cost of the call (ttotal_cost)) using the number of relay stations (rrelays))

and the length in minute s of the call (ccall_length)) for a call record.. Please consider the following::

a.. The tax rate on a call (ccall_tax)) is simply based on the number of relay stations (rrelays)) used to make the call (00<<== relays <==55 then tax _rate = 1%%;; 6<<== relays <==111 then tax _rate = 3%%;; 12<<== relays <==220 then tax _rate = 5%%;; 21<<== relays <==550 then tax _rate = 8%%;; relays >550 then tax _rate =112%%)) .

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 (rrounded 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[[ii]]..nnet_cost = (ccall_DB[[ii]]..rrelays//550.0))**00.40** (ccall_DB[[ii]]..ccall_length));;

3.. The function “ Output ” will have two paramete rs:: call_DB and count.. Note that call_DB and cou nt 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..ttxt”” . 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 "IInput Stream " and "FFormat of Output"" for more information.. See the section “ Format of the input data file((iinput filename is " ca ll_data..ttxt ")) ” .

h int:: cout<<<<ccall_DB[[ii]]..ccell_number<<<<”” t””<<<<ccall_DB[[ii]]..rrelay s <<<”” t””<<<<ccall_DB[[ii]]..ccall_length<<<<eendl;;

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 (cconsistent,, indentation,, proper variable names,, pre//ppost condition,, program header,, function headers,, and so forth..))

Finally,, your input data file (ccall_data .ttxt)) should be in the same directory as your program source file (ccall_s tats 4 .ccpp))..

Input Stream :

In the assignment you will declare one ifstream to bind your input to the file "ccall_data..ttxt"" and one ofstream to bind your output to the file “ weekly6 _call_info..ttxt “..

Whenever a program performs file i//oo you must include the "ffstream"" library.. Add the following statements to your program::

For source file,, "ccall_stats 4 .ccpp"" :

Add " #iinclude <ffstream>> " to your # include statements in your sour ce file..

Add "iinclude <sstring>> to your # include statements in your source file..

Format of the i nput data file (iinput filename is " call_data..ttxt ")):: 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 (ooutput filename is " weekly6 _call_info..ttxt""))::

(tthe order of the columns is as follows:: 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

19.35

Explanation / Answer

#include<iostream>
#include<fstream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
using namespace std;
//Class CallReport Definition
class CallReport
{
//Data member
string number;
int relay;
int callLength;
int numberOfRecords;
double netCost;
double taxRate;
double callTax;
double totalCost;
public:
//Member functions
//To read data from file
void Input(CallReport []);
//To calculate tax
void Process(CallReport []);
//To write data to file
void Output(CallReport []);
};//End of class

//Function to calculate tax
void CallReport::Process(CallReport rep[])
{
//Loops till end of records
for(int c = 0; c < numberOfRecords; c++)
{
//Checks the relay and fix the tax rate
if(rep[c].relay >= 0 && rep[c].relay <= 5)
rep[c].taxRate = 1;
else if(rep[c].relay >= 6 && rep[c].relay <= 11)
rep[c].taxRate = 3;
else if(rep[c].relay >= 12 && rep[c].relay <= 20)
rep[c].taxRate = 5;
else if(rep[c].relay >= 21 && rep[c].relay <= 50)
rep[c].taxRate = 8;
else
rep[c].taxRate = 12;
//Calculates net cost
rep[c].netCost = ( rep[c].relay / 50.0 * 0.40 * rep[c].callLength);
//Calculates call tax
rep[c].callTax = (rep[c].netCost * rep[c].taxRate) / 100;
//Calculates total cost
rep[c].totalCost = rep[c].netCost + rep[c].callTax;
}//End of for loop
}//End of function

//Function to write object contents into the file
void CallReport::Output(CallReport rep[])
{
//ofstream object created to write
ofstream writeFile;
//Opens the file weekly_call_info.txt for writing
writeFile.open("weekly_call_info.txt");
//Checks whether the file can be opened or not
if (writeFile.is_open())
{
//Write the headings
writeFile<<" Records in the file: ";
writeFile<<" Number Relays Minutes NetCost TaxRate Call Tax Total Call Cost";
//Loops till end of records
for(int c = 0; c < numberOfRecords; c++)
{
//Write the result to the file
writeFile<<" "<<rep[c].number<<" "<<rep[c].relay<<" "<<rep[c].callLength<<" ";
writeFile<<setprecision(2)<<fixed<<rep[c].netCost<<" "<<rep[c].taxRate<<" "<<rep[c].callTax<<" "<<rep[c].totalCost;
}//End of for loop
}//End of if
//If file cannot be opened
else
//Display the error message
cout<<" Error: Unable to open file";
//Close the file
writeFile.close();
//Display the result on console
cout<<" Records in the file: ";
cout<<" Number Relays Minutes NetCost TaxRate Call Tax Total Call Cost";
for(int c = 0; c < numberOfRecords; c++)
{
cout<<" "<<rep[c].number<<" "<<rep[c].relay<<" "<<rep[c].callLength;
cout<<" "<<setprecision(2)<<fixed<<rep[c].netCost<<" "<<rep[c].taxRate<<" "<<rep[c].callTax<<" "<<rep[c].totalCost;
}//End of for loop
}//End of function

//Function to read data from file
void CallReport::Input(CallReport rep[])
{
//Creates an object of ifstream
ifstream readf;
//Opens the file call_data.txt for reading
readf.open ("call_data.txt");
//Initializes number of records to zero
numberOfRecords = 0;
//To store data
char data[100];
//Loops till end of file
while(!readf.eof())
{
//Read data from file till tab space
readf.getline(data, 100, ' ');
//Stores the data in variable of class object
rep[numberOfRecords].number = data;
//Read data from file till tab space
readf.getline(data, 100, ' ');
//Converts the data to integer and store it in the variable
rep[numberOfRecords].relay = atoi(data);
//Read data from file till tab space
readf.getline(data, 100);
//Converts the data to integer and store it in the variable
rep[numberOfRecords].callLength = atoi(data);
//Increase the record counter
numberOfRecords++;
}//End of while
//Close file
readf.close();
}//End of function

//Main function
int main()
{
//Creates 100 objects of CallReport type
CallReport rec[100];
//Reads the file contents and stores in rec array of objects
rec[0].Input(rec);
//Calculates tax by calling the process() function
rec[0].Process(rec);
//Writes the result in file
rec[0].Output(rec);
return 0;
}//End of main

Sample Run:


Records in the file:
Number Relays Minutes NetCost TaxRate Call Tax Total Call Cost
9546321555 0 0 0.00 1.00 0.00 0.00
5612971340 5 50 2.00 1.00 0.02 2.02
6051234567 8 25 1.60 3.00 0.05 1.65
7542346622 24 17 3.26 8.00 0.26 3.53
3054432762 15 30 3.60 5.00 0.18 3.78
9544321011 50 100 40.00 8.00 3.20 43.20
8776219988 87 82 57.07 12.00 6.85 63.92
9042224556 4 5 0.16 1.00 0.00 0.16
7877176590 11 1 0.09 3.00 0.00 0.09
5617278899 20 45 7.20 5.00 0.36 7.56
9546321555 4 3 0.10 1.00 0.00 0.10
5612971340 79 86 54.35 12.00 6.52 60.87
3051234567 8 25 1.60 3.00 0.05 1.65
7542346622 24 118 22.66 8.00 1.81 24.47
3054432762 115 25 23.00 12.00 2.76 25.76
9544321011 43 10 3.44 8.00 0.28 3.72
8776219988 265 22 46.64 12.00 5.60 52.24
9042224556 2 5 0.08 1.00 0.00 0.08
7877176590 89 67 47.70 12.00 5.72 53.43
5617278899 40 56 17.92 8.00 1.43 19.35