Assignments and GDBs
CS201 C++ Assignmnet Solution 4 (29-06-2011)
- Details
- Published on Tuesday, 02 August 2011 16:43
- Written by Gulshan Ali
|
Semester: Spring 2011 CS201: Introduction to Programming
Problem Statement: Printing Electricity Bill Detailed Description: Write a C++ program in which you have to:
|
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 9999
---------------------------------------------------------------------------
Month Units Bill Current Bill 10732
Jan-11 312 5000 Arrears 0
Feb-11 312 5000 Tariff Subsidy NA
Mar-11 312 5000 Payable within Duedate 10732
|
---------------------------------------------------------------------------
|
Solution:-
/*
This program prints Electricity Bill from a txt file “Electricity_Bill” which contains the bill information
*/
#include
#include
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 successfuly opened or not
if (!inFile)
{
cout << "Can't open input file named " <
exit(1);
}
while (!inFile.eof())
{
inFile.getline(completeLineText, MAX_CHAR_TO_READ);
cout << completeLineText << endl;
}
cout<
cout<
cout<
inFile.close();
system("pause");
return 0;
}
