You are on page 1of 9

#include <iostream>

using namespace std;


int x=1;
struct CustomerAccountData{
int customerID;
string name;
string dateOfBirth;
string city;
string PhoneNumber;
double currentMoney;
};

struct CustomerAccount {
//stored data
CustomerAccountData customerData;

//a referance that refer to next node


CustomerAccount* next;
CustomerAccount* prev;

};

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;
}

void deleteCustomerAccountWithID(int customerID)


{
CustomerAccount* nodeBefore = head;
if (nodeBefore->customerData.customerID == customerID)
{
deleteHeadNode();}
else
{
while (nodeBefore->next->customerData.customerID != customerID)
{
nodeBefore = nodeBefore->next;
if (nodeBefore->next == NULL)
{
break;
}
}
if (nodeBefore->next == NULL)
{
cout << "Node not found" << endl;
}
else
{
deleteCustomerAccountNode(nodeBefore);
}
}
}
void delete_model(int customerID)
{
CustomerAccount* nodeBefore = head;
if (nodeBefore->customerData.customerID == customerID)
{
deleteHeadNode();}
else
{
while (nodeBefore->next->customerData.customerID != customerID)
{
nodeBefore = nodeBefore->next;
if (nodeBefore->next == NULL)
{
break;
}
}
if (nodeBefore->next == NULL)
{
cout << "Node not found" << endl;
}
else
{
deleteCustomerAccountNode(nodeBefore);
}
}
}
//3)transactions
void deposit(CustomerAccount* customerAccount)
{
double depositMoney;
cout << "Please Enter the anount of money you want deposit at your account: \n";
cin >> depositMoney;
customerAccount->customerData.currentMoney += depositMoney;}
void withdraw(CustomerAccount* customerAccount) {
double withdrawMoney;
cout << "Please Enter the anount of money you want withdraw from your account: \n";
cin >> withdrawMoney;
if (customerAccount->customerData.currentMoney>= withdrawMoney)
{
customerAccount->customerData.currentMoney -= withdrawMoney;
}
else {
cout << "Sorry, you don't have enough money. \n";
}
}
void transact(int customerID , int transactionType)
{
CustomerAccount* customerAccount = head;
while (customerAccount != NULL) {
if (customerAccount->customerData.customerID == customerID)
{
if (transactionType == 1)
{
deposit(customerAccount);
}
else if (transactionType == 2)
{
withdraw(customerAccount);
}
break;
}
customerAccount = customerAccount->next;
}
if (customerAccount == NULL && customerAccount->customerData.customerID !=
customerID)
{cout << "The customer ID doesn't exist \n\n";
// customerAccount==null
}
}
};
int main()
{
customerAccountsLinkedlist customersList;
int choice;
CustomerAccountData customerData;
while (true) {
cout << "*********************************** Welcome in Customer Account Bank
ManagementSystem . ********************************\n\n\n\n\n";
cout << "1) Create new account. \n2) Update information of existing account. \n3)
fortransactions. \n4) check the details of existing account.\n5) Remove existing
account. \n6) Viewcustomer's list. \n7)Exit \n\n\n\n\n";
cout << "Enter your choice: \n";
cin >> choice;
if (choice == 1) {
system("Cls");
int x,n;
cout <<"1 insert_first.\n 2 insert_list\n 3 insert_moddil";
cout << "Enter your choice: \n";
cin>>x;
switch(x){
case 1 :
cout << " customer ID: "<<x<<endl;
customerData.customerID=x;
x++;
cout << "Enter customer name: ";
cin >> customerData.name;
cout << "Enter customer date of birth: ";
cin >> customerData.dateOfBirth;
cout << "Enter customer city: ";
cin >> customerData.city;
cout << "Enter customer phone number: ";
cin >> customerData.PhoneNumber;
cout << "Enter customer current money: ";
cin >> customerData.currentMoney;
customersList.insert_first(customerData);
break;
case 2 :
cout << "customer ID: "<<x<<endl;
customerData.customerID=x;
x++;
cout << "Enter customer name: ";
cin >> customerData.name;
cout << "Enter customer date of birth: ";
cin >> customerData.dateOfBirth;
cout << "Enter customer city: ";
cin >> customerData.city;
cout << "Enter customer phone number: ";
cin >> customerData.PhoneNumber;
cout << "Enter customer current money: ";
cin >> customerData.currentMoney;
customersList.insert_last(customerData);
break;
case 3 :

cout << "customer ID: "<<x<<endl;


customerData.customerID=x;
x++;
cout << "Enter customer name: ";
cin >> customerData.name;
cout << "Enter customer date of birth: ";
cin >> customerData.dateOfBirth;
cout << "Enter customer city: ";
cin >> customerData.city;
cout << "Enter customer phone number: ";
cin >> customerData.PhoneNumber;
cout << "Enter customer current money: ";
cin >> customerData.currentMoney;
cout<<"Enter number of nodes to create\n";
cin>>n;
customersList.inser_moddile(customerData,n);
break;
}
system("Cls");
}
else if (choice == 2) {
system("Cls");
cout << "Please Enter the ID of the customer account you want to modify: \n";
cin >> customerData.customerID;
cout << "Enter new customer name: ";
cin >> customerData.name;
cout << "Enter new customer date of birth: ";
cin >> customerData.dateOfBirth;
cout << "Enter new customer city: ";
cin >> customerData.city;
cout << "Enter new customer phone number: ";
cin >> customerData.PhoneNumber;
cout << "Enter new customer current money: ";
cin >> customerData.currentMoney;
customersList.updateCustomerAccount(customerData);
}
else if (choice == 3) {
system("Cls");
int customerID,transactionType;
cout << "Please Enter Your Customer ID: \n";
cin >> customerID;
cout << "Please Choose Your Transaction type:\n1)deposit.\n2)withdraw\n\n";
cin >> transactionType;
customersList.transact(customerID, transactionType);}
else if (choice == 4) {
system("Cls");
int customerID;
cout << "Please Enter the ID of the customer account you want to check: \n";
cin >> customerID;
CustomerAccount* head = customersList.getHead();
customersList.select(head, customerID);
}else if (choice == 5) {
int x,n;
cout <<"1 deletefirst 2 delete_last \n 3 delete_middle \n 4 delete_id ";
cout << "Enter your choice: \n";
cin>>x;
switch(x){

case 1 :

customersList.deletefirst();

break;

case 2 :
customersList.delete_Last();
break;
case 3 :

cout<<"plase enter the id_node";


cin>>n;
customersList. delete_model(n);

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");
}

You might also like