This is subject of C++
Your program should read the file answers.dat.
This file contains the name of the student who took the quiz, and
his answers for each question. The answers file has the following
format:
The correct answers to the quiz questions were:
Name your program pass1.cpp. Your program should meet the following requirements
The only change is that your name should be printed as the top label to indicate you were the developer.
/*******************
Pat Programmer
CSCI 2010 Section 03
Assignment 1
Programmed on Windows 7, Visual C++
This program does …
*******************/
You should obviously change the name to your name, the section to your section, the system to the system you used, and write a real description of the program
NOTE: You should not use pointers in this assignment. It is a review from last semester.
Sample Run
Suppose you have an answers.dat with these contents:
Elvis Presley
C++
for
if
variable
function
cheese
array
robots
reference
main
prototype
When you run your program, the output would be:
!!! Pat Programmer’s Most Excellent Quiz Reporter !!!
Report for Elvis Presley
CORRECT ANS STUDENT ANS
C++ C++
for for
if if
variable variable
function function
return cheese INCORRECT
array array
void robots INCORRECT
reference reference
main main
prototype prototype
QUIZ SCORE
81.82%
Note: Could you plz go this code and let me know if
u need any changes in this.Thank You
_________________
//answersFile.txt
Elvis Presley
C++
for
if
variable
function
cheese
array
robots
reference
main
prototype
__________________
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
//Declaring the function
void readAnswers(string answers[], int size, string&
name);
double calQuizScore(string questions[], string answers[], int
size);
void printReport(string questions[], string answers[], int size,
string name, double quizScore);
int main()
{
//defines an input stream for the data file
ifstream dataIn;
//setting the precision to two decimal places
std::cout << std::setprecision(2) << std::fixed;
//Declaring constants
const int size = 11;
string name;
//Declaring and initializing an array
string questions[] = { "C++", "for", "if", "variable", "function",
"return", "array",
"void", "reference", "main", "prototype" };
string answers[size];
//calling the functions
readAnswers(answers, size, name);
double quizScore = calQuizScore(questions, answers, size);
printReport(questions, answers, size, name, quizScore);
return 0;
}
/* This function will read the input file and
* populate the values into an array
*/
void readAnswers(string answers[], int size, string&
name)
{
string ans;
//defines an input stream for the data file
ifstream dataIn;
dataIn.open("answersFile.txt");
//checking whether the file name is valid or not
if (dataIn.fail()) {
cout << "** File Not Found **";
exit(0);
}
else {
getline(dataIn, name);
for (int i = 0; i < size; i++) {
getline(dataIn, ans);
answers[i] = ans;
}
dataIn.close();
}
}
// This function will calculate the quiz score
double calQuizScore(string questions[], string answers[], int
size)
{
double score = 0.0;
int cnt = 0;
for (int i = 0; i < size; i++) {
if (questions[i].compare(answers[i]) == 0)
cnt++;
}
score = ((double)cnt / size) * 100;
return score;
}
//This function will display the report
void printReport(string questions[], string answers[], int size,
string name, double quizScore)
{
cout << "\n\n!!! Pat Programmer’s Most Excellent Quiz
Reporter !!!" << endl;
cout << "Report for " << name << endl;
cout << "CORRECT ANS\tSTUDENT ANS" << endl;
for (int i = 0; i < size; i++) {
cout << setw(15) << left << questions[i] <<
setw(15) << left << answers[i];
if (questions[i].compare(answers[i]) != 0)
cout << setw(10) << right << "INCORRECT" <<
endl;
else
cout << endl;
}
cout << "QUIZ SCORE:" << quizScore
<<"%"<< endl;
}
_______________________
Output:
_______________Could you plz rate me well.Thank You
This is subject of C++ Your program should read the file answers.dat. This file contains the...
c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....
Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
In c++ Write a program that contains a class called Player. This class should contain two member variables: name, score. Here are the specifications: You should write get/set methods for all member variables. You should write a default constructor initializes the member variables to appropriate default values. Create an instance of Player in main. You should set the values on the instance and then print them out on the console. In Main Declare a variable that can hold a dynamcially...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything. Your function should be named...
C++ 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. (Lab2b.cpp) Write a...
Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...
Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...
For your second program, please read the data from the input file directly into an array. (You may safely dimension your array to size 300.) Then close the input file. All subsequent processing will be done on the array. Your program should have two functions besides main(). The first function will print out the contents of the array in forward order, 10 numbers per line, each number right justified in a 5 byte field. The second function will print out...
PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...