Classes for a Quiz Program

im a beginner and the program should have 3 classes but i cant make it

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1883 Views - Last Post: 23 August 2009 - 07:12 AM Rate Topic: -----

#16 Lillefix  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 37
  • View blog
  • Posts: 204
  • Joined: 19-September 08

Re: Classes for a Quiz Program

Posted 23 August 2009 - 04:03 AM

View Postcziel, on 23 Aug, 2009 - 02:49 AM, said:

thank you for the reply

but i dont quite understand this code


Just what is it you don't understand about this code. It is a fairly straight-forward use of classes.
Are you sure that you actually understand what a class is and how to use them?

Ofcourse this code does not have all the code necessary, but that is to prevent you from simply copying my code. For this to work, you will have to implement all the functions.

This post has been edited by Lillefix: 23 August 2009 - 04:23 AM

Was This Post Helpful? 0
  • +
  • -

#17 cziel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-August 09

Re: Classes for a Quiz Program

Posted 23 August 2009 - 04:05 AM

actually...to be honest i really dont know much about classes because i am only starting to learn it..i dont have any experiences yet with classes so im really sorry...
Was This Post Helpful? 0
  • +
  • -

#18 Elcric  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 101
  • View blog
  • Posts: 453
  • Joined: 02-May 09

Re: Classes for a Quiz Program

Posted 23 August 2009 - 06:56 AM

Hello, :D

This is the fun part, when lots of people jump in and help. Sharing ideas is fun. We have lots of very smart and creative people who love to help beginners.

I was trying not to change too much of what you originally had.

There are always lots of ways to program a solution to a problem.

Even though you do not know classes. Trying to learn helps you learn.

The best way to learn programming is to program.

Classes are not really hard.

If you want we can continue and people will jump in with ideas and help you as we go along.

I been thinking maybe we could have four classes:

1. Security with the user name and password: m_user[10]; m_pass[10];

2. Easy

3. Average

4. Difficult

This is a rough idea of what it would look like.

Security is the base class. The other three are derived from Security.

Keep in mind I am trying hard not to change what you started with, just to add to it to help you in the right direction.

[code]
//************************************
//
//************************************
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;

class Security
{
private:

char m_user[10];
char m_pass[10];
};


class Easy : public Security
{

private:

char m_z1;
char m_z2;
char m_z3;
char m_z4;
char m_z5;
char m_z6;
char m_z7;
char m_z8;
char m_z9;
char m_z10;

int m_easyx;
int m_easyy;

char m_aaa[40];


public:

Easy();
void password();
~Easy();

};

class Average : public Security
{

private:

char m_y1;
char m_y2;
char m_y3;
char m_y4;
char m_y5;
char m_y6;
char m_y7;
char m_y8;
char m_y9;
char m_y10;

int m_avex;
int m_avey;

char m_bbb[40];

public:

Average();
void setUser(char user);
void password();
~Average();

};

class Difficult : public Security
{

private:

char m_x1;
char m_x2;
char m_x3;
char m_x4;
char m_x5;
char m_x6;
char m_x7;
char m_x8;
char m_x9;
char m_x10;

int m_hardx;
int m_hardy;

char m_ccc[40];


public:

Difficult();
void password();
~Difficult();

};



//************************************
// MAIN() FUNCTION.
//************************************
int main(int argc, char* argv[])
{
FILE *group7a;
FILE *group7b;
FILE *group7c;

char aaa[40];
char bbb[40];
char ccc[40];

char user[10];
char pass[10];

int file1 = 1;
int file2 = 2;
int file3 = 3;

int hamp;
char hatch;

char x1 = 0;
char x2 = 0;
char x3 = 0;
char x4 = 0;
char x5 = 0;
char x6 = 0;
char x7 = 0;
char x8 = 0;
char x9 = 0;
char x10 = 0;

int hardx = 0;
int hardy = 0;

char y1 = 0;
char y2 = 0;
char y3 = 0;
char y4 = 0;
char y5 = 0;
char y6 = 0;
char y7 = 0;
char y8 = 0;
char y9 = 0;
char y10 = 0;

int avex = 0;
int avey = 0;

char z1 = 0;
char z2 = 0;
char z3 = 0;
char z4 = 0;
char z5 = 0;
char z6 = 0;
char z7 = 0;
char z8 = 0;
char z9 = 0;
char z10 = 0;

int easyx = 0;
int easyy = 0;

hatch = 'n';
while( hatch != 'y' )
{
cout << "Input username to continue:" << endl;
cin >> user;



cout << "Input password:" << endl;
cin >> pass;

if( ( strcmp ( user, "lasalle" ) == 0 ) && ( strcmp ( pass, "group7" ) == 0 ) )
{
cout << "\nCORRECT USERNAME AND PASSWORD!\n" << endl;
void password();
} else
{
cout << "\nWRONG USERNAME AND PASSWORD. ACCESS IS DENIED\n" << endl;
exit(0);
}

void password();

cout << "SCIENCE IS FUN GAME" << endl;
cout << "Main Menu" << endl;
cout << "1 - Game Description" << endl;
cout << "2 - Game Programmers" << endl;
cout << "3 - EASY ROUND" << endl;
cout << "4 - AVERAGE ROUND" << endl;
cout << "5 - DIFFICULT ROUND" << endl;
cout << "6 - Exit" << endl;
cout << "Choose " << endl;
cin >> hamp;

switch(hamp)
{
case 1:
{
cout << "PROGRAM DESCRIPTION: " << endl;
cout << "\n\n\n\n\n\n\n\n" << endl;
cout << "IT Project2" << endl;
cout << "Presented for " << endl;
cout << "The Partial Fullfillment" << endl;
cout << "In the course of" << endl;
cout << "Object Oriented Programming" << endl;
cout << "Presented to:" << endl;
cout << "Mr. Mark G. De Vera" << endl;
cout << "Presented by the:" << endl;
cout << "GROUP 7" << endl;
cout << "July 30, 2009" <<endl;
cout << "^_^" << endl;
cout << "\n\n\n\n\nYOU WILL BE ASKED TO INPUT YOUR USERNAME AND PASSWORD AGAIN FOR THE SECURITY OF THE PROGRAM\n";
cout << "THANK YOU!\n\n\n\n\n";
break;
}
case 2:
{
cout << "THE PROGRAMMERS:" << endl;
cout << "Gian Carlo P. Torres" << endl;
cout << "Wendel C. Balita" << endl;
cout << "Oscar Dimaculangan" << endl;
cout << "\n\n\n\n\nYOU WILL BE ASKED TO INPUT YOUR USERNAME AND PASSWORD AGAIN FOR THE SECURITY OF THE PROGRAM\n";
cout << "THANK YOU!\n\n\n\n\n";
break;
}
case 3:
{
cout << "EASY ROUND:" << endl;
cout << "GENERAL RULE: ALL ANSWERS SHOULD BE IN SMALL LETTERS" << endl;
cout << "\n\n\n\nEasy round is all about GENERAL SCIENCE.\n\n\n\n";
cout << "1.What is the first element in the periodic table of element?" << endl;
cout << "a. helium" << endl;
cout << "b. mercury" << endl;
cout << "c. hydrogen" << endl;
cout << "d. oxygen" << endl;
cin >> z1;
if( z1 == 'c' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else{
easyy = easyy + 1;
cout << "SORRY! YOU ARE WRONG. THE CORRECT ANSWER IS: C\a " << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "2. What is the study of various species of life?" << endl;
cout << "a. chemistry" << endl;
cout << "b. biology" << endl;
cout << "c. physics" << endl;
cout << "d. physical science" << endl;
cin >> z2;
if( z2 == 'b' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "SORRY! YOU ARE WRONG. THE CORRECT ANSWER IS: B\a " << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "3. Who discovered the telephone?" << endl;
cout << "a. Thomas Edison" << endl;
cout << "b. Albert Einstein" << endl;
cout << "c. Galileo Galilei" << endl;
cout << "d. Jimmy Neutron" << endl;
cin >> z3;
if( z3 == 'a' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: A\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "4. What is the biggest planet in the solar system?" << endl;
cout << "a. Mars" << endl;
cout << "b. Jupiter" << endl;
cout << "c. Saturn" << endl;
cout << "d. Vesta" << endl;
cin >> z4;
if( z4 == 'b' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: B\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "5. What is the basic unit of life?" << endl;
cout << "a. blood" << endl;
cout << "b. heart" << endl;
cout << "c. brain" << endl;
cout << "d. cell" << endl;
cin >> z5;
if( z5 == 'd' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: D \a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "6. Who is the father of biology?" << endl;
cout << "a. Socrates" << endl;
cout << "b. Aristotle" << endl;
cout << "c. Plato" << endl;
cout << "d. none of the above" << endl;
cin >> z6;
if( z6 == 'b' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: B\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "7. What is the smallest planet in the solar system?" << endl;
cout << "a. Pluto" << endl;
cout << "b. Mercury" << endl;
cout << "c. Mars" << endl;
cout << "d. Ceres" << endl;
cin >> z7;
if( z7 == 'b' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "YOUR ANSWER IS WRONG. THE CORRECT ANSWER IS: B\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "8. Astronomy is under what field of science?" << endl;
cout << "a. physics" << endl;
cout << "b. chemistry" << endl;
cout << "c. biology" << endl;
cout << "d. none of the above" <<endl;
cin >> z8;
if( z8 == 'd' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "YOUR ANSWER IS WRONG. THE CORRECT ANSWER IS: D\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "9. Who is the cartoon character also known as BOY - GENIUS?" << endl;
cout << "a. Ash Ketchum" << endl;
cout << "b. Spongebob Squarepants" << endl;
cout << "c. Jimmy Neutron" << endl;
cout << "d. Astroboy" << endl;
cin >> z9;
if( z9 == 'c' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "YOUR ANSWER IS WRONG. THE CORRECT ANSWER IS: C\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "10. What is the highest level of mankind here in earth?" << endl;
cout << "a. humans" << endl;
cout << "b. animals" << endl;
cout << "c. microbes" << endl;
cout << "d. none of the above" << endl;
cin >> z10;
if( z10 == 'a' )
{
easyx = easyx + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
easyy = easyy + 1;
cout << "YOUR ANSWER IS WRONG. THE CORRECT ANSWER IS: A\a" << endl;
}
cout << "^_^" << endl;
cout << "You have " << easyx << " correct answers." << endl;
cout << "You have " << easyy << " wrong answers." << endl;
cout << "Print your score. " << endl;
cout << "Input name of output text file: " << endl;
cin >> aaa;
group7a = fopen( aaa, "w" );
fprintf( group7a, "EASY ROUND %d\n", file1 );
fprintf( group7a, "Correct answers = %d\n", easyx );
fprintf( group7a, "Wrong answers = %d\n", easyy );
fclose( group7a );
cout << "\n\n\n\n\nYOU WILL BE ASKED TO INPUT YOUR USERNAMER AND PASSWORD AGAIN FOR THE SECURITY OF THE PROGRAM\n";
cout << "THANK YOU!\n\n\n\n\n";
break;
}
case 4:
{
cout << "Average Round" << endl;
cout << "GENERAL RULE: ALL ANSWERS SHOULD BE IN SMALL LETTERS" << endl;
cout << "\n\n\n\nAVERAGE ROUND IS ALL ABOUT PHYSICAL SCIENCE.\n\n\n\n";
cout << "1.What is the first man-made satelite?" << endl;
cout << "a. sputnik1" << endl;
cout << "b. sputnik3" << endl;
cout << "c. apollo1" << endl;
cout << "d. apollo11" << endl;
cin >> y1;
if( y1 == 'a' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: A\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "2.What makes Uranus blue?" << endl;
cout << "a. carbon dioxide" << endl;
cout << "b. helium" << endl;
cout << "c. methane" << endl;
cout << "d. hydrogen" << endl;
cin >> y2;
if( y2 == 'c' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
} else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: C\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "3.What is the largest asteroid?" << endl;
cout << "a. eris" << endl;
cout << "b. ceres" << endl;
cout << "c. pluto" << endl;
cout << "d. comets" << endl;
cin >> y3;
if( y3 == 'b' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: B\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "4.What is the largest mountain in the solar system?" << endl;
cout << "a. mt.apo" << endl;
cout << "b. mt.everest" << endl;
cout << "c. olympus wind" << endl;
cout << "d. olympus mons" << endl;
cin >> y4;
if( y4 == 'd' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: D\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "5.What makes mars red?" << endl;
cout << "a. helium" << endl;
cout << "b. iron oxide" << endl;
cout << "c. hydrogen" << endl;
cout << "d. methane" << endl;
cin >> y5;
if( y5 == 'b' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: B\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "6.What is the hottest planet in the solar system?" << endl;
cout << "a. mercury" << endl;
cout << "b. jupiter" << endl;
cout << "c. venus" << endl;
cout << "d. earth" << endl;
cin >> y6;
if( y6 == 'c' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: C\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "7.What is the nearest point of a planet to the sun?" << endl;
cout << "a. perihelion" << endl;
cout << "b. aphelion" << endl;
cout << "c. perigee" << endl;
cout << "d. apogee" << endl;
cin >> y7;
if( y7 == 'a' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: A\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "8. When did the first manned moon landing happen?" << endl;
cout << "a. May 6, 1969" << endl;
cout << "b. July 16, 1908" << endl;
cout << "c. July 21, 1969" << endl;
cout << "d. none of the above" << endl;
cin >> y8;
if( y8 == 'c' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: C\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "9. What is the biggest moon of Jupiter?" << endl;
cout << "a. Ganymede" << endl;
cout << "b. Callisto" << endl;
cout << "c. Io" << endl;
cout << "d. Europa" << endl;
cin >> y9;
if( y9 == 'a' )
{
avex = avex + 1;
cout << "YOUR ANSWER IS CORRECT!" << endl;
}else
{
avey = avey + 1;
cout << "SORRY YOU ARE WRONG. THE CORRECT ANSWER IS: A\a" << endl;
}
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << "10. What were the first creatures in this world to fly?" << endl;
cout << "a. birds" << endl;
cout << "b. insects" << endl;
cout << "c. butterflies" << endl;
cout << "d. none of the above" << endl;
cin >> y10;
 &nbs
Was This Post Helpful? 0
  • +
  • -

#19 cziel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-August 09

Re: Classes for a Quiz Program

Posted 23 August 2009 - 07:03 AM

yes...im really am grateful to all people who are replying in this post because i am learning new things from all of you,,,your smart opinions and ideas really help me...im so glad that there are peopla who are willing to help..thanks everyone
Was This Post Helpful? 0
  • +
  • -

#20 cziel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-August 09

Re: Classes for a Quiz Program

Posted 23 August 2009 - 07:12 AM

Quote

Keep in mind I am trying hard not to change what you started with, just to add to it to help you in the right direction.


well thank you very much for your help..i really appreciated what you have done.it is really a BIG help to me...thank you very much

also to those others that posted their ideas...a BIG thanks to them... ^^
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2