Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 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.  
  11. namespace p_29_calcul_medie
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void textBox1_TextChanged(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. private void buttonExit_Click(object sender, EventArgs e)
  26. {
  27. Application.Exit();
  28. }
  29.  
  30. bool Validare()
  31. {
  32. string s = TextBoxNote.Text.Trim();
  33. if (s == String.Empty) return false;
  34. //verific notele din oral daca sunt valide
  35. for (int i = 0; i < s.Length; i++)
  36. if (!(('0' <= s[i] && s[i] <= '9') || (s[i] == ' ')))
  37. return false;
  38. string[] note = s.Split(new char[] { ' ' },
  39. StringSplitOptions.RemoveEmptyEntries);
  40. foreach (string w in note)
  41. {
  42. if (w.Length > 2) return false;
  43. int x = int.Parse(w);
  44. if (x < 1 || x > 10) return false;
  45. }
  46. if (note.Length < 2) return false;
  47. //verific nota la teza
  48. s = TextBoxTeza.Text.Trim();
  49. if (s == String.Empty) return true; // nu e nota in teza
  50.  
  51. if (s.Length > 2) return false;
  52.  
  53. for (int i = 0; i < s.Length; i++)
  54. if (s[i] < '0' || s[i] > '9') return false;
  55. int y = int.Parse(s);
  56. if (y < 1 || y > 10) return false;
  57. return true;
  58. }
  59.  
  60. private void buttonCalcul_Click(object sender, EventArgs e)
  61. {
  62. if (!Validare())
  63. {
  64. MessageBox.Show("Date introduse eronat!");
  65. return;
  66. }
  67.  
  68. //calculez suma notelor in oral si numarul de note
  69. double s = 0;
  70. int n = 0;
  71. string[] note = TextBoxNote.Text.Split(new char[] { ' ' },
  72. StringSplitOptions.RemoveEmptyEntries);
  73. n = note.Length;
  74. foreach (string w in note)
  75. {
  76. s += int.Parse(w);
  77. }
  78. s = s / n;
  79. string t = TextBoxTeza.Text.Trim();
  80. if (t == String.Empty)
  81. {
  82. //nu este nota la teza
  83. int x = (int)(s * 100);
  84. s = x / 100.0;
  85. TextBoxMedia.Text = s.ToString();
  86. }
  87. else // este si teza
  88. {
  89.  
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement