Advertisement
Ange1ofD4rkness

QuizProgram_mcoliver88_1v1

Sep 27th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. //=============================================================================================
  13.     public class QuizProblems
  14.     {
  15.         public QuizProblems (string question, string [] answers, int correctAnswer)
  16.         {
  17.             this.question = question;
  18.             this.answers = answers; //watch as there will be inheritance here
  19.             this.correctAnswer = correctAnswer;
  20.             this.selectedAnswer = -1;
  21.             this.flagged = false;
  22.         }
  23.         public string question
  24.         {
  25.             get;
  26.             set;
  27.         }
  28.         public string [] answers
  29.         {
  30.             get;
  31.             set;
  32.         }
  33.         public int correctAnswer //stores what the correct answer is
  34.         {
  35.             get;
  36.             set;
  37.         }
  38.         public int selectedAnswer //stores which answer in the array they selected
  39.         {
  40.             get;
  41.             set;
  42.         }
  43.         public bool flagged
  44.         {
  45.             get;
  46.             set;
  47.         }
  48.     }
  49. //=============================================================================================
  50.     public partial class Form1 : Form
  51.     {
  52.         int i = 0;
  53.         int score = 0;
  54.        
  55.         //Array of questions
  56.         const int NumQuestions = 10; //variable stroing number of questions
  57.        
  58.         QuizProblems [] Question = new QuizProblems[NumQuestions]; //creates ours new
  59.        
  60.         public Form1()
  61.         {
  62.             InitializeComponent();
  63.             SetupQuestions();
  64.         }
  65.        
  66.         private void Form1_Load(object sender, EventArgs e)// Events at run time (Before user interaction)
  67.         {
  68.             Previous.Visible = false; //Previous Button Not displayed
  69.             RadioAnswer1.Visible = false;
  70.             RadioAnswer2.Visible = false;
  71.             RadioAnswer3.Visible = false;
  72.             RadioAnswer4.Visible = false;
  73.             Finish.Visible = false;
  74.             Review.Visible = false;
  75.             Previous.Enabled = false;
  76.             A1.Visible = false;
  77.             A2.Visible = false;
  78.             A3.Visible = false;
  79.             A4.Visible = false;
  80.         }
  81.        
  82.         private void SetupQuestions() //used to setup the Question object
  83.         {
  84.             Question [0] = new QuizProblems("What component inside a computer is non volatile memory?", new string [] {"ROM", "RAM", "SDRAM", "DRAM"}, 1);
  85.             Question [1] = new QuizProblems("What component contains the ALU?", new string [] {"HDD", "SDD", "CPU", "PSU"}, 3);
  86.             Question [2] = new QuizProblems("What component can be static or dynamic?", new string [] {"SDD", "RAM", "USB", "PCI"}, 2);
  87.             Question [3] = new QuizProblems("What component has the northbridge and southbridge?", new string [] {"Graphics Card", "Case", "Hard drive", "Motherboard"}, 4);
  88.             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);
  89.             Question [5] = new QuizProblems("Which of the following is a computer operating system?", new string [] {"Xerox", "Borax", "Linux", "Xenon"}, 3);
  90.             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);
  91.             Question [7] = new QuizProblems("What should be used to backup mutiple PCs?", new string [] {"Server", "Desktop", "Laptop", "Tablet"}, 1);
  92.             Question [8] = new QuizProblems("Paging is a term used with what?", new string [] {"CMOS", "BIOS", "IP Addressing", "Virtual Memory"}, 4);
  93.             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);
  94.         }
  95.        
  96.         private void MainImage_Click(object sender, EventArgs e)
  97.         {
  98.         }
  99.        
  100.         private void Exit_Click(object sender, EventArgs e)//Event handler for "Exit button"
  101.         {
  102.             DialogResult dlgresult;
  103.             dlgresult = MessageBox.Show("Are you sure you want Exit the program", "Quit Program?", MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
  104.             if (dlgresult == DialogResult.Yes)
  105.             {
  106.                 Application.Exit();
  107.             }
  108.         }
  109.         private void Instructions_Click(object sender, EventArgs e)
  110.         {
  111.             DialogResult dlgResult;
  112.             dlgResult = MessageBox.Show
  113.             (
  114.             "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",
  115.             "Computer Systems Quiz Instructions",
  116.             MessageBoxButtons.OK,
  117.             MessageBoxIcon.Information,
  118.             MessageBoxDefaultButton.Button2
  119.             );
  120.         }  
  121.         private void StartQuiz_Click(object sender, EventArgs e)//"Event handler for Start Quiz button"
  122.         {
  123.             MainImage.Visible = false; //Hide main image
  124.             Previous.Visible = true; //Show Previous Button
  125.            
  126.             //Change name of start quiz button and create new event handler for button
  127.             StartQuiz.Text = "Next >>" ; //changes name of start quiz button to restart quiz
  128.             StartQuiz.Click -= this.StartQuiz_Click; //unsubcribed orginal event handler of "start quiz"
  129.             StartQuiz.Click += this.Next_Click; //create new event handler renamed button "restart"
  130.            
  131.             //change name of instructions button and create new event handler for button
  132.             Instructions.Text = "Flag";
  133.             Instructions.Click -= this.Instructions_Click;
  134.             Instructions.Click += this.Flag_Click;
  135.         }
  136.        
  137.         private void Flag_Click(Object sender, EventArgs e)// Event handler for flag button
  138.         {
  139.             //flag instructions to go here
  140.         }
  141.        
  142.         private void Line1_Click(object sender, EventArgs e)
  143.         {
  144.         }
  145.        
  146.         private void Line3_Click(object sender, EventArgs e)
  147.         {
  148.         }
  149.        
  150.         private void Next_Click(object sender, EventArgs e)
  151.         {
  152.             Previous.Enabled = true;//Enables the previous button
  153.            
  154.             RadioAnswer1.Visible = true;
  155.             RadioAnswer2.Visible = true; //Quiz answers now visible to user
  156.             RadioAnswer3.Visible = true;
  157.             RadioAnswer4.Visible = true;
  158.            
  159.             A1.Visible = true; //answer numbers now visible to the user
  160.             A2.Visible = true;
  161.             A3.Visible = true;
  162.             A4.Visible = true;
  163.            
  164.             // RadioAnswer1.Checked = false;
  165.             // RadioAnswer2.Checked = false;
  166.             // RadioAnswer3.Checked = false;
  167.             // RadioAnswer4.Checked = false;
  168.            
  169.             QuestionLabel.Text = Question[i].question; //print the question in that array index
  170.            
  171.             RadioAnswer1.Text = Question[i].answers[0]; //prints the first option for an answer
  172.             RadioAnswer2.Text = Question[i].answers[1]; //prints the second option for an answer
  173.             RadioAnswer3.Text = Question[i].answers[2]; //prints the third option for an answer
  174.             RadioAnswer4.Text = Question[i].answers[3]; //prints the fourth option for an answer
  175.            
  176.             if ((RadioAnswer1.Checked) || (RadioAnswer2.Checked) || (RadioAnswer3.Checked) || (RadioAnswer4.Checked))
  177.             {
  178.                 if (RadioAnswer1.Checked)
  179.                 {
  180.                     Question[i].selectedAnswer = 1;
  181.                 }
  182.                 else if (RadioAnswer2.Checked)
  183.                 {
  184.                     Question[i].selectedAnswer = 2;
  185.                 }
  186.                 else if (RadioAnswer3.Checked)
  187.                 {
  188.                     Question[i].selectedAnswer = 3;
  189.                 }
  190.                 else if (RadioAnswer4.Checked)
  191.                 {
  192.                     Question[i].selectedAnswer = 4;
  193.                 }
  194.                 else
  195.                 {
  196.                     MessageBox.Show("You have not not answered the question. \n Please answer the question before proceeding");
  197.                 }
  198.             }
  199.            
  200.             i++;
  201.            
  202.             if (i == NumQuestions)
  203.             {
  204.                 Finish.Visible = true;
  205.                 StartQuiz.Enabled = false;
  206.             }
  207.         }
  208.        
  209.         private void Previous_Click(object sender, EventArgs e)
  210.         {
  211.         }
  212.        
  213.         private void MainImage_Click_1(object sender, EventArgs e)
  214.         {
  215.         }
  216.        
  217.         private void QuestionLabel_Click(object sender, EventArgs e)
  218.         {
  219.         }
  220.        
  221.         private void Finish_Click(object sender, EventArgs e)
  222.         {
  223.             Review.Visible = true;
  224.             Previous.Enabled = false;
  225.             Instructions.Enabled = false;
  226.            
  227.             for (int i = 0; i < 9; i++)
  228.             {      
  229.                 if (Question[i].selectedAnswer == Question[i].correctAnswer) //checks if the answer is correct
  230.                 {
  231.                     score = score + 1;
  232.                 }
  233.             }
  234.            
  235.             if (score <= 30)
  236.             {
  237.                 MessageBox.Show("Very poor. \nYou got " + score + "\nClick review to view your Incorrect Answers");//Prints User score
  238.             }
  239.             else if ((score > 30) && (score <= 50))
  240.             {
  241.                 MessageBox.Show("Could be better, You got " + score + "\nClick review to view your Incorrect Answers");//Prints User score
  242.             }
  243.             else if ((score >50) && (score<=60))
  244.             {
  245.                 MessageBox.Show("Not bad. Your score was " + score + "\nClick review to view your Incorrect Answers");//Prints User score
  246.             }
  247.             else if ((score >70) && (score<=90))
  248.             {
  249.                 MessageBox.Show("Well done your score was " + score + "\nClick review to view your Incorrect Answers");//Prints User score
  250.             }
  251.             else if (score == 100)
  252.             {
  253.                 MessageBox.Show("Fantastic you got every question right");//Prints User score
  254.             }
  255.         }
  256.        
  257.         private void Review_Click(object sender, EventArgs e)
  258.         {
  259.         }
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement