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.Threading.Tasks;
- using System.Windows.Forms;
- namespace p_29_calcul_medie
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void buttonExit_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- bool Validare()
- {
- string s = TextBoxNote.Text.Trim();
- if (s == String.Empty) return false;
- //verific notele din oral daca sunt valide
- for (int i = 0; i < s.Length; i++)
- if (!(('0' <= s[i] && s[i] <= '9') || (s[i] == ' ')))
- return false;
- string[] note = s.Split(new char[] { ' ' },
- StringSplitOptions.RemoveEmptyEntries);
- foreach (string w in note)
- {
- if (w.Length > 2) return false;
- int x = int.Parse(w);
- if (x < 1 || x > 10) return false;
- }
- if (note.Length < 2) return false;
- //verific nota la teza
- s = TextBoxTeza.Text.Trim();
- if (s == String.Empty) return true; // nu e nota in teza
- if (s.Length > 2) return false;
- for (int i = 0; i < s.Length; i++)
- if (s[i] < '0' || s[i] > '9') return false;
- int y = int.Parse(s);
- if (y < 1 || y > 10) return false;
- return true;
- }
- private void buttonCalcul_Click(object sender, EventArgs e)
- {
- if (!Validare())
- {
- MessageBox.Show("Date introduse eronat!");
- return;
- }
- //calculez suma notelor in oral si numarul de note
- double s = 0;
- int n = 0;
- string[] note = TextBoxNote.Text.Split(new char[] { ' ' },
- StringSplitOptions.RemoveEmptyEntries);
- n = note.Length;
- foreach (string w in note)
- {
- s += int.Parse(w);
- }
- s = s / n;
- string t = TextBoxTeza.Text.Trim();
- if (t == String.Empty)
- {
- //nu este nota la teza
- int x = (int)(s * 100);
- s = x / 100.0;
- TextBoxMedia.Text = s.ToString();
- }
- else // este si teza
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement