Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace p32_test_grila
  8. {
  9.     class Intrebare
  10.     {
  11.         public string tip; // unic sau multiplu
  12.         public string enuntIntrebare;
  13.         public string[] varianteRaspuns;
  14.         public int[] rasp; // indicii raspunsurilor corecte
  15.         public Intrebare(string _tip, string E, string[] _vR, string R)
  16.         {
  17.             tip = _tip;
  18.             enuntIntrebare = E;
  19.             varianteRaspuns = new string[_vR.Length];
  20.             for (int i = 0; i < _vR.Length; i++)
  21.                 varianteRaspuns[i] = _vR[i];
  22.             string[] nr = R.Split(new char[] { ' ' },
  23.                 StringSplitOptions.RemoveEmptyEntries);
  24.             rasp = new int[nr.Length];
  25.             for (int i = 0; i < nr.Length; i++)
  26.                 rasp[i] = int.Parse(nr[i]);
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32.  
  33. using System;
  34. using System.Collections.Generic;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Drawing;
  38. using System.IO;
  39. using System.Linq;
  40. using System.Text;
  41. using System.Threading.Tasks;
  42. using System.Windows.Forms;
  43.  
  44. namespace p32_test_grila
  45. {
  46.     public partial class Form1 : Form
  47.     {
  48.         public int nrIntrebari;
  49.         List<Intrebare> L;
  50.         Intrebare[] a;// am memorat primele 7 intrebari
  51.  
  52.         int nrCrt; // la a cata intrebare suntem
  53.  
  54.  
  55.         // afisezala ecran intrebarea cu nr de ordine nrCrt
  56.  
  57.         public void IncarcareIntrebre()
  58.         {
  59.             if (a[nrCrt].tip == 'unic)
  60.            {
  61.                Label labelEnunt = new Label();
  62.                labelEnunt.Text = a[nrCrt].enuntIntrebare;
  63.                labelEnunt.Location = new Point(5, 5);
  64.                labelEnunt.AutoSize = true;
  65.                labelEnunt.Font = new Font("Times New Roman", 14, FontStyle.Bold);
  66.                labelEnunt.ForeColor = Color.Blue;
  67.        }
  68.  
  69.        public void AlegeSapteIntrebari()
  70.        {
  71.            nrIntrebari = L.Count;
  72.            a = new Intrebare[8];
  73.            Random w = new Random();
  74.            int[] t = new int[8];
  75.            int k = 0; // cate intrebari distincte am ales
  76.            while (k < 7)
  77.            {
  78.                int p = w.Next(nrIntrebari);
  79.                int gasit = 0;
  80.                for (int i = 1; i <= k; i++)
  81.                    if (t[i] == p)
  82.                        gasit = 1;
  83.                if (gasit == 0)
  84.                    t[++k] = p;
  85.            }
  86.            for (int i = 1; i <= 7; i++)
  87.                a[i] = L[t[i]];
  88.            labelnrcrd.Text = a[1].enuntIntrebare;
  89.        }
  90.  
  91.        public Form1()
  92.        {
  93.            InitializeComponent();
  94.            CitireIntrebare();
  95.            AlegeSapteIntrebari();
  96.        }
  97.        public void CitireIntrebare()
  98.        {
  99.            if (!File.Exists("test.txt"))
  100.            {
  101.                MessageBox.Show("Fisier inexistent");
  102.                return;
  103.            }
  104.            L = new List<Intrebare>();
  105.            StreamReader fin = new StreamReader("test.txt");
  106.            Intrebare Q;
  107.            string _tip;
  108.            string E;
  109.            int n;
  110.            string[] v;
  111.            string R;
  112.  
  113.            while ((_tip = fin.ReadLine()) != null)
  114.            {
  115.                E = fin.ReadLine();
  116.                n = int.Parse(fin.ReadLine());
  117.                v = new string[n];
  118.                for (int i = 0; i < n; i++)
  119.                    v[i] = fin.ReadLine();
  120.                R = fin.ReadLine();
  121.                Q = new Intrebare(_tip, E, v, R);
  122.                L.Add(Q);
  123.                //label1.Text = Q.rasp[0].ToString(); // verificare
  124.            }
  125.            //label1.Text = L.Count.ToString();
  126.        }
  127.    }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement