Question

I need help writing c++ code to make this program. 1. Define a function that can...

I need help writing c++ code to make this program.

1. Define a function that can read the input file answers.dat. This function should not

print anything.

2. Define a function that computes the quiz score of the function by comparing the

correct answers to the student’s answer. The result should be a percentage between

0 and 100, not a value between 0 and 1. This function should not print anything.

3. Define a function that prints the report as shown in the sample run below. The

report format should be exactly the same: alignment, numbers after decimal points,

and so on. For incorrect answers, print INCORRECT as shown next to the wrong

answers.

The only change is that your name should be printed as the top label to indicate you

were the developer.

4.The main() function should create the necessary variables and use the three

functions above. The main() function should not print anything.

I need to write a program the helps your instructor grade quizzes. The program will read a file containing a single students answers to a quiz. It will compute the student grade on the test as a percentage and then print report.

CSCI-2010 Assignment 1

50 Points

OBJECTIVES

This assignment will ensure that you have installed Visual Studio

1

, and can submit

assignments correctly in D2L. It will also help you review C++ from CSCI 1010.

Please start early. Let me know as soon as possible if you have problems installing or using

Visual C++ 2013, or trouble finding your .cpp files for submission.

Grading quizzes

Write a program helps your instructor grade quizzes. The program will read a file

containing a single student’s answers to a recently given quiz. It will compute the student’s

grade on the test as a percentage, and then print a report.

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 student name is always the first line.

A student name may or may not have last names. For example, both

Elvis Presley and Cher took this class.

A quiz always has 11 questions.

There is one answer per line. Each answer is one word and all lowercase.

The correct answers to the quiz questions were:

1.C++

2.for

3.if

4.variable

5.function

6.return

7.array

8.void

9.reference

10.main

11.prototype

0 0
Add a comment Improve this question Transcribed image text
Answer #1

AS the question suggested I have created the program although i wasn't clear in which function i should print the outputs. so i printed it in the main function. You can change according to the need.OR comment it i will modify it as soon as possible.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
fstream newfile,newfile1;
string name;
string a[11]={"c++","for","if","variable","function","return","array","void","reference","main","prototype"};
std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
str.erase(0, str.find_first_not_of(chars));
return str;
}

std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
str.erase(str.find_last_not_of(chars) + 1);
return str;
}
std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
return ltrim(rtrim(str, chars), chars);
}
void reading()
{
newfile.open("answere.txt",ios::in);//open a file to perform read operation using file object
newfile1.open("answere.txt",ios::in); // for printing incorrect answeres
}
float quizscore()
{
int c=0,i=0;
//String b[11];
if (newfile.is_open()){ //checking whether the file is open
string tp;
getline(newfile,tp);
name=tp;
while(getline(newfile, tp)){ //read data from file object and put it into string.
std:: string x=tp;
trim(x); //trimming the string to get the string without any newline character
if(x.compare(a[i])==0)
c++;
i++;

}
//
return (c);
newfile.close(); //close the file object.
}
}
void print()
{
string tp;
int i=0;
getline(newfile1,tp);
while(getline(newfile1, tp)){ //read data from file object and put it into string.
std:: string x=tp;
trim(x); //trimming the string to get the string without any newline character
if(x.compare(a[i])!=0)
cout<<x<<" Incorrect";
i++;
}
newfile1.close();
  
}
int main(){
reading();
float a=quizscore();
cout<<name;
cout<<"\n"<<(a/11)*100<<"%"<<"\n";
print();
return 0;
  
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
I need help writing c++ code to make this program. 1. Define a function that can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is subject of C++ Your program should read the file answers.dat. This file contains the...

    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 student name is always the first line. A student name may or may not have last names. For example, both Elvis Presley and Cher took this class. A quiz always has 11 questions. There is one answer per line. Each answer is...

  • Language: C++ Write a program that will allow the instructor to enter the student's names, student...

    Language: C++ Write a program that will allow the instructor to enter the student's names, student ID, and their scores on the various exams and projects. A class has a number of students during a semester. Those students take 4 quizzes, one midterm, and one final project. All quizzes weights add up to 40% of the overall grade. The midterm exam is 25% while the final project 35%. The program will issue a report. The report will show individual grades...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp,...

    This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp, and Main.cpp 1. The system must be able to manage multiple students (max of 5) and their grades for assignments from three different assignment groups: homework (total of 5), quizzes (total (total of 2) of 4), and exams 2. For each student record, the user should be able to change the grade for any assignment These grades should be accessible to the gradebook for...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • You are creating a new data type for tracking student’s grades. Create a C++ project in...

    You are creating a new data type for tracking student’s grades. Create a C++ project in your development tool. Add the header comment and the header files from your C++template.cpp file. Your program should do the following: • Declare an Enum named Grade. The Enum should have the grades A-F and have each grade correspond with A = 90, B = 80, C = 70, D = 60, F = 50. • Declare a variable of Grade type in your...

  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT