Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Project
- //
- // Created by Kenny Yu on 2017-03-27.
- // Copyright © 2017 Kenny Yu. All rights reserved.
- //
- // ListProgram.cpp: maintain a list of integers
- #include <iostream>
- using namespace std;
- int main() {
- int task, list_size, *list;
- //List Size starts at one Because of the Zero Value
- list_size = 1;
- list = new int[list_size];
- //while (true) {
- do{
- cout << "0. Exit" << endl;
- cout << "1. List" << endl;
- cout << "2. Add" << endl;
- cout << "3. Delete" << endl;
- cout << "Enter task: ";
- cin >> task;
- //Missing One Equal Sign (1)
- if (task == 1) {
- for (int i = 0; i <= list_size; i++)
- cout << list[i] << endl;
- cout << "There are " << list_size << " items in the list." << endl;
- }
- else if (task == 2) {
- int *new_list = new int[list_size + 1];
- //Increase of List size(2)
- list_size++;
- for (int i = 0; i < list_size; i++)
- new_list[i] = list[i];
- cout << "Enter a new item to add to the list: ";
- cin >> new_list[list_size];
- list = new_list;
- }
- else if (task == 3) {
- cout << "Enter the item to delete from the list: "<<endl;
- int *new_list2 = new int[list_size - 1];
- list_size--;
- for (int i = 0; i < list_size; i++)
- new_list2[i] = list[i];
- cout << "Enter a item to delete to the list: ";
- cin >> new_list2[list_size];
- list = new_list2;
- }
- } while (task != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement