Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 3 Modify Program 2... Implement the LIST using pointers to store data for an unlimited number of integer values. (See review lectures for creating

Program 3 Modify Program 2... Implement the LIST using pointers to store data for an unlimited number of integer values. (See review lectures for creating a LIST using pointers) Write and Run the code... Write your conclusion why it is better or worse the first program, and second program

#include

using namespace std;

class LIST{

private:

int v[11];

int count;

public:

LIST() {

for(int i = 0; i < 11; i++)

v[i] = -1;

count = 0;

}

bool isFull() {

if (count == 11){

return true;

}

else{

return false;

}

}

bool add1(int inVar) {

if (!isFull()) {

count++; // add 1 count

for(int i = 0; i < 11; i++){

if(v[i] == -1){

v[i] = inVar;

return true;

}

}

}

return false;

}

bool isEmpty() {

if (count == 0){

return true;

}

else{

return false;

}

}

bool found(int inVal) {

for(int i = 0; i < 11; i++){

if(v[i] == inVal){

return true;

}

}

return false;

}

bool delete1(int inVal) {

for(int i = 0; i < 11; i++){

if(v[i] == inVal){

v[i] = -1;

return true;

}

}

return false;

}

void listAll() {

cout << "List: ";

for(int i = 0; i < 11; i++){

if(v[i] != -1)

cout << v[i] << " ";

}

cout << endl;

}

void makeEmpty() {

for(int i = 0; i < 11; i++){

v[i] = -1;

}

}

};

int main() {

cout << "Program #1" << endl;

LIST L1;

L1.add1(42);

L1.add1(7);

L1.add1(104);

L1.listAll();

L1.delete1(7);

L1.listAll();

if (L1.found(7)) {

cout << "7 found" << endl;

}

else {

cout << "7 not found" << endl;

}

if (L1.found(42)) {

cout << "42 found" << endl;

} else {

cout << "42 not found" << endl;

}

L1.listAll();

L1.makeEmpty();

L1.listAll();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

What's your favorite zoo animal?

Answered: 1 week ago

Question

What is goodman group (GMG) discounted cash flow analysis?

Answered: 1 week ago

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago