Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- void push_back(int *&mass, int &N, const int value);
- void pop_back(int *&mass, int &N);
- void push_front(int *&mass, int &N, const int value);
- void pop_front(int *&mass, int &N);
- int main()
- {
- int N, ch, exit = 0;
- cout << "Enter integer values: ";
- cin >> N;
- int *mass = new int[N];
- ifstream ff("text.txt");
- if (!ff) {
- cout << "Sorry, we can't fle$$$ your file!";
- return 0;
- }
- for (int i = 0; i < N; i++)
- {
- ff >> mass[i];
- cout << mass[i] << " ";
- }
- ff.close();
- do {
- cout << endl << "1) Task 1" << endl << "2) Task 2" << endl << "3) Task 3" << endl << "4) Task 4" << endl << "5) Task 5" << endl << "6) Task 6" << endl << "7) Task 7" << endl << "8) Task 8" << endl << "9) Exit" << endl;
- cin >> ch;
- if (ch == 1) {
- int newEl;
- cout << "Enter the new element: ";
- cin >> newEl;
- push_back(mass, N, newEl);
- for (int i = 0; i < N; i++)
- {
- ff >> mass[i];
- cout << mass[i] << " ";
- }
- }
- else if (ch == 2) {
- pop_back(mass, N);
- for (int i = 0; i < N; i++)
- {
- ff >> mass[i];
- cout << mass[i] << " ";
- }
- }
- else if (ch == 3) {
- int newEl3;
- cout << "Enter the new element: ";
- cin >> newEl3;
- push_front(mass, N, newEl3);
- for (int i = 0; i < N; i++)
- {
- ff >> mass[i];
- cout << mass[i] << " ";
- }
- }
- else if (ch == 4) {
- pop_front(mass, N);
- for (int i = 0; i < N; i++)
- {
- ff >> mass[i];
- cout << mass[i] << " ";
- }
- }
- else if (ch == 9) exit = 1;
- else cout << endl << "We are apologize, but this part of program doesn't work." << endl << "Please, choose a correct task from menu or ask admin what to do and stand by." << endl;
- } while (exit != 1);
- delete[] mass;
- return 0;
- }
- void push_back(int *&mass, int &N, const int value)
- {
- int *newMass = new int[N + 1];
- for (int i = 0; i < N; i++)
- {
- newMass[i] = mass[i];
- }
- newMass[N] = value;
- N++;
- delete[] mass;
- mass = newMass;
- }
- void pop_back(int *&mass, int &N)
- {
- N--;
- int *newMass = new int[N];
- for (int i = 0; i < N; i++)
- {
- newMass[i] = mass[i];
- }
- delete[] mass;
- mass = newMass;
- }
- void push_front(int *&mass, int &N, const int value)
- {
- cout << "Enter N: ";
- cin >> N;
- int *newMass = new int[N];
- newMass[0] = N;
- for (int i = 1; i < N; i++)
- {
- newMass[i] = mass[i - 1];
- }
- delete[] mass;
- mass = newMass;
- }
- void pop_front(int *&mass, int &N)
- {
- int *newMass = new int[N];
- for (int i = 0; i < N - 1; ++i)
- {
- newMass[i] = mass[i + 1];
- }
- N--;
- delete[] mass;
- mass = newMass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement