Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C + + , improve the code by creating a separate program, but using the same Questions class to load a text file with

In C++, improve the code by creating a separate program, but using the same Questions class to load a text file with the questions (if it exists), allow to edit the list of questions and save them. Then make the first program to load the questions from the file.
#ifndef QUESTION_H
#define QUESTION_H
#include
class Question
{
private:
std::string question;
std::string ans1;
std::string ans2;
std::string ans3;
std::string ans4;
int correct;
public:
Question( std::string q, std::string a1, std::string a2, std::string a3, std::string a4, int c )//constructor
{ question = q; ans1= a1; ans2= a2; ans3= a3; ans4= a4; correct = c;}
void data() const
{std::cout << question <<"/"<< ans1<<"/"<< ans2<<"/"<< ans4<<"|"<< correct << std::endl;}
//std::string, std::cin, std::cout
};
#endif // CLASSNAME_H
#include
//#include
#include "Question.h"
using namespace std;
//prototypes (USE ONLY IF YOU WILL USE FUNCTIONS)
int main()
{
//ifstream ifile;
Question quest[10]={ Question("4+2=","3","2","6","7",3),
Question("Fastest land animal", "Cheetah", "Mouse", "Turtle", "Snail", 1),
Question("Largest State in US", "Texas", "California", "Florida", "Alaska", 4),
Question("Stinkiest flower", "Rose", "Titan-arum", "Tulip", "Hydrangea", 2),
Question("Biggest dog breed", "ShiTzu", "Pitbull", "Bulldog", "English-Mastiff", 4),
Question("Color of the sun", "Green", "Pink", "Yellow", "Red", 3),
Question("Longest-running soap opera", "Days-of-our-lives", "Guiding-Light", "Baywatch", "General-Hospital", 2),
Question("Highest grossing Disney movie", "Frozen2", "Little-Mermaid","The-Lion-King", "Beauty-and-the-Beast", 3),
Question("Color of the sky", "Blue", "White", "Grey", "Brown", 1),
Question("Capitol of Peru", "Caracas", "Lima", "Quito", "Monaco", 2)};
for (int i =0; i <10; i++)
quest[i].data();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions