Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- //=============================================================================================
- public class QuizProblems
- {
- public QuizProblems (string question, string [] answers, int correctAnswer)
- {
- this.question = question;
- this.answers = answers; //watch as there will be inheritance here
- this.correctAnswer = correctAnswer;
- this.selectedAnswer = -1;
- this.flagged = false;
- }
- public string question
- {
- get;
- set;
- }
- public string [] answers
- {
- get;
- set;
- }
- public int correctAnswer //stores what the correct answer is
- {
- get;
- set;
- }
- public int selectedAnswer //stores which answer in the array they selected
- {
- get;
- set;
- }
- public bool flagged
- {
- get;
- set;
- }
- }
- //=============================================================================================
- public partial class Form1 : Form
- {
- int i = 0;
- int score = 0;
- //Array of questions
- const int NumQuestions = 10; //variable stroing number of questions
- QuizProblems [] Question = new QuizProblems[NumQuestions]; //creates ours new
- public Form1()
- {
- InitializeComponent();
- SetupQuestions();
- }
- private void Form1_Load(object sender, EventArgs e)// Events at run time (Before user interaction)
- {
- Previous.Visible = false; //Previous Button Not displayed
- RadioAnswer1.Visible = false;
- RadioAnswer2.Visible = false;
- RadioAnswer3.Visible = false;
- RadioAnswer4.Visible = false;
- Finish.Visible = false;
- Review.Visible = false;
- Previous.Enabled = false;
- A1.Visible = false;
- A2.Visible = false;
- A3.Visible = false;
- A4.Visible = false;
- }
- private void SetupQuestions() //used to setup the Question object
- {
- Question [0] = new QuizProblems("What component inside a computer is non volatile memory?", new string [] {"ROM", "RAM", "SDRAM", "DRAM"}, 1);
- Question [1] = new QuizProblems("What component contains the ALU?", new string [] {"HDD", "SDD", "CPU", "PSU"}, 3);
- Question [2] = new QuizProblems("What component can be static or dynamic?", new string [] {"SDD", "RAM", "USB", "PCI"}, 2);
- Question [3] = new QuizProblems("What component has the northbridge and southbridge?", new string [] {"Graphics Card", "Case", "Hard drive", "Motherboard"}, 4);
- Question [4] = new QuizProblems("Starting from the lowest put the computer file sizes in order?", new string [] {"10KB 10GBs 10MBs 10TBs", "10KB 10MBs 10GBs 10TBs", "10KB 10GBs 10TBs 10MBs", "10MBs 10GBs 10KBs 10TBs"}, 2);
- Question [5] = new QuizProblems("Which of the following is a computer operating system?", new string [] {"Xerox", "Borax", "Linux", "Xenon"}, 3);
- Question [6] = new QuizProblems("What is the job of the kernel in a operating system?", new string [] {"Manages requests from input/output devices", "Used to run office packages", "Allows multi tasking of multiple user windows", "Allows connection to networks through wireless NIC"}, 1);
- Question [7] = new QuizProblems("What should be used to backup mutiple PCs?", new string [] {"Server", "Desktop", "Laptop", "Tablet"}, 1);
- Question [8] = new QuizProblems("Paging is a term used with what?", new string [] {"CMOS", "BIOS", "IP Addressing", "Virtual Memory"}, 4);
- Question [9] = new QuizProblems("Which hard drive format, restricts single file sizes to 4GB or less?", new string [] {"FAT 16", "NFAS", "FAT 32", "OSx Journaled"}, 3);
- }
- private void MainImage_Click(object sender, EventArgs e)
- {
- }
- private void Exit_Click(object sender, EventArgs e)//Event handler for "Exit button"
- {
- DialogResult dlgresult;
- dlgresult = MessageBox.Show("Are you sure you want Exit the program", "Quit Program?", MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
- if (dlgresult == DialogResult.Yes)
- {
- Application.Exit();
- }
- }
- private void Instructions_Click(object sender, EventArgs e)
- {
- DialogResult dlgResult;
- dlgResult = MessageBox.Show
- (
- "You will be asked 10 multiple choice questions of computer systems. You can only select ONE anwser from the 4 options. After the quiz you will be given your total score, and have the option to review incorrect questions",
- "Computer Systems Quiz Instructions",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button2
- );
- }
- private void StartQuiz_Click(object sender, EventArgs e)//"Event handler for Start Quiz button"
- {
- MainImage.Visible = false; //Hide main image
- Previous.Visible = true; //Show Previous Button
- //Change name of start quiz button and create new event handler for button
- StartQuiz.Text = "Next >>" ; //changes name of start quiz button to restart quiz
- StartQuiz.Click -= this.StartQuiz_Click; //unsubcribed orginal event handler of "start quiz"
- StartQuiz.Click += this.Next_Click; //create new event handler renamed button "restart"
- //change name of instructions button and create new event handler for button
- Instructions.Text = "Flag";
- Instructions.Click -= this.Instructions_Click;
- Instructions.Click += this.Flag_Click;
- }
- private void Flag_Click(Object sender, EventArgs e)// Event handler for flag button
- {
- //flag instructions to go here
- }
- private void Line1_Click(object sender, EventArgs e)
- {
- }
- private void Line3_Click(object sender, EventArgs e)
- {
- }
- private void Next_Click(object sender, EventArgs e)
- {
- Previous.Enabled = true;//Enables the previous button
- RadioAnswer1.Visible = true;
- RadioAnswer2.Visible = true; //Quiz answers now visible to user
- RadioAnswer3.Visible = true;
- RadioAnswer4.Visible = true;
- A1.Visible = true; //answer numbers now visible to the user
- A2.Visible = true;
- A3.Visible = true;
- A4.Visible = true;
- // RadioAnswer1.Checked = false;
- // RadioAnswer2.Checked = false;
- // RadioAnswer3.Checked = false;
- // RadioAnswer4.Checked = false;
- QuestionLabel.Text = Question[i].question; //print the question in that array index
- RadioAnswer1.Text = Question[i].answers[0]; //prints the first option for an answer
- RadioAnswer2.Text = Question[i].answers[1]; //prints the second option for an answer
- RadioAnswer3.Text = Question[i].answers[2]; //prints the third option for an answer
- RadioAnswer4.Text = Question[i].answers[3]; //prints the fourth option for an answer
- if ((RadioAnswer1.Checked) || (RadioAnswer2.Checked) || (RadioAnswer3.Checked) || (RadioAnswer4.Checked))
- {
- if (RadioAnswer1.Checked)
- {
- Question[i].selectedAnswer = 1;
- }
- else if (RadioAnswer2.Checked)
- {
- Question[i].selectedAnswer = 2;
- }
- else if (RadioAnswer3.Checked)
- {
- Question[i].selectedAnswer = 3;
- }
- else if (RadioAnswer4.Checked)
- {
- Question[i].selectedAnswer = 4;
- }
- else
- {
- MessageBox.Show("You have not not answered the question. \n Please answer the question before proceeding");
- }
- }
- i++;
- if (i == NumQuestions)
- {
- Finish.Visible = true;
- StartQuiz.Enabled = false;
- }
- }
- private void Previous_Click(object sender, EventArgs e)
- {
- }
- private void MainImage_Click_1(object sender, EventArgs e)
- {
- }
- private void QuestionLabel_Click(object sender, EventArgs e)
- {
- }
- private void Finish_Click(object sender, EventArgs e)
- {
- Review.Visible = true;
- Previous.Enabled = false;
- Instructions.Enabled = false;
- for (int i = 0; i < 9; i++)
- {
- if (Question[i].selectedAnswer == Question[i].correctAnswer) //checks if the answer is correct
- {
- score = score + 1;
- }
- }
- if (score <= 30)
- {
- MessageBox.Show("Very poor. \nYou got " + score + "\nClick review to view your Incorrect Answers");//Prints User score
- }
- else if ((score > 30) && (score <= 50))
- {
- MessageBox.Show("Could be better, You got " + score + "\nClick review to view your Incorrect Answers");//Prints User score
- }
- else if ((score >50) && (score<=60))
- {
- MessageBox.Show("Not bad. Your score was " + score + "\nClick review to view your Incorrect Answers");//Prints User score
- }
- else if ((score >70) && (score<=90))
- {
- MessageBox.Show("Well done your score was " + score + "\nClick review to view your Incorrect Answers");//Prints User score
- }
- else if (score == 100)
- {
- MessageBox.Show("Fantastic you got every question right");//Prints User score
- }
- }
- private void Review_Click(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement