Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 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 lab12
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void buttonGenerate_Click(object sender, EventArgs e)
  21. {
  22. AB.Text = "A,2";
  23. AC.Text = "C,1";
  24. AD.Text = "A,1";
  25.  
  26. BC.Text = "C,1";
  27. BD.Text = "B,1";
  28.  
  29. CD.Text = "C,2";
  30. }
  31.  
  32. private void calculPondere_Click(object sender, EventArgs e)
  33. {
  34. String[] input = new String[6];
  35. input[0] = AB.Text;
  36. input[1] = AC.Text;
  37. input[2] = AD.Text;
  38. input[3] = BC.Text;
  39. input[4] = BD.Text;
  40. input[5] = CD.Text;
  41.  
  42. double SA = 0, SB = 0, SC = 0, SD = 0;
  43. for(int i=0;i<input.Length; ++i)
  44. {
  45. if(!input[i].Contains(","))
  46. {
  47. MessageBox.Show("error input");
  48. break;
  49. }
  50.  
  51. if (input[i][0] == 'A')
  52. {
  53. SA += (input[i][2] - '0');
  54. }
  55. else if (input[i][0] == 'B')
  56. SB += (input[i][2] - '0');
  57. else if (input[i][0] == 'C')
  58. SC += (input[i][2] - '0');
  59. else if (input[i][0] == 'D')
  60. SD += (input[i][2] - '0');
  61.  
  62. }
  63.  
  64. double PA = SA / (SA + SB + SC + SD);
  65. double PB = SB / (SA + SB + SC + SD);
  66. double PC = SC / (SA + SB + SC + SD);
  67. double PD = SD / (SA + SB + SC + SD);
  68.  
  69. double max = PA;
  70. string pmax = "PA";
  71. if (PB > max)
  72. {
  73. max = PB;
  74. pmax = "PB";
  75. }
  76.  
  77. if (PC > max)
  78. {
  79. max = PC;
  80. pmax = "PC";
  81. }
  82.  
  83. if (PD > max)
  84. {
  85. max = PD;
  86. pmax = "PD";
  87. }
  88.  
  89.  
  90. textBoxResult.Text = "Ponderea maxima este: " + pmax + " = " + (max*100).ToString() + "%";
  91.  
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement