Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. // лаба2.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6. //#include <stdlib.h>
  7. #include <iostream>
  8.  
  9.  
  10. using namespace std;
  11. const int N = 3;
  12.  
  13.  
  14. void Add(int Q[], int *Last, int *cnt) {
  15. if (*cnt == N)
  16. cout << "Polna!" << endl;
  17. else {
  18. if (*Last == N) {
  19. *Last = 0;
  20. }
  21. cout << "Value" << endl;
  22. cin >> Q[*Last];
  23. *Last = *Last + 1;
  24. *cnt = *cnt + 1;
  25. cout << "Added" << endl;
  26. }
  27. }
  28.  
  29. void Show(int Q[], int First, int Last, int cnt)
  30. {
  31. int i;
  32. if (cnt != 0) {
  33. if (First < Last)
  34. {
  35. for (i = First; i < Last; i++)
  36. {
  37. cout << Q[i];
  38. cout << " ";
  39. }
  40. }
  41. else if (Last <= First) {
  42. for (i = First; i < N; i++)
  43. {
  44. cout << Q[i];
  45. cout << " ";
  46. }
  47. for (i = 0; i < Last; i++)
  48. {
  49. cout << Q[i];
  50. cout << " ";
  51. }
  52. }
  53. cout << "" << endl;
  54. }
  55. else {
  56. cout << "Pusto" << endl;
  57. }
  58. }
  59.  
  60. void Delete(int Q[], int *First, int *cnt, int *Last) {
  61. if (*cnt == 0)
  62. cout << "Pusto!" << endl;
  63. else {
  64. Q[*First] = NULL;
  65. *First = *First + 1;
  66. if (*First == N) {
  67. *First = 0;
  68. }
  69. *cnt = *cnt - 1;
  70. if (*cnt == 0) {
  71. *First = 0;
  72. *Last = 0;
  73. }
  74. cout << "Deleted" << endl;
  75. }
  76. }
  77.  
  78. int main()
  79. {
  80. char otvet;
  81. int Q[N], Last = 0, First = 0;
  82. int cnt = 0;
  83. do {
  84. cout << "Menu" << endl;
  85. cout << "1. Add" << endl;
  86. cout << "2. Delete" << endl;
  87. cout << "3. Show" << endl;
  88. cout << "0. Exit" << endl;
  89. cin >> otvet;
  90. switch (otvet)
  91. {
  92. case '1':
  93. Add(Q, &Last, &cnt);
  94. break;
  95. case '2':
  96. Delete(Q, &First, &cnt, &Last);
  97. break;
  98. case '3':
  99. Show(Q, First, Last, cnt);
  100. break;
  101. }
  102. } while (otvet != '0');
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement