VUsolutions Transferred to AchiKhasi.com

From December 2011, this blog www.VUsolutions.blogspot.com is transferred to http://achikhasi.com/vu/ . So, you may visit http://achikhasi.com/vu/ for latest study related help.

Back to home VUsolutions

VUsolutions Fans Club [join us for MORE solutions]

VUsolutions on Facebook

CS201 Assignment No. 4 solution

Monday, June 27, 2011 Posted In Edit This
Assignment No. 04
Semester: Spring 2011
CS201: Introduction to Programming


Total Marks: 20
Due Date:29/06/2011



Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:

§  The assignment is submitted after due date.
§  The submitted assignment does not open or file is corrupt.
§  All types of plagiarism are strictly prohibited.

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted. If you will submit code in .doc (Word document) you will get zero marks.

Objective
The objective of this assignment is to provide hands on experience of using

§  Streams in C/C++

Guidelines:

§  Code should be properly aligned and well commented.
§  Follow c/c++ rules while writing variables names, function names etc
§  Use only dev-C++ for this assignment.



Assignment:



Problem Statement: 
           Printing Electricity Bill
Detailed Description:
Write a C++ program in which you have to:
1.   Create a text file “Electricity_Bill”.

2.   Write 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                      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 

---------------------------------------------------------------------------

3.   Open file and read data from it and display it on the screen.
        
Sample Output



:::::::::::::::::::::::::::::::::::::::::::::::::::::


Solution:


#include<iostream.h>
#include<fstream.h>
main()
{
ifstream inFile;
char inputFileName[]="Electricity_Bill.txt";
const int MAX_CHAR_TO_READ = 100;
char completeLineText[MAX_CHAR_TO_READ];

inFile.open(inputFileName);

if(!inFile)
{
cout <<"Can't open input file named " << inputFileName << endl;
exit(1);
}

while(!inFile.eof())
{
inFile.getline(completeLineText,MAX_CHAR_TO_READ);
cout << completeLineText << endl;
}
inFile.close();
system("pause");

}

:::::::::::::::::::::::::::::::::::::::::::::



                       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  


---------------------------------------------------------------------------

Back to home VUsolutions

Shaadi.com: Just create ur account & find ur partner or EARN money, its reall & EASY

VUsolutions Followers (Join NOW and Get Extra Benefits)

Install LATEST toolbar having lot of features - GET solutions on Desktop

toolbar powered by Conduit
Caliplus 300x250 NoFlam VitoLiv 468x60 GlucoLo