Create an array with external file in C++ -


i have 4 days of training in c++, bear me.

two data files required evaluate multiple-choice examination. first file (booklet.dat) contains correct answers. total number of questions 50. sample file given below:

acbaaddbcbddaacdbaccabdcabccbddabcacabababcbdbaabd 

the second file (answer.dat) contains students’ answers. each line has 1 student record contains following information:

the student’s answers (a total of 50 answers) in same format above (* indicates no answer)., followed student id , student name. example:

aaccbdbc*dbcbdaaabdbcbdbaa*bcbdd*babdbcdaabdcbdbda 6555 mahmut cbbdbc*bdbdbdbabababbbbbabbabbbbd*bbbcbbdbabbbdc** 6448 sinan acb*addbcbddaacdbaccabdcabccbddabcacabababcbdbaabd 6559 cagil 

i have homework assignment write c++ program counts total number of correct answers each student , outputs information file called report.dat. in file, student’s ids, names , scores must given. each correct answer worth 1 point. sample files given above, output should follows:

6555 mahmut 10 6448 sinan 12 6550 cagil 49  

here's have far:

include <iostream> include <fstream>  using namespace std;  int main() {     char booklet[50] answers[50]     int counter      // link answers booklet.dat     booklet = ifstream     input_file("booklet.dat");     return 0;      // link answers answers.dat     answers = ifstream     input_file("answer.dat");     return 0;       while (booklet==answers)     {         counter++         cout << "the student had">>counter>> "answers right";     } } 

i'm not sure in correct direction. know need create array file booklet.dat , 1 file answer.dat. comparison has made , matches between 2 have counted.

i don't expect assignment me, need nudge in right direction.

1.) on syntax:

a) each line in c++ has end ";". there lines in excample don't. (normally compile should point @ or following line error)

b) multiple variable definitions need "," in between 2 different variables.

2.) recommend use that: (have @ c++ reference fstream) edit: little outline, not complete in form, give , idea ;-)

#include <iostream> #include <string> #include <fstream>  using namespace std;  int main() {  int nr_of_students = 1000;   /* or number you'd analyze */  int stud_nr[nr_of_students]; string stud_name[nr_of_students]; int stud_count[nr_of_students];  fstream in_out; in_out.open("filename.dat",fstream::in); // fstream::in reading file                                          // fstream::out writing file if(in_out.is_open()) {     for(lines=0;(in_out>>answers && lines<nr_of_students);lines++)     {          in_out >> stud_nr[lines];   /* edit: sorry hat index confusions here... */          in_out >> stud_name[lines];          stud_count[lines]=0;          for(int i=0;i<50;i++)          {               /* comparison between booklet_array , answers_array */               /* count stud_count[lines] each right comparison */          }     }      /* simmilar code output-file */ } else cout << "error reading " << "filename.dat" << endl;  return 1; } 

3.) code more performance vectors. tutorial be: tutorial part i , find part 2 in comments there

4.) can achieve more dynamic code argc , argv**, google that

i hope these comments little bit carry on ;)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -