Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5. struct Users {
  6. char Name[10];
  7. char LastName[10];
  8. int Mobile;
  9. int ID;
  10. int score = rand()%100;
  11. };
  12. void fillUsersArray(Users* Array, int Size)
  13. {
  14. for (int i = 0; i < Size; i++)
  15. {
  16. cout << i + 1 << " )" << endl;
  17. cout << "Enter user name : ";
  18. cin >> Array[i].Name;
  19. cout << "Enter user last name : ";
  20. cin >> Array[i].LastName;
  21. cout << "Enter user mobile number : ";
  22. cin >> Array[i].Mobile;
  23. cout << "Enter user ID : ";
  24. cin >> Array[i].ID;
  25. }
  26. }
  27. void GetScoreForUsers(Users* Array, int Size)
  28. {
  29. for (int i = 0; i < Size; i++)
  30. {
  31. if (Array[i].score < 50)
  32. {
  33. cout << i + 1 << " ) user has : "<<Array[i].score << " and it is D" << endl;
  34. }
  35. else if(Array[i].score >= 50 && Array[i].score < 70)
  36. {
  37. cout << i + 1 << " ) user has : " << Array[i].score << " and it is C" << endl;
  38. }
  39. else if (Array[i].score >= 70 && Array[i].score < 90)
  40. {
  41. cout << i + 1 << " ) user has : " << Array[i].score << " and it is B" << endl;
  42. }
  43. else {
  44. cout << i + 1 << " ) user has : " << Array[i].score << " and it is A" << endl;
  45. }
  46. }
  47. }
  48. int MaxScoreUSer(Users* Array, int size)
  49. {
  50. int maxScore = 0;
  51. for (int i = 0; i < size; i++)
  52. {
  53. if (Array[i].score > maxScore)
  54. {
  55. maxScore = Array[i].score;
  56. }
  57. }
  58. return maxScore;
  59. }
  60. void SortUserArray(Users* Array, int Size)
  61. {
  62. for (int i = 0; i < Size; i++)
  63. {
  64. for (int j = i + 1; j < Size; j++)
  65. {
  66. if (Array[i].score < Array[j].score)
  67. {
  68. swap(Array[i], Array[j]);
  69. }
  70. }
  71. }
  72. }
  73. void printUsersArray(Users* Array, int Size)
  74. {
  75. for (int i = 0; i < Size; i++)
  76. {
  77. cout << i + 1 << " )" << endl;
  78. cout << " user name : " << Array[i].Name << endl;;
  79. cout << " user last name : " << Array[i].LastName << endl;;
  80. cout << " user mobile number : " << Array[i].Mobile << endl;;
  81. cout << " user ID : " << Array[i].ID << endl;;
  82. cout << " user score : " << Array[i].score << endl;
  83. }
  84. }
  85. int main()
  86. {
  87. srand(time(NULL));
  88. Users user1;
  89. Users user2;
  90. Users user3;
  91. Users user4;
  92. Users user5;
  93. Users UsersArray[5] = { user1,user2,user3,user4,user5 };
  94. fillUsersArray(UsersArray, 5);
  95. GetScoreForUsers(UsersArray, 5);
  96. cout << "Max score is : " << MaxScoreUSer(UsersArray, 5) << endl;
  97. SortUserArray(UsersArray, 5);
  98. printUsersArray(UsersArray, 5);
  99.  
  100. cin.get();
  101. cin.get();
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement