Public feed
#600466
/* Edward Kretchmer Student #P64-80-1498
Problem #340 - Assignment #3 Due Date 6/12/07
COP-1220 T/TH 6:00PM
This program will save to a file a report of Customer Number,
Kilowatts Used, and Payment Due.
The program will also save to a file a report of Total Kilowatts
Used, Total Payment Due, and Number of Customers Entered.
------------------------------------------------------
INPUT OUTPUT
----- ------
Customer Number Program Description and
Kilowatts Used Instructions
Customer Number
Kilowatts Used
Payment Due
Total Kilowatts Used
Total Payments Due
Number of Customers Entered
------------------------------------------------------
*/
//*** Program preprocessors, libraries, and header files
#include <iostream> // Cout and Cin stream
#include <iomanip> // Cout and Cin Options
#include <fstream> // File Stream
using namespace std; // Eliminates need for std::
int main() //***** BEGINNING OF PROGRAM LOGIC *****
{
//*** Declaration and initialization of program variables
string customer_number;
int kilowatts = 0;
int kilowatts_total = 0;
int counter = 0;
double cost = 0;
double cost_total = 0;
cout << fixed << showpoint // Fixed and show decimal
<< setprecision(2); // Set decimal places to 2
ofstream outdata; // File OUT Stream
outdata << fixed << showpoint // Fixed and Show Decimal
<< setprecision(2); // Set Decimal places to 2
outdata.open("e:/COP1220/Prob 340 Power Company/p340.txt");
system ("cls"); // Clear Screen
cout << "============================================================\n\n"
<< " THIS PROGRAM SAVES A LISTING OF POWER COMPANY TRANSACTIONS \n"
<< " INCLUDING:\n"
<< " - CUSTOMER NUMBER\n"
<< " - KILOWATTS USED\n"
<< " - PAYMENT DUE\n"
<< "=============================================================\n\n"
<< "After all customers are inputted, the Billing Report will display\n"
<< "and save:\n\n"
<< " - Number of Customers Entered\n"
<< " - Total Kilowatts Used\n"
<< " - Total Payments Due\n\n"
<< "The report will be saved to the file: p340.txt\n\n"
<< "NOTE: When finished entering Customer Transactions, enter the\n"
<< " letters 'EOF' when prompted for an Customer Number.\n\n\n\n";
outdata << setw (52) << "North Campus Power Company\n\n"
<< setw(22) << "Customer" << setw(23) << "Kilowatts\n"
<< setw(20) << "Number" << setw(21) << "Used" << setw(24) << "Payment\n";
cout << "Enter 5-digit Customer Number (or EOF to run report): ";
cin >> customer_number; // Primer for loop
// *** BEGINNING OF LOOP ***
while (customer_number != "EOF")
{
cout << "Enter Kilowatts Used: ";
cin >> kilowatts;
if (kilowatts >= 301)
cost = ((.0765 * (kilowatts - 300)) + 23.58);
else if (kilowatts >= 51 && kilowatts <= 300)
cost = ((.0943 * (kilowatts - 50)) + 6.15);
else
cost = (kilowatts * .123);
cost = (cost < 5.7) ? cost = 5.7 : cost = cost;
kilowatts_total+= kilowatts;
cost_total+= cost;
counter++;
outdata << setw(20) << customer_number <<setw(22) << kilowatts
<< setw(22) << cost << "\n";
cout << "Enter 5-digit Customer Number (or EOF to run report): ";
cin >> customer_number;
}
// *** END OF LOOP ***
// *** DISPLAY TOTALS TO SCREEN AND SAVE TO FILE ***
cout << "\n\nThe Employee Transactions you have just entered and the\n"
<< "Customer Usage Report will be saved to the file: p340.txt\n\n";
system ("pause");
system ("cls");
cout << setw(13) << "Number of" << setw(19) << "Total" << setw(21)
<< "Total\n" << setw(15) << "Customers: " << counter << setw(22)
<< "Kilowatts: " << kilowatts_total << setw(18) << "Payments: $ "
<< setw(6) << cost_total << "\n\n";
outdata << "\n\n" << setw(13) << "Number of" << setw(19) << "Total"
<< setw(21) << "Total\n" << setw(15) << "Customers: " << counter
<< setw(22) << "Kilowatts: " << kilowatts_total << setw(17)
<< "Payments: $" << setw(6) << cost_total << "\n\n";
outdata.close(); // Close File
system ("pause");
return 0;
}