#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace VCDrivingTest1
{
const int MaximumNumberOfQuestions = 20;
/// <summary>
/// Summary for QuestionAnswer
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class QuestionAnswer : public System::Windows::Forms::Form
{
public:
int TotalNumberOfQuestions;
// This variable will hold a list of randoom non-repeating numbers
ArrayList ^ lstNumbers;
// This will represent the index of the question that is being asked
int CurrentQuestion;
// These will keep a count of the questions already asked
int QuestionCounter;
int CurrentNumberOfQuestions;
// This will be used to counte the number of correct answers
double Sum;
// This variable allows monitoring if a 0 had been
// added to the list of numbers;
bool Found0;
QuestionAnswer(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
// This method takes a constant integer that represents
// the index of a question in the list of questions
// This method then displays the corresponding question
void PresentQuestion(int qstNumber)
{
rdoAnswer1->Checked = false;
rdoAnswer2->Checked = false;
rdoAnswer3->Checked = false;
rdoAnswer4->Checked = false;
switch (qstNumber)
{
case 1:
txtQuestion->Text = L"If your car and a car coming from your "
L"right reach an intersection at the same "
L"time, who has the right of way?";
rdoAnswer1->Text = L"A. Your car";
rdoAnswer2->Text = L"B. The other car";
rdoAnswer3->Text = L"C. You both wait for the first car that makes a move";
rdoAnswer4->Text = L"D. Neither, as both cars must come to a stop";
break;
case 2:
txtQuestion->Text = L"How many feet before you make a turn should "
L"you signal that you are going to turn?";
rdoAnswer1->Text = L"A. 50 feet";
rdoAnswer2->Text = L"B. 100 feet";
rdoAnswer3->Text = L"C. 150 feet";
rdoAnswer4->Text = L"D. While turning";
break;
case 3:
txtQuestion->Text = L"You are driving in an alley at fifteen (15) "
L"miles per hour. You are";
rdoAnswer1->Text = L"A. Breaking the speed limit for alleys";
rdoAnswer2->Text = L"B. Driving too slow";
rdoAnswer3->Text = L"C. Obeying the law";
rdoAnswer4->Text = L"D. Breaking the law as you should never drive "
L"in an alley";
break;
case 4:
txtQuestion->Text = L"A car isdriving toward you "
L"at night and it has its blinding "
L"high beam lights on. The driver of this car is";
rdoAnswer1->Text = L"A. Guilty only of bad manners because the "
L"high beams blind other drivers";
rdoAnswer2->Text = L"B. A safe driver because the high beams "
L"light up the road more brightly than "
L"the lower beams";
rdoAnswer3->Text = L"C. Not obeying the law because the low beams "
L"must be used at all times";
rdoAnswer4->Text = L"D. not doing anything wrong (it doesn't matter)";
break;
case 5:
txtQuestion->Text = L"You are driving up to an intersection where "
L"there is no signal light or policeman. A man "
L"is crossing in the cross walk in front of "
L"your car. You should:";
rdoAnswer1->Text = L"A. Continue into the intersection because you "
L"have the right-of-way";
rdoAnswer2->Text = L"B. Slow down and be careful";
rdoAnswer3->Text = L"C. Stop and give him the right-of way";
rdoAnswer4->Text = L"D. Not care";
break;
case 6:
txtQuestion->Text = L"You wish to make a \"U\" turn at an intersection "
L"controlled by a traffic light. You should: ";
rdoAnswer1->Text = L"A. Drive to another intersection that has no traffic "
L"light or sign saying NO \"U\" Turn";
rdoAnswer2->Text = L"B. Wait until the light turns green before making "
L"the \"U\" turn";
rdoAnswer3->Text = L"C. Make the \"U\" turn if there is a policeman "
L"at the intersection";
rdoAnswer4->Text = L"D. Wait for the red light before making the \"U\" "
L"turn to make sure that the opposing traffic is safe";
break;
case 7:
txtQuestion->Text = L"You are driving past a school building or its "
L"grounds when the children are going to or "
L"leaving school. The speed limit is:";
rdoAnswer1->Text = L"A. Seven (7) miles per hour";
rdoAnswer2->Text = L"B. Fifteen (15) miles per hour";
rdoAnswer3->Text = L"C. Ten (10) miles per hour";
rdoAnswer4->Text = L"D. Twenty (20) miles per hour";
break;
case 8:
txtQuestion->Text = L"If you are driving out of an alley "
L"or driveway, you must";
rdoAnswer1->Text = L"A. Stop before reaching the sidewalk";
rdoAnswer2->Text = L"B. Stop, if possible to do so safely";
rdoAnswer3->Text = L"C. Stop only if there is heavy traffic";
rdoAnswer4->Text = L"D. Wait for a policeman of respectable "
L"pedestrian to guide you when it is safer";
break;
case 9:
txtQuestion->Text = L"You are coming to an intersection "
L"where there is a flashing yellow traffic "
L"light. You should";
rdoAnswer1->Text = L"A. Slow down and proceed with caution";
rdoAnswer2->Text = L"B. Stop, if possible to do so safely";
rdoAnswer3->Text = L"C. Continue at the same speed";
rdoAnswer4->Text = L"D. Wait for a poileman to direct the traffic";
break;
case 10:
txtQuestion->Text = L"You are driving on a two-lane street. "
L"The car ahead of you is moving very slowly "
L"and the road ahead is clear for passing. "
L"You should:";
rdoAnswer1->Text = L"A. Pass on the left hand side";
rdoAnswer2->Text = L"B. Pass on either side";
rdoAnswer3->Text = L"C. Pass on the right side";
rdoAnswer4->Text = L"D. Make a gesture to signal the other car "
L"to move to the other lane, so you can "
L"drive straight";
break;
case 11:
txtQuestion->Text = L"What is the legal rate of speed "
L"unless there are signs "
L"that give a different speed limit?";
rdoAnswer1->Text = L"A. 25 miles per hour";
rdoAnswer2->Text = L"B. 30 miles per hour";
rdoAnswer3->Text = L"C. 35 miles per hour";
rdoAnswer4->Text = L"D. 45 miles per hour";
break;
case 12:
txtQuestion->Text = L"You are driving a car which is involved in "
L"an accident. Two people are slightly hurt "
L"but don't need to go to the hospital. "
L"You should:";
rdoAnswer1->Text = L"A. Report to the nearest police pricinct";
rdoAnswer2->Text = L"B. Report to the Department of Motor Vehicles";
rdoAnswer3->Text = L"C. Report to the police and the Department of "
L"Motor Vehicles";
rdoAnswer4->Text = L"D. Wait for a policeman";
break;
case 13:
txtQuestion->Text = L"You're driving up to an intersection where "
L"the traffic light is red. A policeman "
L"motions you to go through. You should";
rdoAnswer1->Text = L"A. Wait for the light to turn green and "
L"then go ahead";
rdoAnswer2->Text = L"B. Call the policeman's attention to "
L"the red light";
rdoAnswer3->Text = L"C. Obey the policeman's signal";
rdoAnswer4->Text = L"D. Wait for another car to move to make "
L"sure the road is safe";
break;
case 14:
txtQuestion->Text = "You are pulling into the street from a "
"parallel parking space. Before doing "
"so, you should:";
rdoAnswer1->Text = "A. Blow your horn and pull from the curb slowly";
rdoAnswer2->Text = "B. Signal other traffic and then pull into the street";
rdoAnswer3->Text = "C. Proceed with caution when there is no traffic "
"near enough to cause an accident";
rdoAnswer4->Text = "D. Wait for a policeman or a respectable citizen "
"to signal that the road is safer";
break;
case 15:
txtQuestion->Text = "You have changed your address. You should notify "
"the Department of Motor Vehicles, either by "
"mail or in person, within a period of:";
rdoAnswer1->Text = "A. Fifteen (15) days";
rdoAnswer2->Text = "B. Five (5) days";
rdoAnswer3->Text = "C. Thirty (30) days";
rdoAnswer4->Text = "D. Ten (10) days";
break;
case 16:
txtQuestion->Text = "You are driving on a street and another car is "
"entering the street from a driveway. Who has "
"the right-of-way?";
rdoAnswer1->Text = "A. You";
rdoAnswer2->Text = "B. The other driver";
rdoAnswer3->Text = "C. Neither you nor the other driver";
rdoAnswer4->Text = "D. The next car";
break;
case 17:
txtQuestion->Text = "Up to what age are children required to "
"be restrained in a child restraint seat?";
rdoAnswer1->Text = "A. 6 months old";
rdoAnswer2->Text = "B. 3 years";
rdoAnswer3->Text = "C. 6 years";
rdoAnswer4->Text = "D. 8 years";
break;
case 18:
txtQuestion->Text = "How close to a fire hydrant (fire plug) "
"may you park a motor vehicle?";
rdoAnswer1->Text = "A. Five (5) feet";
rdoAnswer2->Text = "B. Six (6) feet";
rdoAnswer3->Text = "C. Ten (10) feet";
rdoAnswer4->Text = "D. It doesn't matter because you will "
"move your car if the fire fighters request it";
break;
case 19:
txtQuestion->Text = "When the light is green and the yellow "
"light comes on as you approach an "
"intersection, you should";
rdoAnswer1->Text = "A. Hurry to cross";
rdoAnswer2->Text = "B. Stop the crosswalk";
rdoAnswer3->Text = "C. Proceed accross the intersection with caution";
rdoAnswer4->Text = "D. Before deciding about what to do, check if the "
"intersection is equipped with cameras";
break;
case 20:
txtQuestion->Text = "A flashing red traffic light signals means the same as:";
rdoAnswer1->Text = "A. Stop sign";
rdoAnswer2->Text = "B. Yield right-of-way sign";
rdoAnswer3->Text = "C. Slow sign";
rdoAnswer4->Text = "D. An ambulance is approaching";
break;
case 21:
txtQuestion->Text = "How close to the intersection are you allowed "
"to park on a two-way street?";
rdoAnswer1->Text = "A. Twenty (20) feet";
rdoAnswer2->Text = "B. Thirt (30) feet";
rdoAnswer3->Text = "C. Fourty (40) feet";
rdoAnswer4->Text = "D. Fifty (50) feet";
break;
}
}
. . .
private: System::Void btnQuit_Click(System::Object^ sender, System::EventArgs^ e)
{
double average = 1;
if( QuestionCounter != 0 )
average = Sum / QuestionCounter;
String ^ strCongratulations = "";
if( average >= 0.5 )
strCongratulations = "\nCongratulations!";
if( Found0 == true )
QuestionCounter--;
MessageBox::Show(String::Concat("Total Number of Questions: ",
QuestionCounter.ToString(),
"\nNumber of Correct Answers: ",
Sum.ToString(),
"\nSuccess Rate: ",
(average * 100).ToString("F"),
" %\n", strCongratulations));
lstNumbers->Remove(MaximumNumberOfQuestions);
Close();
}
}
|