Question
Program 1 ( Example 1) Example of Implementing an ADT LIST class with individual variables. What are the Pros and Cons with implementing with the
Program 1 ( Example 1) Example of Implementing an ADT LIST class with individual variables. What are the Pros and Cons with implementing with the LIST with individual variables ? Lets assume that you have at most eleven(11) integer variable of data you need to store in a list, whose value would be greater or equal to zero. Run the code below and write about the PROS and CONS of the code.
#include#include using namespace std;
class LISTofIntVars { private: int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;
int count; public:
// constructor Initialize ( set first value ) for the variables.
LISTofIntVars() { v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v10 = v11 = -1; count = 0;}
// check if space left to use
bool isFull() { if (count ==11)
{ return true; } else
{ return false; } }
// called individually and also by the add method
bool add1( int inVar ) { if (!isFull()) {
count++; // add 1 count if (v1 == -1) { v1 = inVar; } else if (v2 == -1) { v2 = inVar; return true; } else if (v3 == -1) { v3 = inVar; return true; } else if (v4 == -1) { v4 = inVar; return true; } else if (v5 == -1) { v5 = inVar; return true; } else if (v6 == -1) { v6 = inVar; return true; } else if (v7 == -1) { v7 = inVar; return true; } else if (v8 == -1) { v8 = inVar; return true; } else if (v9 == -1) { v9 = inVar; return true; } else if (v10 == -1) { v10 = inVar; return true; }
else if (v11 == -1) { v11 = inVar; return true; } else return false;
}
}
return false;
}
// check if any data in storage
bool isEmpty() { if (count == 0)
{ return true; } else
{ return false; } } // called individually and also by the add method
// check if item in list bool found(int inVal) { // called individually and also by the delete method
if (!isEmpty()) { if (v1 == inVal) { return true;}
else if (v2 == inVal) { return true;} else if (v3 == inVal) { return true;} else if (v4 == inVal) { return true;} else if (v5 == inVal) { return true;} else if (v6 == inVal) { return true;} else if (v7 == inVal) { return true;} else if (v8 == inVal) { return true;} else if (v9 == inVal) { return true;} else if (v10 == inVal) { return true;} else if (v11 == inVal) { return true;} else {return false; }
} return false;
bool delete1 ( int inVal ) { if (v1 == inVal) { v1 = -1; return true; } else if (v2 == inVal) { v2 = -1; return true; } else if (v3 == inVal) { v3 = -1; return true; } else if (v4 == inVal) { v4 = -1; return true; } else if (v5 == inVal) { v5 = -1; return true; } else if (v6 == inVal) { v6 = -1; return true; } else if (v7 == inVal) { v7 = -1; return true; }
else if (v8 == inVal) { v8 = -1; return true; } else if (v9 == inVal) { v9 = -1; return true; }
else if (v10 == inVal) else if (v11 == inVal) else { return false; } return false;
}
{ v10 = -1; return true; } { v11 = -1; return true; }
void listAll() { if (v1 != -1) cout << v1 << endl; if (v2 != -1) cout << v2 << endl; if (v3 != -1) cout << v3 << endl; if (v4 != -1) cout << v4 << endl; if (v5 != -1) cout << v5 << endl; if (v6 != -1) cout << v6 << endl; if (v7 != -1) cout << v7 << endl; if (v8 != -1) cout << v8 << endl; if (v9 != -1) cout << v9 << endl; if (v10 != -1) cout << v10 << endl; if (v11 != -1) cout << v11 << endl;
}
// others
}; int main() {
}
cout << " Program #1 By Your name" << endl; // Test all access methods... LISTofIntVars 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(); makeEmpty function is Not yet coded << You Write/add code
L1.listAll(); system("pause"); // Not needed on the MAC return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started