mechanical student asking for the answer..

the question is..

create a file name studAnswers.txt as shown below. this file contain answer of 10 students for 10 objective question asked in a quiz. each line of the file contains a student's id followed by her/his answers for question 1 to 10

501 A C D C A B B C C D
502 A C D A A B A D C D
503 A C C A B B B C C D
504 A B D A B C B D C D
505 B C C A A B B D C B
506 A B D B A B C D C C
507 C B D B A C B D B D
508 A D D C A A B C C D
509 B C C A B B B D C D
510 B C D A A B B D C B

Write a program that opens the studAnswers.txt file for input. the program calculates the number of right answers of each student (in each line of the file) and the marks scored by the student for quiz. the the result are written to the output file name studResult.txt. (Assume that the answers for question 1-10 are A,C,D,A,A,B,B,D,C,D in sequence and the total marks for the quiz is 5%).
That is not a question. That is a homework assignment.

Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
closed account (48T7M4Gy)
The question(s) are in studQuestions.txt
i made this pretty quick not the best...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include<fstream>
#include <string>
using namespace std;


class  Sscores
{

public:
	
	void setScore(char val)
	{

		scoreGrade = val;
	}
private:
	char scoreGrade;

};
class Sstudent 
{


public:

	void setID(int idVal)
	{
		id = idVal;
	}
	int getID()
	{

		return id;
	}
	Sscores a[10];

	void setTotal(int count)
	{
		grade = (double) count * 10;

	}
	double getTotal()
	{
		return grade;

	}
private:
	int id;
	double grade;



};

int main()
{
	char answerkey[10]  { 'A', 'C', 'D', 'A', 'A', 'B', 'B', 'D', 'C', 'D' };
	ifstream fin;
	fin.open("studAnswers.txt");
	int itemp = 0;
	char ctemp = ' ';
	string stemp = "";
	int countG = 0;

	Sstudent students[10];
	for (int i = 0; i < 10; i++)
	{
		fin >> itemp;
		cout << itemp << " ";
		students[i].setID(itemp);
		countG = 0;
		for (int j = 0; j < 10; j++)
		{
			fin >> ctemp;
			if (answerkey[j] == ctemp)
			{
				countG++;

			}
			students[i].a->setScore(ctemp);
			cout << ctemp << " ";

		}
		students[i].setTotal(countG);
		cout << "Grade -> "<< students[i].getTotal() << endl;


	}
	fin.close();
	ofstream fout;
	fout.open("studResults.txt");
	for (int i = 0; i < 10;i++)
	{
		fout <<"Student ID -> "<<students[i].getID() << ", Grade -> " << students[i].getTotal() << endl;
	}
	cout << "Press Enter to Exit...";
	getline(cin, stemp);

	fout.close();



}
Last edited on
Topic archived. No new replies allowed.