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

For c++ 7. C A. Write a complete C program that wi1l calculate the charge tor el

ID: 3915402 • Letter: F

Question

For c++ 7. C A. Write a complete C program that wi1l calculate the charge tor electricity for customers. The program should read the following infornation Erom an input file named "chargin.dat": customer account number (integer) kilowatt hours used (float) status (char) Electric charges are 59 cents pe kilowatt hour for commercial customers and 47 cents per kilowatt hours for residential customers. The status will be "for residential customers and "" for commercial customers You do not know how many lines of data are in the input file. The program should place the following information for each customer in an output file named "chargout.dat" customer account number cost of electricity (float) The output file will be used as input to another program. SAMPLE INPUT FILE: 143 47.3 r 782 24S.7 c SAMPLE OUTPUT FILE: 143 22.231 782 144.963 B.Write a complete C+t program that will read the output file produced from Homework Question 5 above and print a bill (to the screen) for each custoner. Sample output: Electric Charges Customer: 143 Amount Due: $22.23 Customer 782 Amount Due: $144.96

Explanation / Answer

7.A.

#include <iostream>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
#include <fstream>

using namespace std;

int main()
{
float pForCom = 0.59;
float pForRes = 0.47;
//Open file in read mode and read line by line
string line;
ifstream chargin ("chargin.dat");
//Open file in write mode
ofstream chargout ("chargout.dat");
if (chargin.is_open())
{
while ( getline (chargin,line) )
{
string s = line ;
string v[3];
char c[1];
istringstream iss(s);
int i=0;
float totalCharge=0;
while (iss)
{
string subs;
iss >> subs;
v[i] = subs;
i++;
}
  
strcpy(c, v[2].c_str());
//Calculation for total charge according to the status
if(c[0] == 'r'){
totalCharge = std::stof(v[1]) * pForRes;}
else if (c[0] == 'c'){
totalCharge = std::stof(v[1]) * pForCom;}
  
  
//Writing in to the charout file
if (chargout.is_open())
{
chargout << v[0] << " " << totalCharge <<" ";
}
else cout << "Unable to open file";
  
}
//closing both the files
chargin.close();
chargout.close();
}

else cout << "Unable to open file";

  
}

B.

#include <iostream>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
#include <fstream>

using namespace std;

int main()
{
//Open file in read mode and read line by line
string line;
ifstream chargout ("chargout.dat");
  
cout<< "Electric Charges " <<" ";
if (chargout.is_open())
{
while ( getline (chargout,line) )
{
string s = line ;
string v[3];
char c[1];
istringstream iss(s);
int i=0;
float totalCharge=0;
while (iss)
{
string subs;
iss >> subs;
v[i] = subs;
i++;
}
  
strcpy(c, v[2].c_str());
  
cout << "Customer: "<<v[0] << " ";
cout << "Amount Due: $"<<v[1] << " ";
cout << " ";
}
//closing the file
chargout.close();
}

else cout << "Unable to open file";

  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote