Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. # include <cctype>
  2. # include <iomanip>
  3. # include <iostream>
  4. # include <string>
  5. # include <fstream>
  6. # include <cmath>
  7. using namespace std;
  8.  
  9. void readfile(string,char[], int,int,int[]);
  10. void convert(string);
  11. void output(string,ifstream&,char[],double,double,double,int, int,int,int[],char,int&);
  12. void calcstats(int,double, double,double,int, int,int,int[],char,int&);
  13.  
  14. int main()
  15. {
  16. string fname;
  17. int nums[60];
  18. int size = 0;
  19. int sum=0;
  20. int pmax=0;
  21. int pmin=0;
  22. double avg=0;
  23. char letter;
  24. char studname[60];
  25. ifstream outname;
  26. double variation=0;
  27. double stddev=0;
  28. string name;
  29. int sizep, sizec;
  30. int comps[60];
  31. int len;
  32. int count[0];
  33. int count2;
  34. int letterc;
  35. cout << " Enter file name for input? "<< endl;
  36. cin >> fname;
  37. cout << " Enter file name for output?" << endl;
  38. cin >> name;
  39. readfile(fname,studname,count2,len,nums); // reads the file
  40. calcstats(len,variation,stddev,avg,sum,pmax,pmin,count,letter,size); // main numbers
  41. output(fname,outname,studname, variation,stddev,avg,len,pmax,pmin, nums,letter,letterc);
  42.  
  43. return 0;
  44. }
  45.  
  46. void calcstats(int len,double variation, double stddev,double avg, int sum, int pmax, int pmin,int count[], char lettergrade,int& j)
  47.  
  48. {
  49. pmin=0;
  50. avg=0;
  51. pmax = 0;
  52. for (int i = 0; i < len; i++)
  53. {
  54. if (i < pmin)
  55. pmin = i;
  56. if (pmax=i < i)
  57. pmax = i;
  58.  
  59. for ( j=1; j <=count[i]; j++)
  60. if ( i >= 90 && i <= 100 )
  61.  
  62. lettergrade = 'A';
  63.  
  64.  
  65. else
  66. if (i >= 80 && i <= 89 )
  67.  
  68.  
  69. lettergrade = 'B';
  70.  
  71.  
  72. else
  73. if ( i >= 70 && i <= 79 )
  74.  
  75. lettergrade= 'C';
  76.  
  77.  
  78. if ( i >= 60 && i <= 69 )
  79.  
  80. lettergrade='D';
  81.  
  82. else
  83. if (i <= 60)
  84. lettergrade='F';
  85.  
  86.  
  87. }
  88.  
  89. avg = (double)sum/(double)len;
  90. sum = 0;
  91. for (int k = 0; k < len; k++)
  92. sum += (k - avg)*(k - avg);
  93. variation = sum;
  94. stddev = sqrt(variation);
  95.  
  96.  
  97. }
  98.  
  99.  
  100. void convert(char firstname[])
  101. {
  102. for (int j=0;j<60; j++)
  103.  
  104. {
  105. firstname[0]=toupper(firstname[0]);
  106. firstname[j]=tolower(firstname [j]);
  107. }
  108. void readfile(string fname,char name[], int count,int len, int numz[])
  109. {
  110. ifstream in;
  111. count=0;
  112. name[60];
  113. len = 0;
  114. int val;
  115.  
  116. in.open(fname.c_str());
  117.  
  118. in >> val;
  119. in >> name[len];
  120. numz[len]=val;
  121. ++len;
  122.  
  123. while(!in.eof())
  124. {
  125. in >> val>> name[len];
  126. numz[len] = val;
  127. ++len;
  128. count++;
  129.  
  130. }
  131.  
  132. in.close();
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. void output(string fname,ifstream& name,char sname[], double variation,double stddev ,double avg,int max,int min, int len, int nums[], char lettergrade,int& letter) // output function to display everything from the readfile function
  141. {
  142. ofstream out;
  143. string studname;
  144. out.open(fname.c_str());
  145.  
  146. out << "Thomas Castro section#1001 assignment11\n";
  147. out << " " << endl;
  148. out<< " name of inputfile" << name << endl;
  149. for (int i = 0; i < len; ++i)
  150. out << nums[i] << "\t"<< endl;
  151. int lettercount=nums[letter];
  152. convert(sname);
  153. out << "the high score of" << max << "was earned by"<< sname << endl;
  154. out << "The low score of "<<min << " was earned by" << sname << endl;
  155. out << "average: " << avg << endl;
  156. out << "variation: " << variation << endl;
  157. out << "stddev: " << stddev << endl;
  158.  
  159. out << "Grade Distribution" << endl;
  160. out << " A" << " | " << lettercount << endl;
  161. out << " B" <<" | " <<lettercount << endl;
  162. out << " C" <<" | " << lettercount << endl;
  163. out << " D" <<" | " <<lettercount << endl;
  164. out << " F" << " | " <<lettercount << endl;
  165.  
  166. out.close();
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement