#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
usingnamespace std;
class container {
public:
container();
// Postcondition: all data array elements are initialized to 0; count is set to -1
void insert(int value);
// Precondition: "data" array must not be full
// Postcondition: if the container is not full, insert the value data array (first available location from left) and increment count by 1.
// If the data array is full, display "Container is full; program is terminated!"
// and then terminates the program with exit(1) command.
void remove(int & value);
// Precondition: container must not be empty, i.e., "count" must be greater than or equal to 0.
// Postcondition: if data array is not empty, delete the most recently stored (rightmost) value in the container by decrementing
// count by 1 (logical deletion)
// if the container is empty display a message "Container is empty; program is terminated!"
// and then terminate the program with exit(1) system call.
void undelete(int & value);
// Postcondition: the most recently removed value is restored or undeleted
bool isEmpty();
// Postcondition: return true is container is empty; return false otherwise
bool isFull();
// Postcondition: return true is container is full; return false otherwise
void sort();
// Precondition: "data" array must not be empty and there must be at least two values stored in it.
// Postcondition: sort all values stored in the container in ascending order
void display();
// Postcondition: displays all values currently stored in the contianer
private:
conststaticint CAPACITY = 10; // specifies storage capacity of a container object, the container
int data[CAPACITY]; // stores inserted integer values
int count; // (count + 1) indicates how many values have currently stored in data array
};
#endif
Errors usually contain more information, so it would be better if next time you paste the whole error message.
This is the error I got from your program -
Error 3 error C2664: 'void container::undelete(int &)' : cannot convert argument 1 from 'int' to 'int &'
Same for the remove function. I fixed it by either not calling the function by reference. Or just place the random number in a variable.
1 2
int x = rand() % 99 + 1;
c.remove(x);
Edit:
A recommendation is to not use rand() because it's harmful and bad. You should instead learn about the random header file. <random> - http://www.cplusplus.com/reference/random/
Your undelete function is essentially identical to your insert function.
main.cpp lines 35-37 insert three new random values into the container. Those lines do not restore three previous values at stated in the post condition.