Important alert: (current site time 5/25/2013 11:46:28 AM EDT)
 

VB icon

Simple Quiz

Email
Submitted on: 9/14/2012 11:05:12 AM
By: Narayan Loke 
Level: Beginner
User Rating: By 1 Users
Compatibility: C++ (general)
Views: 1553
(About the author)
 
     This code is a basic introduction to graphics programming using C++. I hope u guys enjoy it...... It's actually a quiz of 2-3 questions. It's quite big, but good to go. Thank You...
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Simple Quiz
// Description:This code is a basic introduction to graphics programming using C++. I hope u guys enjoy it......
It's actually a quiz of 2-3 questions.
It's quite big, but good to go.
Thank You...
// By: Narayan Loke
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=13849&lngWId=3//for details.//**************************************

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
#include<process.h>
union REGS i,o;
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
return(o.x.ax);
}
void getmousepos(int *b,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*b=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void setmousepos(int x,int y)
{
i.x.ax=4;
o.x.cx=x;
o.x.dx=y;
int86(0x33,&i,&o);
}
hidemouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
return(o.x.ax);
}
class kbc
{
 private:
	 int k;
 public:
	void qbox();
	int qbank(int ans,int amt,char qst[],char op1[],char op2[],char op3[],char op4[]);
};
void kbc::qbox()
{
rectangle(10,280,630,350);
rectangle(10,360,300,410);
rectangle(320,360,630,410);
rectangle(10,420,300,470);
rectangle(320,420,630,470);
}
int kbc::qbank(int ans,int amt,char qst[], char op1[], char op2[], char op3[], char op4[])
{
int tmp;
char str[20];
itoa(amt,str,10);
k=ans;
int b,x,y;
initmouse();
showmouse();
outtextxy(20,290,qst);
outtextxy(20,370,op1);
outtextxy(330,370,op2);
outtextxy(20,430,op3);
outtextxy(330,430,op4);
while(1)
{
getmousepos(&b,&x,&y);
if(k==1)
 {
 if((b&1)==1)
 {
 setmousepos(0,0);
 cleardevice();
 qbox();
 outtextxy(20,290,qst);
 outtextxy(20,370,op1);
 outtextxy(330,370,op2);
 outtextxy(20,430,op3);
 outtextxy(330,430,op4);
	 if(x>10 && x<300 && y>360 && y<410)
	 {
	 setfillstyle(1,GREEN);
	 floodfill(11,361,getmaxcolor());
	 outtextxy(100,100,"You have won Rs. ");
	 outtextxy(250,100,str);
	 return 0;
	 }
	 if(x>320 && x<630 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,361,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x<10 && x<300 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,361,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>320 && x<630 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,361,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
 }
 }//k==1
 if(k==2)
 {
 if((b&1)==1)
 {
 setmousepos(0,0);
 cleardevice();
 qbox();
 outtextxy(20,290,qst);
 outtextxy(20,370,op1);
 outtextxy(330,370,op2);
 outtextxy(20,430,op3);
 outtextxy(330,430,op4);
	 if(x>10 && x<300 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,361,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>320 && x<630 && y>360 && y<410)
	 {
	 setfillstyle(1,GREEN);
	 floodfill(321,361,getmaxcolor());
	 outtextxy(100,100,"You have won Rs. ");
	 outtextxy(250,100,str);
	 return 0;
	 }
	 if(x>10 && x<300 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,361,getmaxcolor());
	 cout<<"\nPress any key exit";
	 getch();
	 cout<<"\nSorry you lose !!!";
	 exit(0);
	 return 1;
	 }
	 if(x>320 && x<630 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,361,getmaxcolor());
	 cout<<"\nPress any key exit";
	 getch();
	 cout<<"\nSorry you lose !!!";
	 exit(0);
	 return 1;
	 }
 }
 }//k==2
 if(k==3)
 {
 if((b&1)==1)
 {
 setmousepos(0,0);
 cleardevice();
 qbox();
 outtextxy(20,290,qst);
 outtextxy(20,370,op1);
 outtextxy(330,370,op2);
 outtextxy(20,430,op3);
 outtextxy(330,430,op4);
	 if(x>10 && x<300 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,421,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>320 && x<630 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,421,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>10 && x<300 && y>420 && y<470)
	 {
	 setfillstyle(1,GREEN);
	 floodfill(11,421,getmaxcolor());
	 outtextxy(100,100,"You have won Rs. ");
	 outtextxy(250,100,str);
	 return 0;
	 }
	 if(x>320 && x<630 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(11,421,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 exit(0);
	 cout<<"\nPress any key exit";
	 getch();
	 return 1;
	 }
 }
 }//k==3
	if(k==4)
 {
 if((b&1)==1)
 {
 setmousepos(0,0);
 cleardevice();
 qbox();
 outtextxy(20,290,qst);
 outtextxy(20,370,op1);
 outtextxy(330,370,op2);
 outtextxy(20,430,op3);
 outtextxy(330,430,op4);
	 if(x>10 && x<300 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,631,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 exit(0);
	 cout<<"\nPress any key exit";
	 getch();
	 return 1;
	 }
	 if(x>320 && x<630 && y>360 && y<410)
	 {
	 setfillstyle(1,RED);
	 floodfill(321,361,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,631,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>10 && x<300 && y>420 && y<470)
	 {
	 setfillstyle(1,RED);
	 floodfill(11,421,getmaxcolor());
	 setfillstyle(1,GREEN);
	 floodfill(321,631,getmaxcolor());
	 cout<<"\nSorry you lose !!!";
	 cout<<"\nPress any key exit";
	 getch();
	 exit(0);
	 return 1;
	 }
	 if(x>320 && x<630 && y>420 && y<470)
	 {
	 setfillstyle(1,GREEN);
	 floodfill(321,421,getmaxcolor());
	 outtextxy(100,100,"You have won Rs. ");
	 outtextxy(250,100,str);
	 return 0;
	 }
 }
 }//k==4
 }
}
void main()
{
int b,x,y,tmp;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
//tmp=initmouse();
//tmp=showmouse();
kbc c;
c.qbox();
tmp=c.qbank(2,1000,"What does MI6 stand for ?","1.Master Intelligence 6","2.Military Intelligence 6","3.Memory Interface 6","6.Manmade Interns");
delay(2000);
cleardevice();
if(tmp==0)
{
c.qbox();
tmp=c.qbank(3,10000,"Who played Michael Corleone in Godfather?","1. Robert De Niro","2.Sylvester Stallone","3.Al Pacino","4.Jason Statham");
delay(2000);
cleardevice();
if(tmp==0)
{
c.qbox();
tmp=c.qbank(4,20000,"Who is known as People's Champion?","1.Roberto Duran","2.Neil Bartlet","3.Muhammad Ali","4.Rocky Marciano");
}
}
getch();
closegraph();
//cout<<tmp;
//getch();
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.