CS201 Assignment No. 4

View previous topic View next topic Go down

GMT - 3 Hours CS201 Assignment No. 4

Post by kamran on Fri Jun 24, 2011 4:25 am

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
[You must be registered and logged in to see this image.]


[You must be registered and logged in to see this image.]
avatar
kamran
Monstars
Monstars

Scorpio Cat
Posts : 301
Join date : 2011-02-11
Age : 30

Back to top Go down

GMT - 3 Hours Re: CS201 Assignment No. 4

Post by Bano Zulaikha on Mon Jun 27, 2011 6:48 pm

Solution:

Code:

#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");

}

[You must be registered and logged in to see this image.]
avatar
Bano Zulaikha
Monstars
Monstars

Aries Rooster
Posts : 20
Join date : 2011-06-27
Age : 36

Character sheet
Experience:
5/5  (5/5)

Back to top Go down

GMT - 3 Hours Re: CS201 Assignment No. 4

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


Permissions in this forum:
You cannot reply to topics in this forum