6 Replies - 1315 Views - Last Post: 19 November 2009 - 02:08 AM Rate Topic: -----

#1 thebeast91   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 26-October 09

Scoring Students

Posted 16 November 2009 - 10:49 PM

I need to write a program using arrays and strings.Here is the question.
A class of students takes a 20 question multiple-choice exam;each question has 5 choices(a,b,c,d,e)only one of them are correct.In "tests.dat"Each record of which consists of a student id, followed by a blank, followed by students 20 responses. In "answers.dat" which consists of a single record, namely the correct answers to the exam.Then It needs to produce a grade summary report like this.If the answer is correct it should put a "*" by the correct answer


student-id number correct
1231231212312 12
1233424325435 25
.... ...






question A B C D E
1 5 1 13* 3 1
2 4 7* 5 12 7
.
.
...



this is what i got so far.Thank you

#include <iostream>
#include <fstream>

using namespace std;
int main()
{
ifstream fin ans,fin tests;
char key[21],id[21],response[21];
int count[20][5];

fin ans>>key;
fin tests>>>id>>response;

for(i=0,i<20,i++)
{
if(key[i] ==responses[i])
{
	num correct ++;
count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A'] &&"*"<<endl;
else(key[i] !=responses[i]){
	count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A']<<endl;
}
}
}




fin ans.open("answers.dat");
if(fin.fail("answers.dat"))
{
	cout<<"Error opening stream"<<endl;
	abort();
}
fin tests.open("tests.dat");
if(fin.fail("tests.dat"))
{
	cout<<"Error opening stream"<<endl;
	abort();
}

cout<<id<<correct<<<endl<<endl;
cout<<count<<"A		B		C		D		E"<<
	<<key<<count[i][responses[i]-'A']

return 0;

}



Is This A Good Question/Topic? 0
  • +

Replies To: Scoring Students

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Scoring Students

Posted 17 November 2009 - 05:30 AM

I'll start you off with this fact: you can't have spaces in variable names, like you have here:
ifstream fin ans,fin tests;

But you need to tell US:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 thebeast91   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 26-October 09

Re: Scoring Students

Posted 17 November 2009 - 11:32 AM

View PostJackOfAllTrades, on 17 Nov, 2009 - 04:30 AM, said:

I'll start you off with this fact: you can't have spaces in variable names, like you have here:
ifstream fin ans,fin tests;

But you need to tell US:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Well I did not know how to start. I sat down and wrote this code I know It is not readable bc I was so confused with the code. I need to someone to guide me
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Scoring Students

Posted 17 November 2009 - 11:41 AM

This is not a tutoring service, so someone guiding you when you don't know where to start is a bit difficult.

Perhaps you should start with getting some guidance from the source...your teacher? Your teacher gets paid pretty decent money to teach you these things. If he or she is NOT teaching you properly, then you should go see him/her and see how he/she can help you. It *is* that for which they're paid, and assuming you're paying for your tuition...YOU are paying them!
Was This Post Helpful? 0
  • +
  • -

#5 thebeast91   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 26-October 09

Re: Scoring Students

Posted 17 November 2009 - 06:05 PM

View PostJackOfAllTrades, on 17 Nov, 2009 - 10:41 AM, said:

This is not a tutoring service, so someone guiding you when you don't know where to start is a bit difficult.

Perhaps you should start with getting some guidance from the source...your teacher? Your teacher gets paid pretty decent money to teach you these things. If he or she is NOT teaching you properly, then you should go see him/her and see how he/she can help you. It *is* that for which they're paid, and assuming you're paying for your tuition...YOU are paying them!



I didnt mean it like that ofcourse my teacher helps me I am just really confused in this part
its unreadable i wanted to read the correct answers get a count of them and add a "*"after the right answer

{
	num correct ++;
count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A'] &&"*"<<endl;
else(key[i] !=responses[i]){
	count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A']<<endl;
}
}
}

Was This Post Helpful? 0
  • +
  • -

#6 thebeast91   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 26-October 09

Re: Scoring Students

Posted 18 November 2009 - 07:17 PM

View Postthebeast91, on 17 Nov, 2009 - 05:05 PM, said:

View PostJackOfAllTrades, on 17 Nov, 2009 - 10:41 AM, said:

This is not a tutoring service, so someone guiding you when you don't know where to start is a bit difficult.

Perhaps you should start with getting some guidance from the source...your teacher? Your teacher gets paid pretty decent money to teach you these things. If he or she is NOT teaching you properly, then you should go see him/her and see how he/she can help you. It *is* that for which they're paid, and assuming you're paying for your tuition...YOU are paying them!



I didnt mean it like that ofcourse my teacher helps me I am just really confused in this part
its unreadable i wanted to read the correct answers get a count of them and add a "*"after the right answer

{
	num correct ++;
count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A'] &&"*"<<endl;
else(key[i] !=responses[i]){
	count[i][responses[i]-'A']++;
cout<<count[i][responses[i]-'A']<<endl;
}
}
}


should i add this?
for(i=0;i<20;i++)
	{
		if(key[i] ==responses[i])
		{
		num correct ++;
			count[i][responses[i]-'A']++;
			cout<<count[i][responses[i]-'A'] &&"*"<<endl;
		} 
		else(key[i] !=responses[i])
		{
		count[i][responses[i]-'A']++;
			cout<<count[i][responses[i]-'A']<<endl;
		}
		if(key[i] ==responses[i])
		{
		num correct ++;
			count[i][responses[i]-'B']++;
			cout<<count[i][responses[i]-'B'] &&"*"<<endl;
		} 
		else(key[i] !=responses[i])
		{
		count[i][responses[i]-'B']++;
			cout<<count[i][responses[i]-'B']<<endl;
		}
		if(key[i] ==responses[i])
		{
		num correct ++;
			count[i][responses[i]-'C']++;
			cout<<count[i][responses[i]-'C'] &&"*"<<endl;
		} 
		else(key[i] !=responses[i])
		{
		count[i][responses[i]-'C']++;
			cout<<count[i][responses[i]-'C']<<endl;
		}
		if(key[i] ==responses[i])
		{
		num correct ++;
			count[i][responses[i]-'D']++;
			cout<<count[i][responses[i]-'D'] &&"*"<<endl;
		} 
		else(key[i] !=responses[i])
		{
		count[i][responses[i]-'D']++;
			cout<<count[i][responses[i]-'D']<<endl;
		}
		if(key[i] ==responses[i])
		{
		num correct ++;
			count[i][responses[i]-'E']++;
			cout<<count[i][responses[i]-'E'] &&"*"<<endl;
		} 
		else(key[i] !=responses[i])
		{
		count[i][responses[i]-'E']++;
			cout<<count[i][responses[i]-'E']<<endl;
		}
	}

Was This Post Helpful? 0
  • +
  • -

#7 thebeast91   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 26-October 09

Re: Scoring Students

Posted 19 November 2009 - 02:08 AM

this is wat i got and my code is still nor readable what can i do?

#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main()
{
	ifstream finans;
	ifstream fintests;
	char key[21];
	char id[12];
	char responses[21];
	int count[20][5];
	int i;
	int countA = 0;
	int countB = 0;
	int countC = 0;
	int countD = 0;
	int countE = 0;
	int numcorrect =0;
	int bob[2]={Student-id, Number Correct};

	finans.open("Answers.dat");
	if(fin.fail())
	{
		cout<<"Error opening stream"<<endl;
		exit(1);
	}
	fintests.open("Tests.dat");
	if(fin.fail())
	{
		cout<<"Error opening stream"<<endl;
		exit(1);
	}
	while(fintests.open("Tests.dat") && finans.open("Answers.dat")
	{
	fintests>>id>>responses
	for(int i=0; i < 20; i++)
	{
		fintests>>id[i]>>responses[i];
	}
	for(int i=0; i<20; i++)
	{
		finans>>key[i]
		if(key[i] ==responses[i])
		{
			numcorrect ++;
			if(responses=='A')
			{
			count[i][responses[i]-'A']++;
			}
			cout<<countA"*"
			else
			{
				cout<<countA" "
			}
			else
			{
				if(responses=='B')
				{
				count[i][responses[i]-'B']++;
				}
				cout<<countB"*"
				else
				{
					cout<<countB" "
				}
				else
				{
					if(responses=='C')
					{
						count[i][responses[i]-'C']++;
					}
					cout<<countC"*"
					else
					{
						cout<<countC" "
					}
					else
					{
						if(responses=='D')
						{
							count[i][responses[i]-'D']++;
						}
						cout<<countD"*"
						else
						{
							cout<<countD" "
						}
						else
						{
							if(responses=='E')
							{
								count[i][responses[i]-'E']++;
							}
							cout<<countE"*"
							else
							{
								cout<<countE" "
							}

						}

					}
				}
			}
		else(key[i] !=responses[i])
		{

		}
		
		cout<<bob[2]<<endl;
		cout<<id[12]<<"\t\t"<<numcorrect<<endl;


		cout<<count[20][5]<<endl;
		}
	}
return 0;
	
	}	

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1