Answer to Question #339919 in C++ for wayne

Question #339919

Write a program in which inheritance and other oop concepts are used. 


You have to write code in which we will get the output of quiz test. 


Player enter the name and roll no and quiz test will start


You should use fstream and question will be in in .txt file

( The question you copied are as follow

1.WHEN COMPUTER WAS FIRST INVENTIONED?

a.1822

b.1823

c.1834

d.1922

a

2.WHO kILLED PRESEDENT BENOGIR VUTTO?

a.nawaz shrif

b.pervase

c.non of them

d.political leder

c

3.WHO IS THE CAPTAIN OF BANGLADESH CRICKET TREAM?

a.asharaful

b.murtaja

c.rafiq

d.aftab

a

4.WHAT IS OUR NATIONAL GAME?

a.cicket

b.football

c.hadodo

d.badminton

c

5.WHO IS NOW CHIEFJUSTICS IN BANGLADESH?

a.yeaz uddin

b.moin

c.jalil

d.fakhar uddin

d

6.WHO IS THE PRIME MINISTER OF INDIA?

a.sonia gundi

b.rajib gundi

c.autol biharipal

d.pervase

c

7.WHAT IS THE DATE OF SIDDR ORCUS?

a.16th nov

b.17th nov

c.18th nov

d.20th n0v

a

8.WHEN WILL BE THE NEXT WORLD CUP CRICKET?

a.2011

b.2012

c.2009

d.2008

a


)


20 marks


1
Expert's answer
2022-05-11T13:52:18-0400
#include<iostream>
#include<string>
#include<fstream>


using namespace std;


class Player
{
	string name;
	int rollNo;
public:
	Player(){}
	Player(string _name, int _rollNo)
	:name(_name), rollNo(_rollNo){}
	void Assign()
	{
		cout << "Please, enter a name of player: ";
		cin >> name;
		cout << "Please, enter a rollNo of player: ";
		cin >> rollNo;
	}
	void DisplayPlayer()
	{
		cout << "\nPlayer`s name: " << name
			<< "\nPlayer`s roll no: " << rollNo;


	}
};


class Quiz :public Player
{
	float result;
public:
	Quiz():result(0){}
	Quiz(string _name, int _rollNo) :result(0),Player(_name, _rollNo) {}
	void AddValue() { result += 10;}
	void StartQuiz()
	{
		cout << "Your are welcome in a quiz!\n"
			<< "Rules:\n correct answer 10 points\n"
			<< "No correct answer 0 points\n"
			<< "Max result - 80 points\n";
		ifstream ifs("in.txt");
		if (!ifs.is_open())
			cout << "File isn`t opened!";
		else
		{
			string line;
			char ch;
			int n = 0;
			while (getline(ifs, line, '\n'))
			{
				cout << line << endl;
				if (n % 5 == 4)
				{
					
					cout << "\nYour select: ";
					cin >> ch;
					if (((n == 4 )|| (n == 14)|| (n == 34) || (n == 39)) && ch == 'a')
						AddValue();
					if (((n == 9)||(n==19) || (n == 29)) && ch == 'c')
						AddValue();
					if ((n == 24) && ch == 'd')
						AddValue();
				}
				n++;
			}
		}
	}
	void Display()
	{
		DisplayPlayer();
		cout << "\nYour result is " << result;
	}
};




int main()
{
	Quiz q;
	q.Assign();
	q.StartQuiz();
	q.Display();
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS