Advertisement
DrAungWinHtut

Exam Update 1

Mar 22nd, 2022
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.03 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Exam_System
  13. {
  14.     public partial class frmExam : Form
  15.     {
  16.  
  17.         string[] saQuestions = new string[100];
  18.         string[] saCurrentQuestion = new string[7];
  19.         int iCurrentQno = 0;
  20.         int iTotalQ = 0;
  21.         string sCurrentCorrectAns = "";
  22.  
  23.         public frmExam()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.  
  28.         private void frmExam_Load(object sender, EventArgs e)
  29.         {
  30.             txtScores.Text = "0";
  31.  
  32.             try
  33.             {
  34.                 // Create an instance of StreamReader to read from a file.
  35.                 // The using statement also closes the StreamReader.
  36.                 using (StreamReader sr = new StreamReader("D:\\CStutorial\\Quiz\\q1.txt"))
  37.                 {
  38.                     string line;
  39.                     // Read and display lines from the file until the end of
  40.                     // the file is reached.
  41.                     while ((line = sr.ReadLine()) != null)
  42.                     {
  43.                         saQuestions[iTotalQ] = line;
  44.                         iTotalQ = iTotalQ + 1;
  45.                     }
  46.                 }
  47.             }
  48.             catch (Exception ex)
  49.             {
  50.                MessageBox.Show (ex.Message);
  51.             }
  52.             funNextQuestion();
  53.            
  54.         }
  55.  
  56.         private void funMarking()
  57.         {
  58.             if( rdo1.Checked == false && rdo2.Checked == false && rdo3.Checked == false && rdo4.Checked == false )
  59.             {
  60.                 MessageBox.Show("Please Choose One Answer");
  61.             }
  62.             else
  63.             {
  64.                 int iScore = int.Parse(txtScores.Text);
  65.                 if (sCurrentCorrectAns == "1" && rdo1.Checked == true)
  66.                 {
  67.                     iScore = iScore + 10;
  68.                 }
  69.                 else if (sCurrentCorrectAns == "2" && rdo2.Checked == true)
  70.                 {
  71.                     iScore = iScore + 10;
  72.                 }
  73.                 else if (sCurrentCorrectAns == "3" && rdo3.Checked == true)
  74.                 {
  75.                     iScore = iScore + 10;
  76.                 }
  77.                 else if (sCurrentCorrectAns == "4" && rdo4.Checked == true)
  78.                 {
  79.                     iScore = iScore + 10;
  80.                 }
  81.                 txtScores.Text = iScore.ToString();
  82.                 btnSubmit.Enabled = false;
  83.                 rdo1.Enabled = false;
  84.                 rdo2.Enabled = false;
  85.                 rdo3.Enabled = false;
  86.                 rdo4.Enabled = false;
  87.             }
  88.  
  89.            
  90.            
  91.         }
  92.  
  93.         private void btnSubmit_Click(object sender, EventArgs e)
  94.         {
  95.             funMarking();
  96.             btnNext .Enabled = true;
  97.            
  98.         }
  99.  
  100.         private void btnNext_Click(object sender, EventArgs e)
  101.         {
  102.             if(iCurrentQno < iTotalQ ) //    4 - 0 1 2 3
  103.             {
  104.                 funNextQuestion();
  105.             }
  106.             else{
  107.                 MessageBox.Show("The Quiz is Over");
  108.                 btnNext .Enabled = false;    
  109.             }
  110.            
  111.         }
  112.  
  113.         private void funNextQuestion()
  114.         {
  115.             saCurrentQuestion = saQuestions[iCurrentQno].Split('#');
  116.             txtQuestion.Text = saCurrentQuestion[1];
  117.             rdo1.Text = saCurrentQuestion[2];
  118.             rdo2.Text = saCurrentQuestion[3];
  119.             rdo3.Text = saCurrentQuestion[4];
  120.             rdo4.Text = saCurrentQuestion[5];
  121.             sCurrentCorrectAns = saCurrentQuestion[6];
  122.             iCurrentQno++;
  123.             lblQno.Text = iCurrentQno + "/" + iTotalQ;
  124.             btnSubmit.Enabled = true;
  125.             rdo1.Enabled = true;
  126.             rdo2.Enabled = true;
  127.             rdo3.Enabled = true;
  128.             rdo4.Enabled = true;
  129.  
  130.             btnNext.Enabled = false;
  131.         }
  132.     }
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement