Linked List Class formal and develop an actual nked s program which uses your ow
ID: 3744509 • Letter: L
Question
Linked List Class formal and develop an actual nked s program which uses your own Linkealist class unction net discussed much in class 1, Implement a class called Customer. This class should include the folowing Print the dana within he lnked ZipCode (private- integer) private floating Point) value if validation fails within each numeric mutator Make sure the les Find the customer with the speciftied 1D andeurn tu was found, 10. Bool deletelt (int ID) pointer. In this new class's.cpp ile, implement all of these public functions: head is a private member of your class. class. Your main) function wil NEVER access these directly, so, they should be private 3. int size)Explanation / Answer
please give thumbs up, thanks
.h file :
#ifndef LinkedList_h
#define LinkedList_h
#include<string>
using namespace std;
class Customer
{
private:
int ID;
string Name;
string Address;
string City;
string State;
int ZipCode;
double AccountBalance;
public:
Customer()
{
this->ID=0;
this->Name="";
this->Address="";
this->State="";
this->ZipCode=0;
this->AccountBalance=0.0;
}
bool setID(int data)
{
if(data<=0)
return false;
else{
this->ID=data;
return true;
}
}
void setName(string data)
{
this->Name=data;
}
void setAddress(string data)
{
this->Address=data;
}
void setState(string data)
{
this->State=data;
}
void setBalance(double data)
{
this->AccountBalance=data;
}
bool setZipCode(int data)
{
if(data<=0)
return false;
else{
this->ZipCode=data;
return true;
}
}
int getID()
{
return this->ID;
}
string getName()
{
return this->Name;
}
string getAddress()
{
return this->Address;
}
string getState()
{
return this->State;
}
double getBalance()
{
return this->AccountBalance;
}
int getZipCode()
{
return this->ZipCode;
}
};
struct node
{
Customer data;
node *next;
};
class linked_list
{
private:
node *head;
public:
linked_list();
void push_back(Customer *C);
void push_front(Customer *C);
int size();
void delete_list();
void print_list();
Customer *pop_front();
Customer * pop_back();
Customer *find(int ID);
bool exist(int ID);
bool deleteit(int ID);
};
#endif
.cpp file :
#include <iostream>
#include"LinkedList.h"
using namespace std;
linked_list::linked_list()
{
head = NULL;
}
void linked_list::push_back(Customer *C)
{
node *temp,*s;
temp=(node *)new node();
temp->data=*C;
temp->next=NULL;
if(head == NULL)
{
head = temp;
}
else
{
s=head;
while(s->next!=NULL)
{
s=s->next;
}
temp->next=NULL;
s->next=temp;
}
}
void linked_list:: push_front(Customer *C)
{
node *temp, *p;
temp=(node *)new node();
temp->data=*C;
temp->next=NULL;
if(head==NULL)
{
head=temp;
head->next=NULL;
}
else
{
p=head;
head=temp;
head->next=p;
}
}
int linked_list::size()
{
node *temp=head;
int count=0;
while(temp!=NULL)
{
count++;
temp=temp->next;
}
return count;
}
void linked_list:: delete_list()
{
node * temp,*c;
c=head;
if(head!=NULL)
{
while(c!=NULL)
{
temp=c;
c=c->next;
temp->next=NULL;
delete temp;
}
}
}
void linked_list::print_list()
{
node *temp=head;
while(temp!=NULL)
{
cout<<"ID : "<<temp->data.getID()<<endl;
cout<<"NAME : "<<temp->data.getName()<<endl;
cout<<"Address : "<<temp->data.getAddress()<<endl;
cout<<"State : "<<temp->data.getState()<<endl;
cout<<"ZipCode : "<<temp->data.getZipCode()<<endl;
cout<<"Account Balnce : "<<temp->data.getBalance()<<endl;
cout<<endl;
temp=temp->next;
}
}
Customer * linked_list::pop_front()
{
if(head==NULL)
return NULL;
else
{
node* temp;
temp=head;
head=head->next;
temp->next=NULL;
return &temp->data;
}
}
Customer * linked_list:: pop_back()
{
node *temp,*s;
if(head == NULL)
{
return NULL;
}
else
{
s=head;
while(s->next!=NULL)
{
temp=s;
s=s->next;
}
temp->next=NULL;
return &s->data;
}
}
Customer * linked_list::find(int ID)
{
node *s;
if(head == NULL)
{
return NULL;
}
else
{
s=head;
while(s!=NULL)
{
if(s->data.getID()==ID)
return &s->data;
s=s->next;
}
}
}
bool linked_list :: exist(int ID)
{
node *s;
if(head == NULL)
{
return false;
}
else
{
s=head;
while(s!=NULL)
{
if(s->data.getID()==ID)
return true;
s=s->next;
}
}
return false;
}
bool linked_list::deleteit(int ID)
{
node * s=head;
if(this->exist(ID))
{
if(head->data.getID()==ID)
{
head=head->next;
}
else
{
while(s->next!=NULL)
{
if(s->data.getID()==ID)
{
s->next=(s->next)->next;
break;
}
}
}
return true;
}
else
{
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.