lab9 - 0."Quiz.dat"); //Open the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Tom Nanke //CIS 150-001 //11-6-07 //Lab 9 // This program grades a set of true/false tests. It first reads from file "Quiz.dat" the //correct answer to a question, then reads the student's answer for that question. It keeps //track of whether or not each question was answered correctly, and prints out the student's //name, followed by the number of questions answered correctly and the number of questions //answered incorrectly. / #include <iostream> #include <fstream> #include <string> using namespace std; u const int MAX=15; //There are 15 questions / int main () { fstream inData; int numberRight=0; //Initializiing the number right to 0. int numberWrong=0; //Initializing the number wrong to 0. / struct StudentEval //Data structure containing strings that will represent { //the correct answer and the student's answer. string correctAnswer; string answer; }; StudentEval questions[MAX]; //Array containing the answers to the test int counter=0; //Initialization of the counter to
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0."Quiz.dat"); //Open the data file. for (counter = 0; counter < MAX; counter++) //Loop will read and store the answers { //it reads from file until it reads the inData>>questions[counter].correctAnswer; //last one. inData>>questions[counter].answer; } cout<<endl; for (counter = MAX - 1; counter >= 0; counter--) //This loop keeps track of the number { //righ t and the number wrong. if(questions[counter].answer==questions[counter].correctAnswer) numberRight++; n if(questions[counter].answer!=questions[counter].correctAnswer) numberWrong++; } for (counter = 0; counter < MAX; counter++) { cout<<questions[15].answer<<endl; //Outputs the last item from the file, which would be the cout<<" got " <<numberRight<< " questions right."<<endl; //student's name, and then outputs the number right and cout<<" and " <<numberWrong<< " questions wrong."<<endl; //the number wrong. } return 0; }...
View Full Document

This note was uploaded on 04/25/2010 for the course CECS CIS 150 taught by Professor L.tsui during the Fall '07 term at University of Michigan-Dearborn.

Page1 / 2

lab9 - 0."Quiz.dat"); //Open the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online