Saturday 2 July 2011

CS 201 Assignment 4 solution


#include<iostream.h>
#include<fstream.h>

main()
{
      ifstream inFile;
      ofstream outFile;
     
      char outputFileName[]="Electricity_Bill.txt";
      char outputText[]="\t\t\tElectricity Consumer Bill\n"
      "---------------------------------------------------------------------------\n"
      "Reference No        Tariff        Load       Old A/C No\n"
      "123456789123456     2              1              123456789123456\n"
      "\n---------------------------------------------------------------------------\n"
      "Name and Address \n"  
      "XYZ Lahore Pakistan \n"
      "\n---------------------------------------------------------------------------\n"
      "Reading             MF     Total Unit Consumed    Total Cost of electricity\n"
      "55671               1      328                      9999\n"
      "\n---------------------------------------------------------------------------\n"
      "Month             Units     Bill              Current Bill            10732\n"
      "Jan-11            312       5000              Arrears                 0\n"
      "Feb-11            312       5000              Tariff Subsidy          NA\n"
      "Mar-11            312       5000              Payable within Duedate  10732 \n"
      "\n---------------------------------------------------------------------------\n";

       outFile.open(outputFileName, ios::out);
     
       if(!outFile)
       {
                   cout << "Can't open file named " << outputFileName << endl;
                   exit(1);
                   }
                 
       outFile << outputText;
       outFile.close();
     
      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");    
}

No comments:

Post a Comment