CIS210 Introduction to C Programming Fall 2016 AssignmentX P

CIS-210 Introduction to C++ Programming (Fall 2016) Assignment-X Points: 100 Due Date: 10/26/2016 (before class) Specifications: The Fairhope Utility Company charges subscribers for their electricity consumption according to the following table (monthly rates) 1. Kilowatt-hours 0 s kwh s 400 5per kwh $0.08 401 5 kWhs 1500 $0.15 1501 s kwh 3500 | 24 3501 s kWh 29 Note: Distribution charges a well as federal state and local taxes add 10%to each bill. Write a C++ program that reads the customer names, account number, and kWh consumed from a text file called electric_usage.txt and then outputs to the file, bill info.txt, the customer name, account number and total amount to pay. See sample input / output below . 2. Sample Input/Output electrical usage.txt (input) Tom 123-49-82 2100 Mark 241-87-11 346 Nancy 198-85-07 5002 Beth 342-53-49 2812 Erin 787-63-88 688 brmat the outpat wes bvo decma ives two decmal places bill info.txt (output) Fo Customer Name: Tom Account Number: 123-49-82 Bill Amount: 554.40 Customer Name: Mark Account Number: 241-87-11 Bill Amount: 30.45

Solution

electric_info.txt(Save this file under D Drive.Then the path of the file pointing to the file is D:electric_info.txt)

Tom 123-49-82 2100
Mark 241-87-11 346
Nancy 198-85-07 5002
Beth 342-53-49 2812
Erin 787-63-88 688

________________________

C++ code

#include <iostream>
#include <iomanip>
#include <fstream>
#define FEDERAL_AND_LOCAL_TAX 0.10
using namespace std;

int main()
{
//Declaring variables
string name,account_num;
int kilowatt_hours;
double bill_amount=0.0,tot_bill_incl_tax=0.0;

//defines an input stream for the data file  
ifstream dataIn;
  
//Defines an output stream for the data file
ofstream dataOut;
  
  
//Opening the input file
dataIn.open(\"D:\\\\electric_info.txt\");
  
//creating and Opening the output file
dataOut.open(\"D:\\\\bill_info.txt\");
  
//Reading single line from input file every time   
while(dataIn>>name>>account_num>>kilowatt_hours)
{
   
    /* Based on the range of the no of kilowatt hours
   * bill amount and total bill
   * amount will be calculated
   */
    if(kilowatt_hours>=0 && kilowatt_hours<=400)
    {
    //Calculating the bill amount bsed on number of Kilowatt hours  
    bill_amount=kilowatt_hours*0.08;
   }
   else if(kilowatt_hours>=401 && kilowatt_hours<=1500)
   {
       //Calculating the bill amount bsed on number of Kilowatt hours  
       bill_amount=kilowatt_hours*0.15;
   }
   else if(kilowatt_hours>=1501 && kilowatt_hours<=3500)
   {
       //Calculating the bill amount bsed on number of Kilowatt hours  
       bill_amount=kilowatt_hours*0.24;
   }
   else if(kilowatt_hours>=3501 )
   {
       //Calculating the bill amount bsed on number of Kilowatt hours  
       bill_amount=kilowatt_hours*0.29;
   }
  
   //Calculating the tottal bill amount including federal and local tax
   tot_bill_incl_tax=bill_amount+bill_amount*FEDERAL_AND_LOCAL_TAX;
  
//Writing the customer name to the output file
dataOut<<\"Customer Name: \"<<name<<endl;
  
//Writing the Account number to the output file
dataOut<<\"Account Number: \"<<account_num<<endl;
  
//Writing the Total bill amount to the output file
dataOut<<\"BillAmount: \"<<std::fixed<< std::setprecision(2)<<tot_bill_incl_tax<<\"\ \"<<endl;
  
}
  
return 0;
}

_______________________________

bill_info.txt (After running the program we can see this file in D:Drive as we specified the path of the output file is D:\\\\bill_info.txt )

Customer Name: Tom
Account Number: 123-49-82
BillAmount: 554.40

Customer Name: Mark
Account Number: 241-87-11
BillAmount: 30.45

Customer Name: Nancy
Account Number: 198-85-07
BillAmount: 1595.64

Customer Name: Beth
Account Number: 342-53-49
BillAmount: 742.37

Customer Name: Erin
Account Number: 787-63-88
BillAmount: 113.52

___________Thank You

 CIS-210 Introduction to C++ Programming (Fall 2016) Assignment-X Points: 100 Due Date: 10/26/2016 (before class) Specifications: The Fairhope Utility Company c
 CIS-210 Introduction to C++ Programming (Fall 2016) Assignment-X Points: 100 Due Date: 10/26/2016 (before class) Specifications: The Fairhope Utility Company c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site