IP requirements:
Load an exam
Take an exam
Show exam results
Quit
Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file.
Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g., "Good job" or "Better luck next time") Upon completion of the exam, the program should return the user to the menu.
Choice 3: The program should display the total points available and the total points scored during that exam. A percentage score should also be displayed. (Optional: if you choose to track which problems were missed, you could display that information for the user.)
Choice 4: No change to this functionality from the Phase 4 IP. You should consider creating an additional class Student that will track student's score through methods such as addPointsPossible, addPointsScored, getPointsPossible, and getPointsScored. You should also enhance your Exam class to include methods getPointValue and getAnswer. You may also want to add a method to only display one question at a time, such as displayQuestion.
having the header file student.h is throwing errors and pragma once is also throwing errors. I use dev c++ I have googled and tried different things to get it to compile and run properly to no avail. Please give me some assistance with this thanks.
code I am working with. -----------
//student.h
#pragma once
#include <string>
#ifndef STUDENT_H
#define STUDENT_H
using namespace std;
class Student
{
private:
double pointsPossible;
double pointsScored;
public:
Student()
{
pointsPossible = 0.0;
pointsScored = 0.0;
}
void addPointsPossible(double p)
{
pointsPossible += p;
}
void addPointsScored(double p)
{
pointsScored += p;
}
double getPointsPossible()
{
return pointsPossible;
}
double getPointsScored()
{
return pointsScored;
}
};
#endif
//Exam.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include "Student.h"
//Use the standard namespace.
using namespace std;
//Define the class Test.
class Test
{
private:
//Create an object of the string class to store the
name of the file.
string testfile;
public:
//Declare the default constructor.
Test();
//Declare the parameterized constructor.
Test(string);
//Declare the function to load the file.
bool loadfile();
//Declare the function to display the file.
void displayfile();
//Declare the function to display quetions one at a
time.
void displayQuestion(Student*);
//Declare the function to get point value.
double getPointValue();
//Declare the function to get answer.
char getAnswer();
};
//Define the default constructor.
Test::Test()
{
//Initialize the file name with default value.
testfile = "";
}
//Define the parameterized constructor.
Test::Test(string filename)
{
//Initialize the file name with the parameter.
testfile = filename;
}
//Define the function to load the file.
bool Test::loadfile()
{
//Open the file in read mode.
ifstream file(testfile.c_str());
//Check if the file exists or not.
if (!file)
{
//Display the error message.
cout << "\nFile not
found.";
//Return the value false.
return false;
}
//Close the file.
file.close();
//Return the value true.
return true;
}
void Test::displayQuestion(Student *s)
{
//Open the file in read mode.
ifstream file(testfile.c_str());
//Create an object of the string class.
string temp;
char ans;
getline(file, temp);
cout << endl << temp;
getline(file, temp);
//Start the while loop till end of file.
while (!file.eof())
{
if (atoi(temp.substr(0, 1).c_str())
!= 0)
{
cout <<
"\nEnter Your answer : ";
cin >>
ans;
s->addPointsPossible(1);
s->addPointsScored(1);
cout <<
endl << temp;
getline(file,
temp);
}
else
{
cout <<
endl << temp;
getline(file,
temp);
}
}
cout << endl << temp;
cout << "\nEnter Your answer : ";
cin >> ans;
s->addPointsPossible(1);
s->addPointsScored(1);
//Close the file.
file.close();
}
//Define the function to display the file.
void Test::displayfile()
{
//Open the file in read mode.
ifstream file(testfile.c_str());
//Create an object of the string class.
string temp;
//Start the while loop till end of file.
while (!file.eof())
{
//Read a line from the file and
store in temp.
getline(file, temp);
//Display the string.
cout << endl <<
temp;
}
//Close the file.
file.close();
}
//Define the main() function.
int main()
{
//Create an object of string class to store the name
of the file.
string filename;
//Create variable to store the input.
bool check;
char c = 'y';
Student *s = new Student();
//Start the while loop.
while (c == 'y' || c == 'Y')
{
//Create a variable of int
type.
int select = 0;
//Display the main menu.
cout << "EXAM
MENU\n\n";
cout << "1. Load an exam"
<< endl;
cout << "2. Take an exam"
<< endl;
cout << "3. Show exam
results" << endl;
cout << "4. Quit." <<
endl;
//Prompt the user to enter a
choice.
cout << "\nEnter your choice
: ";
//Store the user input.
cin >> select;
//Check if the user entered the
first option.
if (select == 1)
{
//Prompt the
user to enter the name of the file.
cout <<
"Enter the filename : ";
//Store the
input in the string.
cin >>
filename;
//Create an
object of the Test class with the file name.
Test
t(filename);
//Call the
function to load the file.
check =
t.loadfile();
//Check if the
file exists or not.
if (check)
{
//Display status message.
cout << "\nLoaded successfully.";
//Prompt the user to enter the choice.
cout << "\nDo you want to display the
file? (y/n) : ";
//Store the input.
cin >> c;
//Check the value entered by the user.
if (c == 'y')
{
//Display the output
message.
cout << "\nThe content
of the file is as follows:\n";
//Call the function to
display the content of the file.
t.displayfile();
}
}
}
//Check if the user entered the
second option.
else if (select == 2)
{
//Prompt the
user to enter the name of the file.
cout <<
"Enter the filename : ";
//Store the
input in the string.
cin >>
filename;
//Create an
object of the Test class with the file name.
Test
t(filename);
//Call the
function to load the file.
check =
t.loadfile();
//Check if the
file exists or not.
if (check)
{
t.displayQuestion(s);
}
}
//Check if the user entered the
third option.
else if (select == 3)
{
cout <<
"Marks Obtained : " << s->getPointsScored() <<
endl;
cout <<
"Out of : " << s->getPointsPossible() << endl;
cout <<
"Percentage Marks : " << (s->getPointsScored() /
s->getPointsPossible()) * 100 << endl;
}
else if (select == 4)
{
break;
}
//Move to the else case.
else
{
//Display the
error message.
cout <<
"\nPlease enter a valid input.";
}
//Prompt the user to enter the
choice.
cout << "\nDo you want to
enter again? (y/n) : ";
//Update the value of the
variable.
cin >> c;
}
//Display the exiting message.
cout << "\nExiting from the program... Thank
you!" << endl;
//Return 0 and exit from the program.
return 0;
}
//output
---------------------I used Visual studio 2013, C++ language as well as DEV C++ ---------------
I found out that why it is throwing errors.
You are using "pragma once" in your header file.
Pragma once is a preprocessor directive designed to cause the current source file to be included only once in a single compilation. Pragma once advantages like : Avoidance of name clashes and improvement in compilation speed.
---------------DEV C++-----------------
So if you compiled more than once it will throw error like this.
If you removed the pragma once in your header file, you can compile more than once.
If you are getting Source file not compiled error, You need to compile source file, In our example Exam.cpp
So if you remove pragma once in your header file doesn't
make much difference in your small program.
You can remove if you want or you can add pragma once after the
program is created as per your expectation.
Your code have no other mistakes, I don't know about question and answer patterns, So i simply create a text file with sample data to show that program works fine.
----------Output Screenshot in Visual studio----------
----------Output Screenshot in DEV C++----------
-----------------Sample Text File----------
IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...
I need help with using the infile and outfile operations in C++... Here's my assignment requirements: Assignment: Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would like to know if she gained or lost on a particular investment. Write a program that allows Cindy to read input from a file called Stock.txt: 1. The...
Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode has its unique function member GetEmail() which returns the string variable "studentEmail". TtuStudentNode has its overriding "PrintContactNode()" which has the following definition. void TtuStudentNode::PrintContactNode() { cout << "Name: " << this->contactName << endl; cout << "Phone number: " << this->contactPhoneNum << endl; cout << "Email : " << this->studentEmail << endl; return; } ContactNode.h needs to have the function...
Topics c ++ Loops While Statement Description Write a program that will display a desired message the desired number of times. The program will ask the user to supply the message to be displayed. It will also ask the user to supply the number of times the message is to be displayed. It will then display that message the required number of times. Requirements Do this assignment using a While statement. Testing For submitting, use the data in the...
In c++ Please. Now take your Project 4 and modify it. You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files. One (.h) file for the class definitions, both of them. The class implementation file which has the member function definitions. And the main project file where your main...
PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Linked-List class definition //============================================================================ /** * Define a class containing data members and methods to *...
C++ program. int main() { Rectangle box; // Define an instance of the Rectangle class double rectWidth; // Local variable for width double rectLength; // Local variable for length string rectColor; // Get the rectangle's width and length from the user. cout << "This program will calculate the area of a\n"; cout << "rectangle. What is the width? "; cin >> rectWidth; cout << "What is the length? "; cin >>...
Please use my Lab 3.2 code for this assignment Lab 4.2 instruction Using the code from lab 4.1, add the ability to read from a file. Modify the input function: * Move the input function out of the Cargo class to just below the end of the Cargo class * At the bottom of the input function, declare a Cargo object named temp using the constructor that takes the six parameters. * Use the Cargo output...
I'm not getting out put what should I do I have 3 text files which is in same folder with main program. I have attached program with it too. please help me with this. ------------------------------------------------------------------------------------ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A...
Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be used to compare two objects to see if they are equal. For our purposes, two objects are equal if their abbreviation and uldid are the same. You’ll need to make your overloaded operator a friend of the Cargo class. Create a unit1 object and load it with this data: uld – Pallet abbreviation – PAG uldid – PAG32597IB aircraft - 737 weight – 3321...