<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   List.h
 * Author: tiara
 *
 * Created on May 26, 2019, 4:49 PM
 */

//header file List.h
typedef int ElementType;
const int MAX = 100;

class List {
public:
    List(); //create an empty list
    bool Empty(); //return true if the list is empty, otherwise return false
    void InsertAtEnd(ElementType x); //insert a value x on the end of the list
    void Delete(ElementType x); //if value x is in the list, remove x
    void Display(); //display the data values in the list in the order inserted
    int Sum(); //compute and return the sum of the values in the list
    int Average();

private:
    int N; //number of values in list
    ElementType listArray[MAX]; //the array to hold the list values

};
<file_sep># COMP280-PROGRAM1
COMP280 Programming Assignment 1 (List - Array Implementation)

Create a List object. Using the following definition (List.h file) for a list, implement the member functions (methods) for the List class and store the implementation in file List.cpp.  Use an array to implement the list. Write the client code (the main method and other non-class methods) and put those methods in file main.cpp. 

//file: List.h 
typedef int ElementType;
const int MAX = 100;
class List
{
 public: 
   List(); //Create an empty list
   bool Empty(); // return true if the list is empty, otherwise return false
   void InsertAtEnd(ElementType x); //insert a value x on the end of the list
   void Delete(ElementType x); //if value x is in the list, remove x
   void Display(); //Display the data values in the list in the order inserted	
   int Sum(); // Compute and return the sum of the values in the list
   int Average(); // Compute and return the average of the values in the list

 private:
	int N; //number of values in list
ElementType listArray[MAX]; //the array to hold the list values
};

Your client code should be menu driven using the following menu options:
1.	Insert
2.	Delete
3.	Display
4.	Sum
5.	Average
6.	Exit

Option 1: Insert a new value on the end of the list. 
Option 2: Delete a number specified by the user from the list, if the number is in the list.
Option 3: Displayed in the list of numbers.
Option 4: Compute and return the sum of the values in the list. If the list is empty return 0.
Option 5: Compute and return the average of the values in the list. If the list is empty return 0.
Option 6: Exits the program.
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   List.cpp
 * Author: tiara
 * 
 * Created on May 26, 2019, 4:49 PM
 */


//implementation file List.cpp
#include "List.h"
#include <iostream>
using namespace std;

List::List() {
    N = 0;
    listArray[MAX];
}

bool List::Empty() {
    if (N = 0) {
        return true;
    }
    return false;
}

void List::InsertAtEnd(ElementType x) {
    cin >> x;
    cout << x << endl;
    N++;
    listArray[N - 1] = x;
    cout << "Value added";
}

void List::Delete(ElementType x) {
    for (int i = 0; i < N; i++) {
        if (listArray[i] == x) {
            for (int j = i; j < N - 1; j++) {
                listArray[j] = listArray[j + 1];
            }
            N--;
        }
    }
}

void List::Display() {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            cout << ", ";
        }
        cout << listArray[i];
    }
}

int List::Sum() {
    int sum = 0;
    for (int i = 0; i < N; i++)
        sum += listArray[i];
    return sum;
}

int List::Average() {
    return (Sum() / N);
}



