vuZs

Virtual University: Study Resource Bank

You are here: Home Assignment CS201: Introduction to Programming CS201 C++ Assignmnet Solution 4 (29-06-2011)
Like this Page? Press  
 

Assignments and GDBs

CS201 C++ Assignmnet Solution 4 (29-06-2011)

Semester: Spring 2011

CS201: Introduction to Programming

 

Problem Statement:

             Printing Electricity Bill

Detailed Description:

Write a C++ program in which you have to:

  1. 1.Create a text file “Electricity_Bill”.

 

  1. 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

 

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

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

      

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;

   }

Add comment


Security code
Refresh

You are here: Home Assignment CS201: Introduction to Programming CS201 C++ Assignmnet Solution 4 (29-06-2011)