Advertisement
Guest User

Student CPP

a guest
Nov 2nd, 2011
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include "Student.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <Windows.h>
  6. using namespace std;
  7.  
  8. Students::Students(){
  9.     keyNumber=0;
  10.     grade=0;
  11.     studentNumber=0;
  12.     //Seed Random Function
  13.     srand(time(NULL));
  14.     //Has student randomly guess questions
  15.         for(int i=0;i<100;i++)
  16.         {
  17.             answers[i]=rand()%5;
  18.            
  19.         }
  20. }
  21.  
  22. void Students::getVersion(int studentNumber)
  23. {
  24.     //Sets the keyNumber for the student to determine what test it will be checked against
  25.     keyNumber=studentNumber%4;
  26. }
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  28. void Students::checkAnswers(int a[100][2]){
  29.     //Variable to hold the test answers
  30.     int theKey[100][2];
  31.  
  32.     for(int i=0;i<100;i++)
  33.         {
  34.             theKey[i][0] = a[i][0];
  35.             theKey[i][1] = a[i][1];
  36.         }  
  37.    
  38.     //checks students answers to key
  39.     for(int i=0;i<100;i++)
  40.     {
  41.         if(answers[i]==theKey[i][0]||answers[i]==theKey[i][1])
  42.         {
  43.             totalCorrect[i]=1;
  44.         }
  45.         else
  46.         {
  47.             totalCorrect[i]=0;
  48.         }
  49.     }
  50.    
  51. }
  52. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. void Students::checkGrade()
  54. {
  55.     //Calculates the students correct answers
  56.     for(int a=0;a<100;a++)
  57.     {
  58.         grade = grade + totalCorrect[a];
  59.     }  
  60.         //cout<<grade<<endl;
  61.    
  62.  
  63. }
  64. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. void Students::returnAnswers(int pubAnswers[]){
  66.     //Used to return the students answers so that the main function and access them
  67.     for(int i=0;i<100;i++)
  68.     {
  69.         pubAnswers[i]=answers[i];
  70.     }
  71. }
  72. void Students::printGrades(int pubAnswers[]){
  73.     ofstream output;
  74.     output.open("Grades.txt");
  75.     for(int i=0;i<100;i++)
  76.     {
  77.         if(-1>grade<70)
  78.         {
  79.             output<<"Student "<<i<<"'s Grade is a A"<<endl;
  80.         }
  81.         if(69>grade<75)
  82.         {
  83.             output<<"Student "<<i<<"'s Grade is a D"<<endl;
  84.         }
  85.         if(74>grade<80)
  86.         {
  87.             output<<"Student "<<i<<"'s Grade is a C"<<endl;
  88.         }
  89.         if(79>grade<90)
  90.         {
  91.             output<<"Student "<<i<<"'s Grade is an "<<endl;
  92.         }
  93.         if(89>grade<101)
  94.         {
  95.             output<<"Student "<<i<<"'s Grade is an A"<<endl;
  96.         }
  97.     }
  98.    
  99.     output.close();
  100. }
  101. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. int Students::getSN(){
  103.     return keyNumber;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. void Students::getCorrect(int pubAnswers[100]){
  107.     for(int i=0;i<100;i++)
  108.         pubAnswers[i] = totalCorrect[i];
  109.    
  110. }
  111. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  112. int Students::getGrade(){
  113. return grade;
  114. }
  115. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  116. void Students::StudentWrite(int a){
  117.     int b = a;
  118.     ofstream output;
  119.     switch(b){
  120.     case 0:
  121.         output.open("Student 1.txt");
  122.         break;
  123.     case 1:
  124.         output.open("Student 2.txt");
  125.         break;
  126.     case 2:    
  127.         output.open("Student 3.txt");
  128.         break;
  129.     case 3:    
  130.         output.open("Student 4.txt");
  131.         break;     
  132.     }      
  133.     for(int i=0;i<100;i++)
  134.     {
  135.         output<<totalCorrect[i]<<"  "<<grade<<endl;
  136.        
  137.     }
  138.     output.close();
  139.    
  140.     cout<<"done"<<endl;
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement