Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // лаба2.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- //#include <stdlib.h>
- #include <iostream>
- using namespace std;
- const int N = 3;
- void Add(int Q[], int *Last, int *cnt) {
- if (*cnt == N)
- cout << "Polna!" << endl;
- else {
- if (*Last == N) {
- *Last = 0;
- }
- cout << "Value" << endl;
- cin >> Q[*Last];
- *Last = *Last + 1;
- *cnt = *cnt + 1;
- cout << "Added" << endl;
- }
- }
- void Show(int Q[], int First, int Last, int cnt)
- {
- int i;
- if (cnt != 0) {
- if (First < Last)
- {
- for (i = First; i < Last; i++)
- {
- cout << Q[i];
- cout << " ";
- }
- }
- else if (Last <= First) {
- for (i = First; i < N; i++)
- {
- cout << Q[i];
- cout << " ";
- }
- for (i = 0; i < Last; i++)
- {
- cout << Q[i];
- cout << " ";
- }
- }
- cout << "" << endl;
- }
- else {
- cout << "Pusto" << endl;
- }
- }
- void Delete(int Q[], int *First, int *cnt, int *Last) {
- if (*cnt == 0)
- cout << "Pusto!" << endl;
- else {
- Q[*First] = NULL;
- *First = *First + 1;
- if (*First == N) {
- *First = 0;
- }
- *cnt = *cnt - 1;
- if (*cnt == 0) {
- *First = 0;
- *Last = 0;
- }
- cout << "Deleted" << endl;
- }
- }
- int main()
- {
- char otvet;
- int Q[N], Last = 0, First = 0;
- int cnt = 0;
- do {
- cout << "Menu" << endl;
- cout << "1. Add" << endl;
- cout << "2. Delete" << endl;
- cout << "3. Show" << endl;
- cout << "0. Exit" << endl;
- cin >> otvet;
- switch (otvet)
- {
- case '1':
- Add(Q, &Last, &cnt);
- break;
- case '2':
- Delete(Q, &First, &cnt, &Last);
- break;
- case '3':
- Show(Q, First, Last, cnt);
- break;
- }
- } while (otvet != '0');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement