I'm not sure how you code the copy constructor and "=" operator I don't know if using info[MAXITEM]=x.info[MAXITEM];
is wrong I'm still new to codding I just learned copy constructor and "=" operator so I'm not sure how to implement here.
#include <iostream>
#include <string>
using namespace std;
#define MAXITEM 100
typedef float itemType;
class List
{
private:
int length=0;
itemType info[MAXITEM];
public:
List()
{
info[MAXITEM];
}
List(const List &x)
{
cout<<"copy exec";//testing if copy constructor is being exec
info[MAXITEM]=x.info[MAXITEM];
}
List & operator =(const List &x)
{
cout<<"= exec";//testing if = operator is being exec
info[MAXITEM]=x.info[MAXITEM];
return *this;
}
~List()
{
}
bool boolisthere(itemType item)const
{
for(int i=0;i<length;i++)
{
if(info[i]==item)
return true;
else
return false;
}
}
void Insert(itemType item)
{
info[length]=item;
length++;
}
void Delete(itemType item)
{
for(int i=0;i<length;i++)
{
if(info[i]==item)
{
info[i]=info[length-1];
length--;
}
}
}
void Print()
{
for(int i=0;i<length;i++)
{
cout <<info[i]<<" ";
}
cout<<endl;
}
int Length()
{
return length;
}
};
int main()
{
List l;
l.Insert(3.5);
l.Insert(2.1);
l.Insert(6.8);
l.Insert(4.3);
l.Insert(7.5);
l.Insert(0.2);
l.Length();
l.Print();
l.Delete(4.3);
l.Print();
List l2(l);//copyconstructor call
l2.Print();
List l3;
l3=l; //= operator call
l3.Print();
}