Advertisement
Guest User

STUDENTE

a guest
May 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.23 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. using System.IO;
  10.  
  11. namespace studenti
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         Class1 st = new Class1();
  16.         int punt;
  17.         int pos;
  18.         float medd,tott;
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e)
  26.         {
  27.            
  28.         }
  29.  
  30.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  31.         {
  32.             int.TryParse(comboBox1.Text, out pos);
  33.             if (pos<1 || pos>10)
  34.             {
  35.                 return;
  36.             }
  37.             textBox3.Text = st.punteggio[pos].ToString();
  38.  
  39.             if (textBox3.Text == "0")
  40.             {
  41.                 textBox3.Text = "";
  42.             }
  43.         }
  44.  
  45.         private void button3_Click(object sender, EventArgs e)
  46.         {
  47.             punt =Convert.ToInt32(textBox3.Text);
  48.             textBox3.Text = "";
  49.             st.Aggiungi(punt, pos);
  50.         }
  51.         private void button2_Click(object sender, EventArgs e)
  52.         {
  53.             medd=st.Media();
  54.             label7.Text = "Media: " + medd.ToString();
  55.         }
  56.  
  57.         private void button1_Click(object sender, EventArgs e)
  58.         {
  59.             tott = st.Totale();
  60.             label6.Text = "Totale: " + tott.ToString();
  61.         }
  62.  
  63.         private void textBox3_TextChanged(object sender, EventArgs e)
  64.         {
  65.            
  66.         }
  67.  
  68.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  69.         {
  70.  
  71.         }
  72.  
  73.         private void textBox1_TextChanged(object sender, EventArgs e)
  74.         {
  75.  
  76.         }
  77.  
  78.         private void button4_Click(object sender, EventArgs e)
  79.         {
  80.             comboBox2.Items.Add(textBox1.Text);
  81.             comboBox2.Items.Add(textBox2.Text);
  82.             for (int i=0; i<=10;i++){
  83.                 comboBox2.Items.Add("Questionario " + i + ":" + st.punteggio[i].ToString());
  84.             }
  85.  
  86.             StreamWriter pagella = new StreamWriter("pagella.txt");
  87.             for (int i = 0; i < comboBox2.Items.Count; i++)
  88.             {
  89.                 pagella.WriteLine(comboBox2.Items[i].ToString());
  90.             }
  91.             pagella.Close();
  92.             comboBox2.Items.Clear();
  93.         }
  94.  
  95.  
  96.     }
  97. }
  98.  
  99.  
  100. CLASSE--------------------------------------------------------------------
  101.  
  102. using System;
  103. using System.Collections.Generic;
  104. using System.Linq;
  105. using System.Text;
  106.  
  107. namespace studenti
  108. {
  109.     class Class1
  110.     {
  111.         private string nome;
  112.         private string cognome;
  113.         private float tot;
  114.         private float med;
  115.         public int[] punteggio = new int[11];
  116.         private int count = 0;
  117.  
  118.         public string Nome
  119.         {
  120.             set { nome = value; }
  121.             get { return nome; }
  122.         }
  123.         public string Cognome
  124.         {
  125.             set { cognome = value; }
  126.             get { return cognome; }
  127.         }
  128.         public float Tot
  129.         {
  130.             set { tot = value; }
  131.             get { return tot; }
  132.         }
  133.         public float Med
  134.         {
  135.             set { med = value;}
  136.             get { return med; }
  137.         }
  138.         public Class1()
  139.         {
  140.             nome = "";
  141.             cognome = "";
  142.            
  143.         }
  144.  
  145.         public void Aggiungi(int punteggio1, int po)
  146.         {
  147.             punteggio[po] = punteggio1;
  148.         }
  149.         public float Media()
  150.         {
  151.             count = 0;
  152.             tot = 0;
  153.             for (int i = 0; i < 10; i++)
  154.             {
  155.                 if (punteggio[i] > 0)
  156.                 {
  157.                     tot += punteggio[i];
  158.                     count++;
  159.                 }                
  160.             }
  161.             med = tot / count;
  162.             return med;
  163.         }
  164.         public float Totale()
  165.         {
  166.             tot = 0;
  167.             for (int i = 0; i < 10; i++)
  168.             {
  169.                 if (punteggio[i] > 0)
  170.                 {
  171.                     tot += punteggio[i];
  172.                 }                
  173.             }
  174.             return tot;
  175.         }
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement