Advertisement
Guest User

Untitled

a guest
May 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 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. using System.IO;
  7.  
  8. namespace BubbleIceCream
  9. {
  10. public struct Players
  11. {
  12. public string firstname;
  13. public string lastname;
  14. public string interest;
  15. public int points;
  16. }
  17. class Program
  18. {
  19. public static int playercount = 43;
  20.  
  21. static void Main()
  22. {
  23. Players[] player = new Players[playercount];
  24. Load(player);
  25. Sort(player);
  26.  
  27. }
  28.  
  29.  
  30. public static void Load(Players[] player)
  31. {
  32. StreamReader sr = new StreamReader(@"C:\Users\thomcs4\OneDrive - Otago Polytechnic\BITY1\IN510 Programming 1\FamilyFeud\familyFeud.txt");
  33. for (int i = 0; i < playercount; i++)
  34. {
  35. player[i].firstname = sr.ReadLine();
  36. player[i].lastname = sr.ReadLine();
  37. player[i].interest = sr.ReadLine();
  38. player[i].points = 0;
  39. }
  40. Console.WriteLine("Playerdata has loaded.");
  41. Console.ReadLine();
  42. }
  43.  
  44. public static void Sort(Players[] player)
  45. {
  46. Players temp;
  47. for (int i = 0; i < player.Length - 1; i++)
  48. {
  49. for (int pos = 0; pos < player.Length - 1; pos++)
  50. {
  51. if (player[pos + 1].firstname.CompareTo(player[pos].firstname) < 0)
  52. {
  53. temp = player[pos + 1];
  54. player[pos + 1] = player[pos];
  55. player[pos] = temp;
  56. }
  57. }
  58. }
  59.  
  60. for (int i = 0; i < playercount; i++)
  61. {
  62. Console.WriteLine($"{player[i].firstname.PadRight(20)} {player[i].lastname.PadRight(20)}");
  63. }
  64. Console.ReadLine();
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement