Professional Documents
Culture Documents
struct CustomerAccount {
//stored data
CustomerAccountData customerData;
};
class customerAccountsLinkedlist
{
private:
CustomerAccount* head, *tail;
int count;
public:
customerAccountsLinkedlist()
{head = NULL;
tail = NULL;
}
void insert_first(CustomerAccountData b)
{
CustomerAccount* temp = new CustomerAccount;
//store data in temp
temp->customerData.name = b.name;
temp->customerData.dateOfBirth = b.dateOfBirth;
temp->customerData.city = b.city;
temp->customerData.currentMoney = b.currentMoney;
temp->customerData.PhoneNumber = b.PhoneNumber;
temp->customerData.customerID=b.customerID;
if(head==NULL)
{
head = tail = temp;
temp->next = temp->prev = NULL;
}
else
{
temp->next = head;
temp->prev = NULL;
head->prev = temp;
head = temp;
}
}
void insert_last(CustomerAccountData d)
{
CustomerAccount* temp = new CustomerAccount;
//store data in temp
temp->customerData.name = d.name;
temp->customerData.dateOfBirth = d.dateOfBirth;
temp->customerData.city = d.city;
temp->customerData.currentMoney = d.currentMoney;
temp->customerData.PhoneNumber = d.PhoneNumber;
temp->customerData.customerID=d.customerID;
temp->next = NULL;
if (head == NULL)
{
head = temp;
tail = temp;
}
else
{
tail= head;
while(tail->next!=NULL){
tail=tail->next;
}
tail->next=temp;
temp->prev=tail;
temp->next=NULL;
}
}
void inser_moddile(CustomerAccountData e,int n)
{
CustomerAccount* temp = new CustomerAccount;
temp->customerData.name = e.name;
temp->customerData.dateOfBirth = e.dateOfBirth;
temp->customerData.city = e.city;
temp->customerData.currentMoney = e.currentMoney;
temp->customerData.PhoneNumber = e.PhoneNumber;
temp->customerData.customerID=e.customerID;
temp->next = NULL;
if(head==NULL)
{
head=temp;
tail=temp;
}
else
{
tail=head;
while(tail->customerData.customerID!=n&&tail->next!=NULL)
{
tail=tail->next;
}
tail->customerData.customerID=n;
temp->next=tail->next;
tail->next->prev=temp;
tail->next=temp;
temp->prev=tail;
}
}
void updateCustomerAccount(CustomerAccountData d)
{
CustomerAccount* customerAccount = head;
while (customerAccount != NULL) {
if (customerAccount->customerData.customerID == d.customerID) {
customerAccount->customerData.name = d.name;
customerAccount->customerData.dateOfBirth
= d.dateOfBirth;
customerAccount->customerData.city
= d.city;
customerAccount->customerData.currentMoney
= d.currentMoney;
customerAccount->customerData.PhoneNumber
= d.PhoneNumber;
break;
}
customerAccount = customerAccount->next;
}
if (customerAccount == NULL && customerAccount->customerData.customerID !=
d.customerID) {
cout << "The customer ID doesn't exist \n\n";
// customerAccount==null
}
}
CustomerAccount* getHead() {
return this->head;
}
void displayCustomersAccountsList(CustomerAccount* head)
{
CustomerAccount* customerAccount = head;
while (customerAccount != NULL) {
cout << "\n\n\n";
cout << "Customer ID: " <<
customerAccount->customerData.customerID << endl;
cout <<"Customer name: " <<
customerAccount->customerData.name << endl;
cout << "Customer date of birth: " <<
customerAccount->customerData.dateOfBirth << endl;
cout << "Customer city: " <<
customerAccount->customerData.city << endl;
cout<<"Customer phone: "<<
customerAccount->customerData.PhoneNumber << endl;
cout<<"Customer current money: "<<
customerAccount->customerData.currentMoney <<
endl;
cout<<"\n\n\n";
customerAccount= customerAccount->next;
}
}
void select(CustomerAccount* head,int customerID)
{
CustomerAccount* customerAccount = head;
while (customerAccount != NULL ) {
if (customerAccount->customerData.customerID == customerID) {
cout << "\n\n\n";
cout << "Customer ID: "
<< customerAccount->customerData.customerID << endl;
cout << "Customer name: "
<< customerAccount->customerData.name << endl;
cout << "Customer date of birth: "
<< customerAccount->customerData.dateOfBirth <<
endl;
cout << "Customer city: "
<< customerAccount->customerData.city << endl;
cout << "Customer phone: "
<< customerAccount->customerData.PhoneNumber << endl;
cout << "Customer current money: "
<< customerAccount->customerData.currentMoney <<
endl;
cout << "\n\n\n";
break;
}
customerAccount = customerAccount->next;
}
if (customerAccount == NULL &&
customerAccount->customerData.customerID !=
customerID)
{
cout << "The customer ID doesn't exist \n\n";
// customerAccount==null
}
}
void deletefirst()
{
if(head==NULL){
cout<<endl<<"not,s node";
}
else{
CustomerAccount* temp;
if(head->next==NULL)
{
temp = head;
head==NULL;
delete temp;
}
else
{
head = head->next;
head->prev=NULL;
delete temp;
}
}
}
void delete_Last()
{
CustomerAccount* temp;
CustomerAccount* d;
temp=head;
while(temp->next->next!=NULL)
{
temp=temp->next;
}
d=temp->next;
temp->next=NULL;
delete d;
}
//5)delete a customer Account
void deleteCustomerAccountNode(CustomerAccount* nodeBefore)
{
CustomerAccount* temp;
temp = nodeBefore->next;
nodeBefore->next = temp->next;
delete temp;
}
void deleteHeadNode()
{
CustomerAccount* temp;
temp = head;
head = head->next;
delete temp;
}
case 1 :
customersList.deletefirst();
break;
case 2 :
customersList.delete_Last();
break;
case 3 :
break;
case 4:
int customerID;
cout << "Please Enter the ID of the customer account you want to delete: \n";
cin >> customerID;
customersList.deleteCustomerAccountWithID( customerID);
}
system("Cls");
}
else if (choice == 6) {
system("Cls");
CustomerAccount* head = customersList.getHead();
customersList.displayCustomersAccountsList(head);
}
else if (choice == 7) {
system("CLS");
cout << "EXIT \n";
break;
}
else {
cout << "Your choice is invalid, please enter a valid choice \n\n\n\n";}
}
system("pause>0");
}