Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int i=0;
  6. string name[100];
  7. int input[100];
  8.  
  9. void heapify(int arr[], string arrN[], int n, int i)
  10. {
  11. int largest = i;
  12. int l = 2*i + 1;
  13. int r = 2*i + 2;
  14.  
  15. // if left child is larger than root
  16. if (l < n && arr[l] > arr[largest])
  17. largest = l;
  18.  
  19. // if right child is larger than largest so far
  20. if (r < n && arr[r] > arr[largest])
  21. largest = r;
  22.  
  23. // if largest is not root
  24. if (largest != i)
  25. {
  26. swap(arr[i], arr[largest]);
  27. swap(arrN[i],arrN[largest]);
  28.  
  29. // recursively heapify the affected sub-tree
  30. heapify(arr,arrN, n, largest);
  31. }
  32. }
  33.  
  34. void heapSort(int arr[], string arrN[], int n)
  35. {
  36. // build heap (rearrange array)
  37. for (int i = n / 2 - 1; i >= 0; i--)
  38. heapify(arr, arrN, n, i);
  39.  
  40. // one by one extract an element from heap
  41. for (int i=n-1; i>=0; i--)
  42. {
  43. // move current root to end
  44. swap(arr[0], arr[i]);
  45. swap(arrN[0],arrN[i]);
  46.  
  47. // call max heapify on the reduced heap
  48. heapify(arr,arrN, i, 0);
  49. }
  50. }
  51.  
  52. /* function to print array of size n */
  53. void printArray(int arr[],string arrN[], int n)
  54. {
  55. for (int i = 0; i < n; i++)
  56. {
  57. cout << (i+1) << ". "<< arrN[i];
  58. cout << " - " << arr[i] << " Php" << endl;
  59.  
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66. int mainUI()
  67. {
  68. int choices;
  69.  
  70. cout << "Welcome to Kenneth's Workshop" << endl << endl;
  71. cout << " [0] View all Employees" << endl;
  72. cout << " [1] Add Employees(With Salary)" << endl;
  73. cout << " [2] Exit Program" << endl;
  74.  
  75. cin >> choices;
  76. switch(choices)
  77. {
  78. case 0:
  79. {
  80.  
  81. cout << " VIEW ALL EMPLOYEES ALONG THEIR SALARIES" << endl << endl;
  82.  
  83. string names[i];
  84. int salary[i];
  85. for(int j = 0; j <i ; j++)
  86. {
  87. if(j == i+1)
  88. {
  89. break;
  90. }
  91. names[j] = name[j];
  92. salary[j] = input[j];
  93. }
  94. int n = sizeof(salary)/sizeof(salary[0]);
  95.  
  96. heapSort(salary, names, n);
  97. printArray(salary,names, n);
  98. system("pause");
  99. system("cls");
  100. mainUI();
  101. }
  102. case 1:
  103. {
  104. system("cls");
  105. while(true){
  106. cout << "Enter all of your data here" << endl << endl;
  107. cout << "Enter name of employee: ";
  108. cin >> name[i];
  109.  
  110. if(name[i]=="~"){
  111. break;
  112. }
  113.  
  114. cout << "Enter salary: ";
  115. cin >> input[i];
  116. i++;
  117. system("cls");
  118. }
  119. system("cls");
  120. mainUI();
  121. }
  122. case 2:
  123. {
  124. return 0;
  125. }
  126. }
  127. }
  128.  
  129. int main(){
  130. mainUI();
  131.  
  132. return 0;
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement