Public paste
Undefined
By: jazy | Date: Dec 6 2006 19:33 | Format: C++ | Expires: never | Size: 2.19 KB | Hits: 1481

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6.  
  7. void getData(ifstream &infile,int grade [], int &sizeOf); //only one needed to reference since once we don't need to modify this
  8. void curveData(int curve[],int sizeOf,int grade[]);
  9. void printData(ofstream &outfile,int curve[],int grade[],int sizeOf);
  10.  
  11. //void test(ifstream &infile) {infile.open("temp.cpp");};
  12.  
  13. const int SIZE=15; //we are assuming that the size of 15 is the max for this
  14. double myMax=0.0;  
  15.  
  16.  
  17.  
  18. int main()
  19. {
  20.     // Variables going to be used by main //  
  21.     ifstream infile;
  22.     ofstream outfile;
  23.     int i;
  24.     int grade[SIZE];
  25.     int curve[SIZE];
  26.  
  27.     getData(infile,grade,i);
  28.     i -= 1; // it will be plus one more then in file. due to while struct.
  29.     curveData(curve,i,grade);
  30.     printData(outfile,curve,grade,i);
  31.    
  32. //Close the files that have been used in and out
  33.     infile.close();
  34.     outfile.close();
  35.    
  36.     return 0;
  37. }
  38.  
  39. void getData(ifstream &infile,int grade[],int &sizeOf) {
  40. //open input file
  41. infile.open("indata7.txt");
  42. //since the size if unknown we will set it to '0' until we know after reading the input the size
  43. sizeOf=0;
  44. while (!infile.eof()) {
  45.          
  46.      infile >> grade[sizeOf];
  47.        
  48.         //Since we need to find the max no need to transverse this array again we can do it in one step.
  49.         //lets make sure we don't get any garbage values anything > 100;
  50.         if (grade[sizeOf] >= myMax && grade[sizeOf] <= 100)
  51.                 myMax = grade[sizeOf];.
  52.  
  53.      //since there was an element we will increase the known size
  54.      sizeOf++;    
  55. }
  56.  
  57. }
  58.  
  59. void curveData(int curve[],int sizeOf,int grade[]) {
  60.  
  61.         // since we know myMax we can just do this here and mult each element for the curved grade.
  62.         double mult = 100.0/myMax;
  63.        
  64.         for (int k=0;k<sizeOf;k++) {
  65.                 curve[k] = grade[k] * mult; //save info in a new array to output both of them.
  66.                
  67.         }
  68. }
  69.  
  70. void printData(ofstream &outfile,int curve[],int grade[],int sizeOf) {
  71.         //open the outputfile that is going to be used
  72.         outfile.open("outdata7.txt");
  73.         outfile<<"Actual GradesttCurved Gradesn";
  74.         for(int j = 0;j < sizeOf; j++)
  75.     outfile<<grade[j]<<"ttt"<<curve[j]<<endl; //output both actual and curved grades.
  76. }
  77.