Question

The utility department of Brentwood City needs you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

utility.txt(Save the text file in D:Drive .Then the path of the file is D:\\utility.txt )

222123
955.9
576
715.8

____________________________________________

Code in c++

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;


int main() {
//Declaring constant  
const char* filename = "D:\\utility.txt";
  
//Declaring variables
long cust_number,cnum;
float gallons_water,gwater;
int electricity_kw,electricity;
float natural_gas_cf,gas;
float const WATER=0.02,ELEC=0.24,GAS=0.39;

//Input stream
std::ifstream inFile(filename);

//Check whether the file is available or not.
if(!inFile) {
cout << endl << "Failed to open file " << filename;
return 1;
}
  
//If the file is available,read the values from it.
while(!inFile.eof()) {
inFile >>cnum>>gwater>>electricity>>gas;
cust_number=cnum;
gallons_water=gwater;
electricity_kw=electricity;
natural_gas_cf=gas;
  
//calculating the cost
float cost_of_water=gallons_water*WATER;
float cost_of_electricity=electricity_kw*ELEC;
float cost_of_gas=natural_gas_cf*GAS;
  
//calculating the total Cost.
float total_charges=cost_of_water+cost_of_electricity+cost_of_gas;
  
//Displaying the Bill.
cout << std::setw(36) << "Brentwood City Utility Bill"<<setw(16)<<"Customer #"<<cust_number<<endl<<"\n";
cout<<std::setw(14)<<"Water"<<setw(17)<<gallons_water<<" gallons at $"<<WATER<<"="<<setw(14)<<"$"<<setw(2)<<cost_of_water<<endl;
cout<<std::setw(20)<<"Electricity"<<setw(9)<<electricity_kw<<" Kilowatts at $"<<ELEC<<"="<<setw(14)<<"$"<<setw(2)<<cost_of_electricity<<endl;
cout<<std::setw(20)<<"Natural Gas"<<setw(11)<<natural_gas_cf<<" cubic foot at $"<<GAS<<"="<<setw(11)<<"$"<<std::fixed<< std::setprecision(2)<<setw(2)<<cost_of_gas<<endl<<"\n";
cout<<std::setw(69)<<"------------------------------------------------------------"<<endl;
cout<<std::setw(33)<<"Total of all utilities ="<<setw(30)<<"$ "<<total_charges<<endl;
}
cout << endl;
return 0;
}

________________________________________________

Output:

CProgram Files (x86)\Dev-Cpp MinGW64\bin\BreantWoodElectricityBill.exe Brentwood City Utility Bill Water Electricity Customer

Add a comment
Know the answer?
Add Answer to:
The utility department of Brentwood City needs you to write a C++ program that will print...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for...

    The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for the first 300 kwh 8 cents per kwh for the next 300 kwh (up to 600 kwh) 6 cents per kwh for the next 400 kwh (up to 1000 kwh) 5 cents per kwh for all electricity used over 1000 kwh Write a program that would repeatedly read in a customer number (an integer) and the usage for that customer in kwh (an integer)....

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • INSTRUCTION AND PROBLEMS Write a Python program for each of the problems in this lab. Please...

    INSTRUCTION AND PROBLEMS Write a Python program for each of the problems in this lab. Please use PyCharm to type and test your programs. Submit the Python files to Blackboard for credit. In this lab, you should submit 4 Python files, one for each problem PROBLEM I Energy consumption is measured in units of kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy bll. A power company charges customers $0.12 per kWh for...

  • WRITE A PROGRAM IN C THAT DOES THE FOLLOWING: The numbers are real numbers, read in...

    WRITE A PROGRAM IN C THAT DOES THE FOLLOWING: The numbers are real numbers, read in as double precision floating-point numbers, one number perline, possibly with some white space before or after. Hint: use scanf. There are guaranteed to be no more than one million (that’s 10^6) numbers in the input, and no fewer than two legitimate numbers. Any number that is equal to zero should be ignored (discarded, not stored in the array or counted in any way).

  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • THE PROBLEM: The nice folks from the Lion Lending Company have hired you to write some...

    THE PROBLEM: The nice folks from the Lion Lending Company have hired you to write some software that will process their daily loan information. The data will come from a text file that has the following format: The first line will contain an integer: number of loan applications There will be two rows for each of the customers First line will be the customer's (1) first name and (2) last name, separated by a space (assume there is no spaces...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST...

    In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST use GUI, that means all user input must be through the windows. The "first window" is the window on the top left of the following picture. Add 5 more items to be purchased. Search is accessed from second window, top right. Thw third window is the bottom left, and the fourth window is the bottom right. The program MUST CONTAIN EVERYTHING IN THE PICTURES....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT