Advertisement
Guest User

LAB4

a guest
Oct 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define SIZE 5
  5.  
  6. int tab[SIZE];
  7. int bat[SIZE];
  8. char x;
  9. int n, i;
  10. int w = 0;
  11.  
  12.  
  13. int main() {
  14. cout << "Wpisz instrukcje, ktora chcesz aktywowac: ";
  15. while (cin >> x) {
  16. if (x == 'A') {
  17. if (w < SIZE) {
  18. cin >> n;
  19. tab[w] = n;
  20. bat[w] = n;
  21. w++;
  22. }
  23. } else if (x == 'I') {
  24. cin >> n;
  25. cin >> i;
  26. tab[i] = n;
  27. } else if (x == 'P') {
  28. cin >> i;
  29. for (int j =0; j<SIZE; j+=i) {
  30. cout << bat[j] << " " <<endl;
  31. }
  32. } else if (x == 'M') {
  33. for (int z=0; z<SIZE-1; z++)
  34. for (int y=0; y<SIZE-1; y++)
  35. if (bat[y]>tab[y+1])
  36. swap(tab[y], tab[y+1]);
  37. cout << tab[0] << " " << tab[1] << endl;
  38. } else if (x == 'Q') {
  39. break;
  40. } else {
  41. cout << "Nie ma takiej instrukcji";
  42. }
  43. }
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement