C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 31st, 2005, 02:24 PM
codeless codeless is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 4 codeless User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 18 m 36 sec
Reputation Power: 0
Post Help with school assignment

trying to get the following work but 5 err/1 warning it seems futile.
The struct is not working.
How can I reduce the default constructor seems long.
is

PROBLEM
/*You will be writing a “Quiz Tutor” program. The program should begin by reading a question and 4 possible answers from a text file. It should display these to the user.
The user will select the answer from the choices.
The program will determine if the answer is correct and indicate this to the user.
If the answer is correct, the next question will be displayed.
If it is incorrect, the incorrect question will be stored in a list in order before displaying the next question.
At the end of the file the user has completed round one, the program should display the number of correct answers and a score (percent correct).
The program will then begin round 2.
The questions from the list of incorrectly answered questions will be redisplayed in order for the user to try again.
If the question is answered correctly this time the number of correct answers is increased.
If the user answers incorrectly the second time, the correct answer is displayed.
At the end of round 2, the quiz is over.
The program should display the new score along with the number of correct answers from the first round plus the number of correct answers from the second round.

*/


code:
Code:
/****Driver for quiz program. ****/

#include<iostream.h>
using namespace std;

#include "game.h"

void rnd_1();
void rnd_2(question &);

void main()
{

	rnd_1();
}



void rnd_1()
{
	question quiz;


	cout << "round 1 \n";

	for ( int i =0; i < quiz.get_quest_num(); i++)
	{
		quiz.display_question();
		quiz.process_rdn1();
	}

	quiz.display_score();
	if (get_ans_cor() == get_quest_num())
	
	{
		cout << " You got everythin right in first round \n";
		exit(1);
	}
	
	else
		rnd_2(quiz);
}

void rnd_2( question & quiz2)
{
	cout << "round 2 \n";

	for ( int i =0; i < quiz2.get_ans_wrg(); i++)
	{
		quiz2.display_wrg();
		quiz2.process_rdn2();
	}

	quiz2.display_score();
	cout << "Thank you for playing \n";
	exit(1);
}//end of driver

/***Game.cpp ----------------
              This file implements Game member functions.
              					
              																****/ 

#include <iostream>
using namespace std;

#include "game.h"


question::question() // default constructor
{
	ifstream in;
	string filename;


	quest_num = 0;
	ans_cor = 0;
	ans_wrg = 0;


	cout <<"Enter file name";
	cin >> filename;

	in.open(filename.c_str());

	assert(in.open());

	while(!in.eof())
	{

		getline(in, q_sub.quest);
		getline(in, q_sub.ans1);
		getline(in, q_sub.ans2);
		getline(in, q_sub.ans3);
		getline(in, q_sub.ans4);
		getline(in, q_sub.answer);
		rdone.enqueue(q_sub); //enque all question submitted	

		quest_num++;          // increase questions read from file
	}
}


void question::display_question()
{
	x_file q_disp = rdone.front();

	cout << q_disp.quest <<endl;
	cout << q_disp.ans1 <<endl;
	cout << q_disp.ans2 <<endl;
	cout << q_disp.ans3 <<endl;
	cout << q_disp.ans4 <<endl;

}

void question::process_rdn1()
{
	string ans;
	x_file q_disp = rdone.front();

	cout <<"Give your answer";
	cin >> ans;

	if ( ans == q_disp.answer)
	{
		cout<<"correct answer\n";
		ans_cor++;
		rdone.dequeue();
	}
	else
	{
		cout <<"Incorrect answer\n";
		ans_wrg++;
		rdtwo.enqueue(q_disp);
		rdone.dequeue();

	}
}


void question::display_wrg()
{
	x_file q_disp = rdtwo.front();

	cout << q_disp.quest <<endl;
	cout << q_disp.ans1 <<endl;
	cout << q_disp.ans2 <<endl;
	cout << q_disp.ans3 <<endl;
	cout << q_disp.ans4 <<endl;

}

void question::process_rdn2()
{
	string ans;
	x_file q_disp = rdtwo.front();

	cout <<"Give your answer";
	cin >> ans;

	if ( ans == q_disp.answer)
	{
		cout<<"correct answer\n";
		ans_cor++;
		ans_wrg--;
		rdtwo.dequeue();
	}
	else
	{
		cout <<"Incorrect answer\n";
		cout<<"The correct answer is "<< q_disp.answer<<endl;
		rdtwo.dequeue();

	}
}

void question::display_score()
{

	cout <<"Your total correct answer: "<< ans_cor << endl;
	cout <<"Your total incorrect answer: "<<ans_wrg; <<endl;
	cout <<" Your Score is "<< ans_cor << quest_num <<endl; // need type casting to double
}


int question::get_quest_num()
{
	return quest_num;
}

int question::get_ans_cor()
{
	return ans_cor;
}

int question::get_ans_wrg()
{
	return ans_wrg;
} //end of game.cpp

#include <iostream.h>
#include <string>
#include <fstream.h>
#include <assert.h>

#include "Queue.h"

#ifndef game
#define game

struct x_file
{
	string quest;
	string ans1;
	string ans2;
	string ans3;
	string ans4;
	string answer;
}; // end of struct

class Question
{

public:

	//--Constructors
	Question();
	
	//--Mutators
		void process_rdn1();
	void process_rdn2();
	
	//--Output
	void display_score();
	void display_wrg()
	void display_question();
	
	//--Accessors
	int get_quest_num();
	int get_ans_cor();
	int get_ans_wrg();

private:
	x_file q_sub; //struct from file

	queue<x_file> rdone; //initial questions
	queue<x_file> rdtwo; // incorrect question

	int ques_num;
	int ans_cor;
	int ans_wrg;

};  //end of class

#endif

Reply With Quote
  #2  
Old July 31st, 2005, 02:41 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by codeless
trying to get the following work but 5 err/1 warning it seems futile.
The struct is not working.
How can I reduce the default constructor seems long.
is

PROBLEM
/*You will be writing a “Quiz Tutor” program. The program should begin by reading a question and 4 possible answers from a text file. It should display these to the user.
The user will select the answer from the choices.
The program will determine if the answer is correct and indicate this to the user.
If the answer is correct, the next question will be displayed.
If it is incorrect, the incorrect question will be stored in a list in order before displaying the next question.
At the end of the file the user has completed round one, the program should display the number of correct answers and a score (percent correct).
The program will then begin round 2.
The questions from the list of incorrectly answered questions will be redisplayed in order for the user to try again.
If the question is answered correctly this time the number of correct answers is increased.
If the user answers incorrectly the second time, the correct answer is displayed.
At the end of round 2, the quiz is over.
The program should display the new score along with the number of correct answers from the first round plus the number of correct answers from the second round.

*/


code:
Code:
/****Driver for quiz program. ****/

#include<iostream.h>
using namespace std;

#include "game.h"

void rnd_1();
void rnd_2(question &);

void main()
{

	rnd_1();
}



void rnd_1()
{
	question quiz;


	cout << "round 1 \n";

	for ( int i =0; i < quiz.get_quest_num(); i++)
	{
		quiz.display_question();
		quiz.process_rdn1();
	}

	quiz.display_score();
	if (get_ans_cor() == get_quest_num())
	
	{
		cout << " You got everythin right in first round \n";
		exit(1);
	}
	
	else
		rnd_2(quiz);
}

void rnd_2( question & quiz2)
{
	cout << "round 2 \n";

	for ( int i =0; i < quiz2.get_ans_wrg(); i++)
	{
		quiz2.display_wrg();
		quiz2.process_rdn2();
	}

	quiz2.display_score();
	cout << "Thank you for playing \n";
	exit(1);
}//end of driver

/***Game.cpp ----------------
              This file implements Game member functions.
              					
              																****/ 

#include <iostream>
using namespace std;

#include "game.h"


question::question() // default constructor
{
	ifstream in;
	string filename;


	quest_num = 0;
	ans_cor = 0;
	ans_wrg = 0;


	cout <<"Enter file name";
	cin >> filename;

	in.open(filename.c_str());

	assert(in.open());

	while(!in.eof())
	{

		getline(in, q_sub.quest);
		getline(in, q_sub.ans1);
		getline(in, q_sub.ans2);
		getline(in, q_sub.ans3);
		getline(in, q_sub.ans4);
		getline(in, q_sub.answer);
		rdone.enqueue(q_sub); //enque all question submitted	

		quest_num++;          // increase questions read from file
	}
}


void question::display_question()
{
	x_file q_disp = rdone.front();

	cout << q_disp.quest <<endl;
	cout << q_disp.ans1 <<endl;
	cout << q_disp.ans2 <<endl;
	cout << q_disp.ans3 <<endl;
	cout << q_disp.ans4 <<endl;

}

void question::process_rdn1()
{
	string ans;
	x_file q_disp = rdone.front();

	cout <<"Give your answer";
	cin >> ans;

	if ( ans == q_disp.answer)
	{
		cout<<"correct answer\n";
		ans_cor++;
		rdone.dequeue();
	}
	else
	{
		cout <<"Incorrect answer\n";
		ans_wrg++;
		rdtwo.enqueue(q_disp);
		rdone.dequeue();

	}
}


void question::display_wrg()
{
	x_file q_disp = rdtwo.front();

	cout << q_disp.quest <<endl;
	cout << q_disp.ans1 <<endl;
	cout << q_disp.ans2 <<endl;
	cout << q_disp.ans3 <<endl;
	cout << q_disp.ans4 <<endl;

}

void question::process_rdn2()
{
	string ans;
	x_file q_disp = rdtwo.front();

	cout <<"Give your answer";
	cin >> ans;

	if ( ans == q_disp.answer)
	{
		cout<<"correct answer\n";
		ans_cor++;
		ans_wrg--;
		rdtwo.dequeue();
	}
	else
	{
		cout <<"Incorrect answer\n";
		cout<<"The correct answer is "<< q_disp.answer<<endl;
		rdtwo.dequeue();

	}
}

void question::display_score()
{

	cout <<"Your total correct answer: "<< ans_cor << endl;
	cout <<"Your total incorrect answer: "<<ans_wrg; <<endl;
	cout <<" Your Score is "<< ans_cor << quest_num <<endl; // need type casting to double
}


int question::get_quest_num()
{
	return quest_num;
}

int question::get_ans_cor()
{
	return ans_cor;
}

int question::get_ans_wrg()
{
	return ans_wrg;
} //end of game.cpp

#include <iostream.h>
#include <string>
#include <fstream.h>
#include <assert.h>

#include "Queue.h"

#ifndef game
#define game

struct x_file
{
	string quest;
	string ans1;
	string ans2;
	string ans3;
	string ans4;
	string answer;
}; // end of struct

class Question
{

public:

	//--Constructors
	Question();
	
	//--Mutators
		void process_rdn1();
	void process_rdn2();
	
	//--Output
	void display_score();
	void display_wrg()
	void display_question();
	
	//--Accessors
	int get_quest_num();
	int get_ans_cor();
	int get_ans_wrg();

private:
	x_file q_sub; //struct from file

	queue<x_file> rdone; //initial questions
	queue<x_file> rdtwo; // incorrect question

	int ques_num;
	int ans_cor;
	int ans_wrg;

};  //end of class

#endif
first of all i think it goes like this
[code]
#include <iostream>
#include "game.h"
using namespace std;

also i cant help cause i dont know what it game.h nor the other .h cause first u have have them also it do it yeah thats my answer remember to drop the h in iostream etc

Reply With Quote
  #3  
Old July 31st, 2005, 04:11 PM
codeless codeless is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 4 codeless User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 18 m 36 sec
Reputation Power: 0
program

Quote:
Originally Posted by BloodlustShaman
first of all i think it goes like this
[code]
#include <iostream>
#include "game.h"
using namespace std;

also i cant help cause i dont know what it game.h nor the other .h cause first u have have them also it do it yeah thats my answer remember to drop the h in iostream etc


3 files game.h, game.cpp and quiz.cpp (driver)
the program basically reads questions from a file and requires the user to select correct answer.
the questions are initially placed in a queue, hence struct.
wrong answers are placed in another until user first set of question, then question that was wrong are repeated for the user to get correct answer.

Reply With Quote
  #4  
Old July 31st, 2005, 04:32 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
What exactily is your problem? At first glance, everything looks fine....
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #5  
Old August 5th, 2005, 09:40 PM
proghelper proghelper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 12 proghelper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 21 sec
Reputation Power: 0
I am not clear on your problem.

However, it is not a good idea to have input/output statements in the constructor. You should avoid that.

Additionally, please have a design around the problem. Obviously you have a slution in the program but the mapping from the problem to program is difficult to make.

-----------------------------

Programming ( Assignment / Project ) Help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with school assignment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT