Guest User

Untitled

a guest
Jan 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include "Exam.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. void Exam::loadExam(){
  8.     //seeds random function
  9.     srand(time(NULL));
  10.     //Loads the Exam key randomly
  11.         for(int i=0;i<100;i++)
  12.         {
  13.             key[i][0] = rand()%5;
  14.             bool distinct = false;
  15.             while(!distinct)
  16.             {
  17.                 key[i][1] = rand()%5;
  18.                 if(key[i][0]!=key[i][1])
  19.                     distinct = true;
  20.             }
  21.         }
  22. }
  23.  
  24. void Exam::writeExam(int a){
  25.    
  26.     ofstream output;
  27.     //Determine which test will be writen
  28.     switch(a){
  29.     case 1:
  30.         output.open("Test A.txt");
  31.         break;
  32.     case 2:
  33.         output.open("Test B.txt");
  34.         break;
  35.     case 3:    
  36.         output.open("Test C.txt");
  37.         break;
  38.     case 4:    
  39.         output.open("Test D.txt");
  40.         break;     
  41.     }
  42.     //Writes test to a file    
  43.     for(int i=0;i<100;i++)
  44.     {
  45.         output<<key[i][0]<<"    "<<key[i][1]<<endl;
  46.     }
  47.     output.close();
  48.     cout<<"done"<<endl;
  49. }
Add Comment
Please, Sign In to add comment