Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++... please show that it works //Mylist class is below #include #include using namespace std; class MyList { private: static const int MAX=10; int

In C++... please show that it works

image text in transcribed

//Mylist class is below

#include

#include

using namespace std;

class MyList

{

private:

static const int MAX=10;

int a[MAX];

int csz;

int cap;

public:

MyList();

MyList(int);

~MyList();

bool add(int);

bool remove(int);

bool is_present(int) const;

void display() const;

};

MyList::MyList()

{

cap=MAX;

csz=0;

}

MyList::MyList(int ucap)

{

if (ucap>MAX || ucap

cap=MAX;

else

cap=ucap;

csz=0;

}

MyList::~MyList()

{

cout

cout

}

bool MyList::add(int val)

{

if (csz==cap)

return false;

a[csz]=val;

csz++;

return true;

}

bool MyList::remove(int val)

{

if (!is_present(val))

return false;

int found=0;

for (int i=0;i

if (a[i]==val)

found=i;

a[found]=a[csz-1];

csz--;

}

bool MyList::is_present(int val) const

{

for (int i=0;i

if (a[i]==val)

return true;

return false;

}

void MyList::display() const

{

cout

cout

cout

for (int i=0;i

cout

cout

}

int main()

{

MyList l1;

MyList l2(5);

for (int i=0;i

{

l1.add(i);

l2.add(i);

}

l1.display();

l2.display();

for (int i=0;i

{

l1.remove(i);

l2.remove(i);

}

cout

l1.display();

l2.display();

}

Problem 1 (10 points) Download the MyList class from the Oct 26 lecture. Update the class to support the following features: (a) (1 point) An "erase" operation that deletes all elements in the list and makes it empty. (b) (2 points) An "is_duplicate" operation that checks if the input value is duplicate (meaning there are multiple occurrences of the input value in the list). The function should return O if it is not a duplicate; otherwise value in the list. c) ( point) A "remove alr operation that removes all ocurrences of a particular value (remember that our list can contain duplicates). (d) (1 point) An "is full" function that returns true if the list is full; false otherwise (e) (1 point) An "is_empty" function that returns true if the list is empty false otherwise. (f) (2 points) A copy constructor (g) (2 points) An overloaded assignment operator Demonstrate that your code works using a main function

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago