Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include"pch.h"
- #include<iostream>
- #include<stdlib.h>
- #include<string>
- using namespace std;
- class Vehicle
- {
- int i;
- int y;
- int p;
- public:
- void Add(int id, int year, int prize);
- void Show();
- int getid();
- int getyear();
- int getprize();
- };
- int Vehicle::getid(){
- return this->i;
- }
- int Vehicle::getyear(){
- return this->y;
- }
- int Vehicle::getprize(){
- return this->p;
- }
- void Vehicle::Add(int id, int year, int prize) {
- i = id;
- y = year;
- p = prize;
- }
- void Vehicle::Show() {
- cout << "ID number: " << i << endl;
- cout << "Year of production: " << y << endl;
- cout << "Prize: " << p << endl;
- }
- void Create(Vehicle* &t, int N)
- {
- t = (Vehicle*)malloc(N * sizeof(Vehicle));
- }
- void Create(Vehicle** &t, int N)
- {
- t = (Vehicle**)malloc(N * sizeof(Vehicle*));
- for (int i = 0; i < N; i++) {
- (t)[i] = (Vehicle*)malloc(N * sizeof(Vehicle));
- }
- }
- void Remove(Vehicle* &t) {
- free(t);
- t = NULL;
- }
- void Remove(Vehicle** &t, int N) {
- for (int i = 0; i < N; i++) {
- free(t[i]);
- }
- free(t);
- t = NULL;
- }
- void Add(Vehicle* &t, int N) {
- int id;
- int year;
- int prize;
- for (int i = 0; i < N; i++) {
- cout << "Add ID number: " << endl;
- cin >> id;
- cout << "Add year of production: " << endl;
- cin >> year;
- cout << "Add prize: " << endl;
- cin>>prize;
- t[i].Add(id, year, prize);
- }
- cout << "Choose one of menu options: " << endl;
- }
- void Add(Vehicle** &t, int N) {
- int id;
- int year;
- int prize;
- for (int i = 0; i < N; i++) {
- cout << "Add ID number: " << endl;
- cin >> id;
- cout << "Add year of production: " << endl;
- cin >> year;
- cout << "Add prize: " << endl;
- cin >> prize;
- t[i]->Add(id, year, prize);
- }
- cout << "Choose one of menu options: " << endl;
- }
- //**************************************************************
- void AddNext(Vehicle* &t, int &N, int id, int year, int prize){
- Vehicle* temp = NULL;
- Create(temp, (N+1));
- for(int i = 0; i < N; i++){
- temp[i].Add(t[i].getid(),t[i].getyear(), t[i].getprize());
- }
- temp[N].Add(id, year, prize);
- Remove(t);
- N++;
- t = temp;
- cout << "Choose one of menu options: " << endl;
- }
- void AddNext(Vehicle** &t, int &N, int id, int year, int prize){
- Vehicle** temp = NULL;
- Create(temp, (N+1));
- for(int i = 0; i < N; i++){
- temp[i]->Add(t[i]->getid(), t[i]->getyear(), t[i]->getprize());
- }
- temp[N]->Add(id, year, prize);
- Remove(t, N);
- N++;
- t = temp;
- cout << "Choose one of menu options: " << endl;
- }
- //****************************************************************
- void RemoveNext(Vehicle* &t, int &N, int k){
- int j = 0;
- Vehicle* temp = NULL;
- Create(temp, (N-1));
- for(int i = 0; i < (N); i++){
- if((k-1) != i){
- temp[j].Add(t[i].getid(), t[i].getyear(), t[i].getprize());
- j++;
- }
- }
- Remove(t);
- N--;
- t = temp;
- cout << "Choose one of menu options: " << endl;
- }
- void RemoveNext(Vehicle** &t, int &N, int k){
- int j = 0;
- Vehicle ** temp = NULL;
- Create(temp, (N-1));
- for(int i = 0; i < (N); i++){
- if((k-1) != i){
- temp[j]->Add(t[i]->getid(), t[i]->getprize(), t[i]->getprize());
- j++;
- }
- }
- Remove(t, N);
- N--;
- t = temp;
- cout << "Choose one of menu options: " << endl;
- }
- //**********************************************************
- void Show(Vehicle* t, int N) {
- cout << "List of vehicles: " << endl;
- for (int i = 0; i < N; i++) {
- t[i].Show();
- }
- cout << "Choose one of menu options: " << endl;
- }
- void Show(Vehicle** t, int N) {
- cout << "List of vehicles: " << endl;
- for (int i = 0; i < N; i++) {
- t[i]->Show();
- }
- cout << "Choose one of menu options: " << endl;
- }
- int Menu() {
- int Size1, Size2;
- int Year1, Year2;
- int Prize1, Prize2;
- int RemoveNext1, RemoveNext2;
- int AddNext1, AddNext2;
- Vehicle*vehicle1 = NULL;
- Vehicle**vehicle2 = NULL;
- int nrinstruction;
- cout
- << "----------------------------------------\n"
- << "---------- MENU - selection ----------\n"
- << "---Press 1 - intialize data on 1 wsk ---\n"
- << "---Press 2 - intialize data on 2 wsk ---\n"
- << "-------------Press 0 - exit-------------\n"
- << "----------------------------------------\n";
- do
- {
- cin >> nrinstruction;
- switch (nrinstruction)
- {
- case 1:
- int nrinstruction1;
- system("CLS");
- cout << "---------- MENU - selection ----------\n"
- << "---Press 1 - intialize data on 1 wsk ---\n"
- << "----------Press 2 - show 1 wsk----------\n"
- << "---------Press 3 - remove 1 wsk---------\n"
- << "----------Press 4 - add 1 wsk-----------\n"
- << "-----------Press 0 - go back------------\n"
- << "----------------------------------------\n";
- do
- {
- cin >> nrinstruction1;
- switch (nrinstruction1)
- {
- case 1:
- cout << "Type how much data you want to have:" << endl;
- cin >> Size1;
- Create(vehicle1, Size1);
- Add(vehicle1, Size1);
- break;
- case 2:
- Show(vehicle1, Size1);
- break;
- case 3:
- cout << "Chose id number: \n";
- cin >> RemoveNext1;
- RemoveNext(vehicle1, Size1, RemoveNext1);
- break;
- case 4:
- cout << "Add elements by ID number: \n";
- cin >> AddNext1;
- cout << "Add year of production: \n";
- cin >> Year1;
- cout << "Add prize: \n";
- cin >> Prize1;
- AddNext(vehicle1, Size1, AddNext1, Year1, Prize1);
- break;
- case 0:
- system("CLS");
- cout << "<-- Menu\n";
- return 1;
- default:
- cout << "Choose one of options: 1 - add amount, 2 - show data, 3 - remove data, 4 - add data, 0 - back to menu \n";
- break;
- }
- } while (nrinstruction1 !=0);
- Remove(vehicle1);
- break;
- case 2:
- int nrinstruction2;
- cout << "---------- MENU - selection ----------\n"
- << "---Press 1 - intialize data on 2 wsk ---\n"
- << "----------Press 2 - show 2 wsk----------\n"
- << "---------Press 3 - remove 2 wsk---------\n"
- << "----------Press 4 - add 2 wsk-----------\n"
- << "-----------Press 0 - go back------------\n"
- << "----------------------------------------\n";
- do
- {
- cin >> nrinstruction2;
- switch (nrinstruction2)
- {
- case 1:
- cout << "Type how much data you want to have:" << endl;
- cin >> Size2;
- Create(vehicle2, Size2);
- Add(vehicle2, Size2);
- break;
- case 2:
- Show(vehicle2, Size2);
- break;
- case 3:
- cout << "Chose id number: \n";
- cin >> RemoveNext2;
- RemoveNext(vehicle2, Size2, RemoveNext2);
- break;
- case 4:
- cout << "Add elements by ID number: \n";
- cin >> AddNext2;
- cout << "Add year of production: \n";
- cin >> Year2;
- cout << "Add prize: \n";
- cin >> Prize2;
- AddNext(vehicle2, Size2, AddNext2, Year2, Prize2);
- break;
- case 0:
- system("CLS");
- cout << "<-- Menu \n";
- return 1;
- default:
- cout << "Choose one of options: 1 - add amount, 2 - show data, 3 - remove data, 4 - add data, 0 - back to menu \n";
- break;
- }
- } while (nrinstruction2 != 0);
- Remove (vehicle2, Size2);
- break;
- case 0:
- cout << "Exiting \n";
- return 0;
- default:
- cout << "Choose one of options: 1 - 1 wsk, 2 - 2 wsk, 0 - exit \n";
- break;
- }
- } while (nrinstruction);
- }
- int main()
- {
- while (Menu());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement