|
See this[^] thread - we covered it all there.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
See here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It's the weekend and the lazy assed homework seekers have started coming out of the woodwork.
Doing my part to piss off the religious right.
|
|
|
|
|
thanks for the response...
"could you if you could," help with a start on getting the two files into an array for comparison to get a 0 or 1 value and the add 1 to counter with printed results.? YOU'LL SEE ME GROW I'm new and will not give up.. eventually I'll have the chance to be knowledgeable and help lazy homeworkers. If not, could you point me to another person with a sense of humor.
project for c++ and need help. Source CODE IN C++
the word problem:
the department of motor vehicles administers a written driver's exam consisting of 20 multiple choice questions. an applicant for the drivers license exam answers these questions electronically and the answers are stored in a file named xxxxyyy.dat (where xxxx are the last four digits of the ID number, and the yyy are the first three letters of their last name) in other words, each applicants file will be uniquely named. the file containing the correct answers to questions is named ANSWERS.DAT
write a program that will read the contents of the ANSWERS.DAT file into an array (with the size of 20). program should read the applicants answer file into a second array (also 20) the logic of the program should the 'check' the applicants answer to a question and compare it to the 'correct' answer. the program should keep a tally of the number of questions correctly answerd, and the tally of incorrect answers. Finally the program should cout whether or not the applicant 'passed' or 'failed' the exam. they must answer at least 15 questions correctly to pass. program should indicate "PASS" or "FAIL" along with the number of INCORRECT and CORRECT.
following layout for program centered:
Department of Motor Vehicles
Driver's Exam
answered 99 questions correctly.
answered 99 questions incorrectly.
results for this portion of exam: XXXX
AND THATS ALL ALSO FOR AN EXAMPLE .DAT FILE '1278BOB.DAT' AND MULTIPLE CHOICE a,b,c,d
|
|
|
|
|
|
Okay, just this once since you're a newbie.
Read ANSWERS.DAT into a 20x1 array. Read the applicant's answers into the first column of a 20x2 array. Step through both arrays, comparing the values in the first column. If they agree, set the corresponding element in the second column of the applicant's array to 1; if not, set it to 0. After comparing all 20 answers, sum the values of the applicant's array second column and cout the total as the number of correct answers.
As an algorithm, this should do it. For C++ help, you're on your own. It confuses the hell out of me, so I've given up trying to learn it. Programming rached its epitome with Pascal, and languages have been declining ever since.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
|
johnzfrebbies@ wrote: I have a project for c++ and I need help for the first time. Source CODE IN C++
So why are you not asking ths question in a more appropriate forum?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
which one?
is there somewhere dedicated to tutoring help? or at least pointers in a correct direction?
I have a ways to go in my studies and knowledgable info is what I give in other areas of computer and OS technology, but in this language of c++ I find others perspectives to formulate algorithims more effecttive in learning and tuning to truely understand what I am doing. Some are wrong some are right but at least we all show a a meaningful insight with the best intentions at heart.
Thanks for at least being nice. John
|
|
|
|
|
johnzfrebbies@ wrote: which one?
Here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I believe your stuck with me if thats okay I've already be reprimanded for cross posting and I think you'll miss me if I go. I'll post there later to offer help or retain some helpful input. thanks for the tip.
|
|
|
|
|
I think you should at least make an attempt at a solution and post the partial code. See the thread underneath this one where the poster displayed his work and asked for help in where he went wrong. By doing this it shows that you put some effort into the problem yourself rather than just passing the workload onto the other members of this website.
I have no problem in helping people that put effort into finding a solution. I'm not going to do somebody's homework, however.
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
sorry about that. I was in the process of working it out and not expecting a full blown finished product by any means. any ways thanks for pointing that out. heres what I have so far..... I can' t get my files to read in and compare.
#include "iostream"
#include "fstream"
#include "string"
#include "iomanip"
using namespace std;
int main()
{
int i, correct = -1, incorrect = -1;
ifstream StudentAnsw;
StudentAnsw.open("C:\\driversexam.dat");
ifstream Answers;
Answers.open("C:\\Answers.dat");
char StudentA[20], answer[20];
cout << "\t\t\tTHESE ARE YOUR RESULTS.\n";
for(i = 0; i < 20; i++)
{
cout <<"Question " << (i+1) << " " << endl;
Answers >> answer[i];
StudentAnsw >> StudentA[i];
if(StudentA[i] == answer[i])
{
//Answers >> answer;
//StudentAnsw >> StudentA;
cout << " Was answered correctly.\n";
correct++;
}
else
{
cout << StudentA[i] << " is an incorrect choice.\n";
incorrect++;
}
}
correct = correct++;
incorrect = incorrect++;
cout << "\t\t\tYou answered " << correct << " questions correctly.\n";
cout << "\t\t\tYou answered " << incorrect << " questions incorrectly.\n";
if (correct >= 15)
{
cout << "\n\t\t\tCONGRATUATIONS! \n\t\t\t\tYOU HAVE PASSED THE DRIVER'S LICENSE TEST.\n\a\a";
cout << "\t\t\t\tDON'T DRINK AND DRIVE" << endl;
}
else
{
cout << "\nSorry. You FAILED! the Driver's License Exam.\n";
cout << "\nYou need 15 correct answers to pass the exam.\n";
cout << "\nPlease Study and stay of the road. \n";
}
system("pause");
StudentAnsw.close();
Answers.close();
return 0;
}
|
|
|
|
|
johnzfrebbies@ wrote: I can' t get my files to read in and compare.
So what's the problem?
johnzfrebbies@ wrote: correct = correct++;
incorrect = incorrect++;
Are you sure this is what you want?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hey thanks I corrected that and changed the counter to 0. but still can' read in files for comparison.
|
|
|
|
|
Okay, your code seems correct. To be sure, I copied and compiled your program. For input I used the text file C:\driversexam.dat containing the numbers 1 to 20 and then in Answers.dat I also put the numbers 1 to 20, but I mixed a few up to simulate incorrect answers (Note: this will work with both numbers and characters).
It seems to work correctly.
Here is the output:
THESE ARE YOUR RESULTS.
Question 1
Was answered correctly.
Question 2
Was answered correctly.
Question 3
4 is an incorrect choice.
Question 4
3 is an incorrect choice.
Question 5
Was answered correctly.
Question 6
Was answered correctly.
Question 7
Was answered correctly.
Question 8
Was answered correctly.
Question 9
Was answered correctly.
Question 10
Was answered correctly.
Question 11
Was answered correctly.
Question 12
Was answered correctly.
Question 13
Was answered correctly.
Question 14
Was answered correctly.
Question 15
Was answered correctly.
Question 16
Was answered correctly.
Question 17
Was answered correctly.
Question 18
Was answered correctly.
Question 19
Was answered correctly.
Question 20
Was answered correctly.
You answered 18 questions correctly.
You answered 2 questions incorrectly.
CONGRATUATIONS!
YOU HAVE PASSED THE DRIVER'S LICENSE TEST.
DON'T DRINK AND DRIVE
Press any key to continue . . .
So it seems to work. Have you placed driversexam.dat and Answers.dat in C:\? You've hard-coded the directory structure, so make sure you have the files to be read in the right location. If not, maybe you could provide some more description regarding the problem.
|
|
|
|
|
I don't under stand what I'm doing wrong?..please advise
#include "iostream"
#include "fstream"
#include "string"
#include "iomanip"
using namespace std;
int main()
{
int i;
//int x;
int correct;
int incorrect;
ifstream StudentAnsw;
ifstream Answers;
StudentAnsw.open("C:\\driversexam.dat");
Answers.open("C:\\Answers.dat");
char StudentA[20];
char answer[20];
cout << "THESE ARE YOUR RESULTS.\n";
correct = 0;
incorrect = 0;
for(i = 0; i < 20; i++)
{
cout <<"Question " << (i+1) << " " << endl;
Answers >> answer[i];
StudentAnsw >> StudentA[i];
if (StudentA == answer)
{
cout << " " << " Is a correct answer." << endl << endl;
correct++;
}
else
{
cout << " " << " Is a incorrect choice." << endl;
incorrect++;
}
}
system("pause");
system("CLS");
cout << "You answered " << correct << " questions correctly.\n";
cout << "You answered " << incorrect << " questions incorrectly.\n";
if (correct >= 15)
{
cout << "\nCONGRATUATIONS! \nYOU HAVE PASSED THE DRIVER'S LICENSE TEST.\n";
cout << "DON'T DRINK AND DRIVE" << endl;
}
else
{
cout << "\nSorry. You FAILED! the Driver's License Exam.\n";
cout << "\nYou need 15 correct answers to pass the exam.\n";
cout << "\nPlease Study and stay of the road. \n";
}
StudentAnsw.close();
Answers.close();
return 0;
}
|
|
|
|
|
johnzfrebbies@ wrote: please advise
You have already been advised here. You stated that your code does not work, yet you fail to indicate what it is doing wrong. Have you used the debugger to find out why?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
for(i = 0; i < 20; i++)<br />
{<br />
cout <<"Question " << (i+1) << " " << endl;<br />
Answers >> answer[i];<br />
StudentAnsw >> StudentA[i]; <br />
if (StudentA == answer) <br />
{<br />
cout << " " << " Is a correct answer." << endl << endl;<br />
correct++;<br />
}<br />
else<br />
{<br />
cout << " " << " Is a incorrect choice." << endl;<br />
incorrect++;<br />
}
See the line I have commented above. You need to compare elements of the arrary. Thus, the indicated line should be:
if (StudentA[i] == answer[i])
Change that and it should work.
|
|
|
|
|
#include "iostream"
#include "fstream"
#include "string"
#include "iomanip"
using namespace std;
int main()
{
int i, correct = 0, incorrect = 0;
ifstream StudentAnsw;
StudentAnsw.open("C:\\driversexam.dat");
ifstream Answers;
Answers.open("C:\\Answers.dat");
char StudentA[20], answer[20];
cout << "\t\t\tTHESE ARE YOUR RESULTS.\n";
for(i = 0; i < 20; i++)
{
cout <<"Question " << (i+1) << " " << endl;
Answers >> answer[i];
StudentAnsw >> StudentA[i];
if(StudentA[i] == answer[i])
{
//Answers >> answer;
//StudentAnsw >> StudentA;
cout << " Was answered correctly.\n";
correct++;
}
else
{
cout << StudentA[i] << " is an incorrect choice.\n";
incorrect++;
}
}
cout << "\t\t\tYou answered " << correct << " questions correctly.\n";
cout << "\t\t\tYou answered " << incorrect << " questions incorrectly.\n";
if (correct >= 15)
{
cout << "\n\t\t\tCONGRATUATIONS! \n\t\t\t\tYOU HAVE PASSED THE DRIVER'S LICENSE TEST.\n\a\a";
cout << "\t\t\t\tDON'T DRINK AND DRIVE" << endl;
}
else
{
cout << "\nSorry. You FAILED! the Driver's License Exam.\n";
cout << "\nYou need 15 correct answers to pass the exam.\n";
cout << "\nPlease Study and stay of the road. \n";
}
system("pause");
StudentAnsw.close();
Answers.close();
return 0;
}
|
|
|
|
|
What is the structure of ANSWERS.DAT? Is this a text file? Binary? If text, can you post a couple lines of the content?
Please see my reply above.
modified on Wednesday, April 30, 2008 2:29 AM
|
|
|
|
|
I still have not got the program to display the answers whether correct or incorrect. I'm also trying to get user input by typing file name&num so I can read in that file and compare it to the answers. also I will finish it off with a MAXSIZE array in case the exam consists of more than 20 questions. what I need the most is some help with the syntax for the input from user that consists of NameNum.dat . Should I use a pointer that initiates a search? then store it, After that hows the correct way to open it to read and thus use it? I'm okay with the closing it....obviously. oh! and by the way...this is really wierd but anyways, I have some guys in my course and I inquired for some general input it as what I'm doing wrong. I just wanted to Know if my flowchart was close to accurate. Come to find out no one takes time to do them. but they do have their coverpage with source code and printed executed program. I was shown the source code one guy populated. He had the same parenthesis " " in his header file along with the missing variable [i] and a source code that just so happened to have the same executable and declarative statements. what are the odds of that! when I temporally used those statements for my own recognition until I was complete with a properly working lab with the assigned listed names that were provided on the problem page. well anyways I was quite amused and curious to how he thinks he is the only one to utilize constructive peer tutorials. So I will not be using this assignment in my course. I do however want to figure it out. It will not recieve a grade but this piece of work will be one of my finest. thanks for your help in helping me see why people like me (newbie)can be pretty sh*tty. I believe I've moved up one level in an ethical computer community. (willbie)
#include "iostream"
#include "fstream"
#include "string"
#include "iomanip"
using namespace std;
int main()
{
int i;
//int x;
int correct;
int incorrect;
ifstream StudentAnsw;
ifstream Answers;
StudentAnsw.open("C:\\driversexam.dat");
Answers.open("C:\\Answers.dat");
char StudentA[20];
char answer[20];
i = 0;
Answers >> answer[i];
StudentAnsw >> StudentA[i];
while(Answers.eof() == false)
{
i++;
Answers >> answer[i];
StudentAnsw >> StudentA[i];
}
//return 0;
cout << "THESE ARE YOUR RESULTS.\n";
correct = 0;
incorrect = 0;
for(i = 0; i < 20; i++)
{
cout <<"Question " << (i+1) << " " << endl;
if (StudentA[i] == answer[i])
{
cout << " " << " Is a correct answer." << endl << endl;
correct++;
}
else
{
cout << " " << " Is a incorrect choice." << endl;
incorrect++;
}
}
system("pause");
system("CLS");
cout << "You answered " << correct << " questions correctly.\n";
cout << "You answered " << incorrect << " questions incorrectly.\n";
if (correct >= 15)
{
cout << "\nCONGRATUATIONS! \nYOU HAVE PASSED THE DRIVER'S LICENSE TEST.\n";
cout << "DON'T DRINK AND DRIVE" << endl;
}
else
{
cout << "\nSorry. You FAILED! the Driver's License Exam.\n";
cout << "\nYou need 15 correct answers to pass the exam.\n";
cout << "\nPlease Study and stay of the road. \n";
}
StudentAnsw.close();
Answers.close();
return 0;
}
|
|
|
|
|
johnzfrebbies@ wrote: I still have not got the program to display the answers whether correct or incorrect.
I'm not sure why - the code I posted worked perfectly.
johnzfrebbies@ wrote: I'm also trying to get user input by typing file name&num so I can read in that file and compare it to the answers. also I will finish it off with a MAXSIZE array in case the exam consists of more than 20 questions. what I need the most is some help with the syntax for the input from user that consists of NameNum.dat
If I understand you correctly, you want the user to input the name of the file to be read. We'll be consistent and use ifstream although there are other file functions one could use. We can proceed as follows.
We need to pass a FileName to ifstream . The FileName is, of course the name of the file we want to open for reading.
First we need an array to hold the file name the user inputs. We'll be consistent with the rest of your program and use an array of size 20:
char FileName[20];
At this point you need to use cout and cin to get the filename from the user. I think you can write the code for that. Finally, we'll use your existing Answers ifstream for reading:
ifstream Answers;
Answers.open(FileName);
It's a good idea to check that the file name we entered corresponds to an existing file. We can do that by checking to see if Answers is NULL :
if (!Answers)
{
cout << "Cannot open file." << endl;
system("PAUSE");
exit(1);
}
Putting it all together:
char FileName[20];
cout << "Enter a filename: ";
cin >> FileName;
ifstream Answers;
Answers.open(FileName);
if (!Answers)
{
cout << "Cannot open file." << endl;
system("PAUSE");
exit(1);
}
Of course you can modify this to suit your specific needs, but that's just a basic way to read in a file and get input from it. You could do something different than exit the program if the input file name isn't valid. For example, you could prompt the user to enter another name.
Hope that helps!
|
|
|
|
|
hey Thanks! The code you posted works great and gave me a better understanding by example. Thats what I need to fully understand what I'm doing.
I'll post my full code later today with the modifications, just so and if anyone else needs an example they can be directed to. Thanks again for your help.
|
|
|
|
|
johnzfrebbies@ wrote: hey Thanks! The code you posted works great and gave me a better understanding by example. Thats what I need to fully understand what I'm doing.
I'll post my full code later today with the modifications, just so and if anyone else needs an example they can be directed to. Thanks again for your help.
Okay, great. Glad it worked out.
|
|
|
|