Guest User

Untitled

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. MY STUD.H
  2. ________________
  3.  
  4. #include <fstream>
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. struct StudRd
  11. {
  12.  int id;
  13.  float exam1;
  14.  float exam2;
  15.  float exam3;
  16.  float avg;
  17. };
  18. void ReadRd(ifstream& inFile, StudRd& rd);
  19. void WriteRd(ofstream& outFile, StudRd rd);
  20. void findAvg(StudRd& rd);
  21.  
  22.  
  23.  
  24. MY STUD.CXX
  25. _____________
  26. #include "stud.h"
  27.  
  28. void ReadRd(ifstream& inFile, StudRd& rd)
  29. {
  30.    inFile >> rd.id >> rd.exam1 >> rd.exam2 >> rd.exam3;
  31. }
  32.  
  33. void WriteRd(ofstream& outFile, StudRd rd)
  34. {
  35.    outfile << "id= "    << rd.id << endl;
  36.    outFile << "exam1= " << ed.exam1 << endl;
  37.    outFile << "exam2= " << ed.exam2 << endl;
  38.    outFile << "exam3= " << ed.exam3 << endl;
  39.    outFile.setf(ios::fixed);
  40.    outFile.setf(ios::showpoint);
  41.    outFile.precision(2);
  42.    outFile << "Exams AVG= " << rd.avg << endl;
  43. }
  44. void find Avg(StudRd& rd)
  45. {
  46.    rd.avg = float(rd.exam1 + rd.exam2 + rd.exam3/(3);
  47. }
  48.  
  49.  
  50. RUNPROG1STUD.CXX (Client Code)
  51. _____________________________
  52. #include "stud.h"
  53.  
  54. int main()
  55. {
  56.   ifstream inFile;
  57.   ofstream outFile;
  58.   inFile.open("in.data");
  59.   outFile.open("out.data");
  60.  
  61.   while (inFile)
  62.   {
  63.    StudRd rd;
  64.    ReadRd(inFile, rd);
  65.    findAvg(rd);
  66.    WriteRd(outFile, rd);
  67.  
  68.   }
  69.   outFile << "*** END ***" << endl;
  70.  return 0;
  71. }
Add Comment
Please, Sign In to add comment