Asked By
Eewlespery
20 points
N/A
Posted on - 07/31/2011
Problem Statement:
Printing Electricity Bill Detailed Description
Write a C++ program in which you have to:
-
Create a text file “Electricity_Bill”.
-
Write the following data in it:
Electricity Consumer Bill:
Reference No |
Tariff |
Load |
Old A/C No |
123456789123456 |
2 |
1 |
123456789123456 |
Name and Address
XYZ Lahore Pakistan
Reading |
MF |
Total Unit Consumed |
Total Cost of electricity |
55671 |
1 |
328 |
999 |
—————————————————————————————————————————–
Month |
Units |
Bill |
Current Bill |
10732 |
Jan-11 |
312 |
5000 |
Arrears |
0 |
Feb-11 |
312 |
5000 |
Tariff Subsidy |
N/A |
Mar-11 |
312 |
5000 |
Payable within Due date |
10732 |
Answered By
James20
5 points
N/A
#95977
C++ Code for creating a Electricity Bill Text File
Hi Eewlespery,
First, you save this file as Electricity_Bill.txt
Electricity Consumer Bill
——————————————————————————
Reference No |
Tariff |
Load |
Old A/C No |
123456789123456 |
2 |
1 |
123456789123456 |
Name and Address
XYZ Lahore Pakistan
—————————————————————————————————————————–
Reading |
MF |
Total Unit Consumed |
Total Cost of electricity |
55671 |
1 |
328 |
999 |
—————————————————————————————————————————–
Month |
Units |
Bill |
Current Bill |
10732 |
Jan-11 |
312 |
5000 |
Arrears |
0 |
Feb-11 |
312 |
5000 |
Tariff Subsidy |
N/A |
Mar-11 |
312 |
5000 |
Payable within Due date |
10732 |
Now run this piece of code:
/*
This program prints Electricity Bill from a txt file “Electricity_Bill” which contains the bill information
*/
#include <iostream.h>
#include <fstream.h>
main()
{
ifstream inFile; // Handle for the input file
char inputFilename[] = "Electricity_Bill.txt"; // file name, this file is in the current directory
const int MAX_CHAR_TO_READ = 2000; // maximum character to read in one line
char completeLineText[MAX_CHAR_TO_READ]; // to be used in getLine function
inFile.open(inputFilename); // opening the file
// checking that file is successfully opened or not
if (!inFile)
{
court << "Can't open input file named " <<inputFilename << endl;
exit(1);
}
while (!inFile.eof())
{
inFile.getline(completeLineText, MAX_CHAR_TO_READ);
court << completeLineText << endl;
}
court<<endl;
court<<endl;
court<<endl;
inFile.close();
system("pause");
return 0;
}