Guest User

Untitled

a guest
Dec 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 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 TP01_Partie01
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. // tableau de nom, prenom tel
  15. string[] tabNoms = new string[10];
  16. string[] tabPrenoms = new string[10];
  17. string[] tabTelephones = new string[10];
  18.  
  19. // initialisation du nombre de client
  20. int nbreClient = 0;
  21. string nom, prenom, telephone;
  22. string part1, part2, part3, part4, part5, part6, part7;
  23.  
  24.  
  25. Console.WriteLine("Entrer le nombre de client");
  26. try
  27. {
  28. nbreClient = int.Parse(Console.ReadLine());
  29. }
  30. catch
  31. {
  32. Console.WriteLine("Introduire un nombre!");
  33. }
  34.  
  35. int cnt = 0;
  36. while (cnt < nbreClient)
  37. {
  38. Console.WriteLine("Entrer le nom du client");
  39. nom = Console.ReadLine();
  40. tabNoms[cnt] = nom;
  41. Console.WriteLine("Entrer le prenom du client");
  42. prenom = Console.ReadLine();
  43. tabPrenoms[cnt] = prenom;
  44.  
  45.  
  46. //------------------------------------- Saisi du Numero de telephone -------------------------------------
  47.  
  48. string TelephoneTest = "";
  49. bool isValid = true;
  50. while (true)
  51. {
  52. Console.WriteLine("Entrer le telephone du client sous cette forme (555) 555-5555");
  53. TelephoneTest = Console.ReadLine();
  54.  
  55.  
  56. if (TelephoneTest == "")
  57. {
  58. Console.WriteLine("\n" + "- Veuillez svp entrer un numero de telephone!" + "\n");
  59. isValid = false;
  60. }
  61. else
  62. if (TelephoneTest.Length != 14)
  63. {
  64. Console.WriteLine("- Le numero doit avoir 14 caracteres!");
  65. isValid = false;
  66. }
  67. else
  68. {
  69. part1 = TelephoneTest.Substring(0, 1);
  70. part2 = TelephoneTest.Substring(1, 3);
  71. part3 = TelephoneTest.Substring(4, 1);
  72. part4 = TelephoneTest.Substring(5, 1);
  73. part5 = TelephoneTest.Substring(6, 3);
  74. part6 = TelephoneTest.Substring(9, 1);
  75. part7 = TelephoneTest.Substring(10, 4);
  76.  
  77. int val;
  78.  
  79.  
  80.  
  81. if (part1 != "(")
  82. {
  83. isValid = false;
  84. Console.WriteLine("Vous devez utiliser des prentheses!");
  85. }
  86. else if (!int.TryParse(part2, out val) || !int.TryParse(part5, out val)
  87. || !int.TryParse(part7, out val))
  88. {
  89. isValid = false;
  90. Console.WriteLine("Vous devez utiliser des chiffres!");
  91. }
  92. else if ((part3 != ")") || (part4 != " "))
  93. {
  94. isValid = false;
  95. Console.WriteLine("Vous devez utiliser des prentheses et un espace!");
  96. }
  97.  
  98. }
  99. if (isValid)
  100. {
  101. break;
  102. }
  103.  
  104.  
  105. }
  106.  
  107. telephone = TelephoneTest;
  108. tabTelephones[cnt] = telephone;
  109. //------------------------------------- Fin de du Numero de telephone -------------------------------------
  110.  
  111. cnt++;
  112.  
  113.  
  114.  
  115. }
  116. int j = 1;
  117. for (int i = 0 ; i < nbreClient; i++,j=i+1)
  118. {
  119. Console.WriteLine("le nom du client numero " + j + " est " + tabNoms[i]);
  120. Console.WriteLine("le prenom du client numero " + j + " est " + tabPrenoms[i]);
  121. Console.WriteLine("le telephone du client numero " + j + " est " + tabTelephones[i]);
  122.  
  123. }
  124.  
  125. Console.ReadKey();
  126.  
  127.  
  128. }
  129. }
  130. }
Add Comment
Please, Sign In to add comment