#include #include #include using namespace std; class call_record { public: stri
ID: 3870200 • Letter: #
Question
#include #include #include using namespace std; class call_record { public: string cell_number; int relays; int call_lenght; double net_cost; double tax_rate; double call_tax; double total_cost; }; void Input ( ifstream &,call_record&); void Output( const weekly_call_info&); void process (call_record &); void input(ifstream & in, call_record & weekly_call_info); in>>weekly_call_info.cell_number; in>>weekly_call_info.relays; in>>Weekly_call_info.call_lenght; //} void process (const weekly_call_info ) { double tax_rate; if ((1<= relays) && (relays<=11)) { tax_rate=0.01; out_stream<< "tax_rate:"; out_stream<50) { tax_rate=0.12; cout<< "tax_rate:"; cout<
Explanation / Answer
#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>
using namespace std;
ifstream fin("call_data.txt");
ofstream fout("weekly_call_info.txt");
long int phno;
int relay;
int mins;
float net_cost ,tax_rate, call_tax, total_call_cost;
void Process();
void Display();
void Input()
{
char line[100];
while(fin>>line)
{
if(fin.eof()) break;
phno=atol(line);
fin >> line;
relay=atoi(line);
fin >> line;
mins = atoi(line);
Process();
}
fin.close();
}
void Process()
{
net_cost = relay / 50 * 0.4 * mins;
if ( relay>=0 && relay<=5 )
tax_rate= 0.01;
else if ( relay>=6 && relay<=11 )
tax_rate= 0.03;
else if ( relay>=12 && relay<=20 )
tax_rate= 0.05;
else if ( relay>=21 && relay<=50 )
tax_rate= 0.08;
else if ( relay>=50 )
tax_rate=0.12;
call_tax = net_cost * tax_rate;
total_call_cost = net_cost + call_tax;
Display();
}
void Display()
{
char result[1000];
sprintf(result,"%-20ld %10d %10d %10.2f %10.2f %10.2f %10.2f", phno, relay, mins, net_cost,tax_rate,call_tax,total_call_cost);
fout << result << endl;
}
int main()
{
Input();
return 0;
}
/*
lenovo@lenovo-Vbox:~/chegg$ g++ -Wall call_stats3.cpp -o call_stats3
lenovo@lenovo-Vbox:~/chegg$ cat call_data.txt
9223351454 0 0
8734123434 5 50
2323232321 8 25
8765454231 24 17
9834343234 15 30
3232223893 50 100
6787868768 87 82
8997651211 4 5
2309883490 11 1
9223351454 20 45
8734123434 4 3
2323232321 79 86
8765454231 8 25
9834343234 24 118
3232223893 115 25
6787868768 43 10
8997651211 2 5
2309883490 89 67
lenovo@lenovo-Vbox:~/chegg$ ./call_stats3
lenovo@lenovo-Vbox:~/chegg$ ls
1to100.c call_data.txt call_stats3.cpp cmplx err.txt lab5.c readseq.cpp simu.c~
1to100.c~ call_data.txt~ call_stats3.cpp~ cmplx.cpp fib.c lab5.c~ readseq.cpp~ weekly_call_info.txt
a.out call_stats3 ccmplx cmplx.cpp~ fib.c~ numbers.txt simu.c
lenovo@lenovo-Vbox:~/chegg$ cat weekly_call_info.txt
9223351454 0 0 0.00 0.01 0.00 0.00
8734123434 5 50 0.00 0.01 0.00 0.00
2323232321 8 25 0.00 0.03 0.00 0.00
8765454231 24 17 0.00 0.08 0.00 0.00
9834343234 15 30 0.00 0.05 0.00 0.00
3232223893 50 100 40.00 0.08 3.20 43.20
6787868768 87 82 32.80 0.12 3.94 36.74
8997651211 4 5 0.00 0.01 0.00 0.00
2309883490 11 1 0.00 0.03 0.00 0.00
9223351454 20 45 0.00 0.05 0.00 0.00
8734123434 4 3 0.00 0.01 0.00 0.00
2323232321 79 86 34.40 0.12 4.13 38.53
8765454231 8 25 0.00 0.03 0.00 0.00
9834343234 24 118 0.00 0.08 0.00 0.00
3232223893 115 25 20.00 0.12 2.40 22.40
6787868768 43 10 0.00 0.08 0.00 0.00
8997651211 2 5 0.00 0.01 0.00 0.00
2309883490 89 67 26.80 0.12 3.22 30.02
lenovo@lenovo-Vbox:~/chegg$
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.