Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:47:04+00:00 2026-06-15T02:47:04+00:00

I’m trying to implement a template linked list into a project I’m working on

  • 0

I’m trying to implement a template linked list into a project I’m working on with a lot of classes. It works a bit like a map or set where there is key data and value data. I created it and tested it in a seperate project using ints and string values, and all the functions work inside it work, I even got it to work with serialization using the BOOST libraries.

This is the entire class file for my list:

#ifndef LINKED_LIST_H
#define LINKED_LIST_H

#include <boost\serialization\access.hpp>

#include <iostream>
#include <string>

using namespace std;

template<typename Tkey, typename Tvalue>
class Node
{
public:
Tkey keyData;
Tvalue valueData;
Node * next;
Node()
{   
    next = NULL;
}
Node(Tkey x, Tvalue y)
{
    keyData = x;
    valueData = y;
    next = NULL;
}
Node(Tkey x, Tvalue y, Node * z)
{
    keyData = x;
    valueData = y;
    next = z;
}

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
    ar & keyData;
    ar & valueData;
    ar & next;
}
};

template<typename Tkey, typename Tvalue>
class LinkedList
{
Node<Tkey, Tvalue> *head;
int count;
public:
LinkedList()
{
    head = NULL;
    count = 0;
}
~LinkedList()
{
    Clear();
}

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
    ar & head;
    ar & count;
}

int Size()
{
    return count;
}

bool Empty()
{
    return (count == 0);
}

bool Add(Tkey key, Tvalue value)
{
    Node<Tkey, Tvalue> *p;
    if(head == NULL)
    {
        head = new Node<Tkey, Tvalue> (key, value, NULL);
        count++;
        return true;
    }
    else
    {
        p = head;
        while(p->next !=NULL)
            p=p->next;
        p->next = new Node<Tkey, Tvalue> (key, value, NULL);
        count++;
        return true;
    }
    return false;
}

bool Remove(Tkey key)
{
    Node<Tkey, Tvalue> *p;

    if (head->keyData == key)
    {
        head = head->next;
        return true;
    }

    p=head;

    while (p->next->keyData != key && p->next->next != NULL)
    {
        p = p->next;
    }

    if (p->next->keyData == key && p->next != NULL)
    {
        Node<Tkey, Tvalue> *temp;
        temp = p->next;
        p->next = temp->next;
        count--;
        delete temp;
        return true;
    }

    return false;
}

Tvalue Get(Tkey key)
{
    Node<Tkey, Tvalue> *p;

    p = head;

    while (p->next != NULL)
    {
        if (p->keyData == key)
        {
            return p->valueData;
        }
        p = p->next;
    }

    return NULL;
}

Tvalue Find(int i)
{
    int selection = 0;

    Node<Tkey, Tvalue> *p;

    p = head;

    while (selection != i && p->next != NULL)
    {
        p = p->next;
        selection++;
    }

    if (p->next == NULL)
    {
        return 0;
    }

    return p->valueData;
}

Tkey Exists (Tvalue value)
{
    Node<Tkey, Tvalue> *p;

    p = head;

    while (p->next != NULL)
    {
        if (p->valueData == value)
        {
            return p->keyData;
        }
    }

    return NULL;
}

void Clear()
{
    Node<Tkey,Tvalue> * temp;
    while (head != 0)
    {
        temp = head;
        head = head->next;
        count--;
        delete temp;
    }
}

void Print(Tkey key)
{
    Node<Tkey, Tvalue> * p;
    p = head;
    while(p->keyData != key && p->next != NULL)
    {
        p = p->next;
    }

    if (p->keyData == key && p->next != NULL)
    {
        cout << p->keyData << " " << p->valueData << endl;
    }
    else
    {
        cout << "Data not found" << endl;
    }
}

void PrintAll()
{
    Node<Tkey, Tvalue> * p;
    p = head;
    while(p != NULL)
    {
        cout << p->keyData << " " << p->valueData << "\n";
        p = p->next;
    }
}
};
#endif

To test it out in my project, I created a Linked List variable with an int and one of my classes, then tried to add and get the value data to modify a value.

LinkedList<int,Customer *> customerList;
customerList.Add(1, new Customer("Jack Smith", "1 Adelade Road", "5678", "Male", 4,8,1999));
customerList.Get(1)->AddAccount("9081", new JuniorCurrentAccount("100126764", 50, 25,12,2010));

However when I run it I get an unhandled exception at the Add method pointing at
if(head == NULL)

The exception says “Access violation reading location”

So far I have tried changing the NULLs to 0s when the list checks for Nodes but that didn’t stop the exception, I have also tried including the headers for the class files but that caused a lot of errors that involving accessing variables within those classes.

I believe something is wrong within the class itself, but I cannot find what is causing it. As I said, this class works fine with basic data types (ints, strings ect) but classes is what is causing the errors. Any help would be greatful!

EDIT: Here is the code for the Customer Class .cpp file
#include “Customer.h”
#include “Account.h”
#include “CorportateSavings.h”
#include “CurrentAccount.h”
#include “JuniorCurrentAccount.h”
#include “StudentSavings.h”
#include “Mortgage.h”
#include “BuyToLetMortgage.h”
#include “DiscountMortgage.h”
#include “FixedRateMortgage.h”
#include
#include
#include
#include
#include

using namespace std;

Customer::Customer(string Name, string Address, string TelephoneNo, string Gender, int DOBday, int DOBmonth, int DOByear) : name(Name), address(Address), telephoneNo(TelephoneNo), gender(Gender), DOB(DOBday,DOBmonth,DOByear)
{
parent = 0;
}

Customer::Customer(string Name, string Address, string TelephoneNo, string Gender, int DOBday, int DOBmonth, int DOByear, Customer *c) : name(Name), address(Address), telephoneNo(TelephoneNo), gender(Gender), DOB(DOBday,DOBmonth,DOByear)
{
parent = c;
}

Customer::~Customer(void)
{

}

void Customer::printDetails()
{
//Prints out details of customer
cout << "Name       : " << name << endl;
cout << "Address        : " << address << endl;
cout << "Telephone No   : " << telephoneNo << endl;
cout << "Gender     : " << gender << endl;
cout << "Date of Birth  : ";
printStringDOB();
//If customer has a registered parent/guardian
if (parent != 0)
    cout << "Parent/Guardian Name: " << parent->getName() << endl;

cout << endl;
}

string Customer::getName()
{
return name;
}

void Customer::setName(string Name)
{
name = Name;
}

string Customer::getAddress()
{
return address;
}

void Customer::setAddress(string Address)
{
address = Address;
}

string Customer::getTelephoneNo()
{
return telephoneNo;
}

void Customer::setTelephoneNo(string TelephoneNo)
{
telephoneNo = TelephoneNo;
}

string Customer::getGender()
{
return gender;
}

void Customer::setGender(string Gender)
{
gender = Gender;
}

void Customer::printStringDOB()
{
DOB.printString(); 
}

double Customer::getDOB()
{
return DOB.juldays();
}

void Customer::setDOB(int day, int month, int year)
{
DOB.setDay(day);
DOB.setMonth(month);
    DOB.setYear(year);
}

int Customer::getAge(int Day, int Month, int Year)
{
return DOB.DifferenceYear(Day, Month, Year);
}

void Customer::setParent(Customer * c)
{
parent = c;
}

Customer * Customer::getParent()
{
if (parent = 0)
{
    return NULL;
}
else
{
    return parent;
}
}

void Customer::AccountManager()
{
int choice = AccountManagerChooser();
cout << endl;

while (choice != 9)
{
    switch (choice)
    {
    case 1:
        //Create a bank acount
        CreateAccountManager();
        choice = AccountManagerChooser();
        break;
    case 2:
        {
            //Use a bank account
            string pin;

            cout << "Enter PIN: ";
            cin >> pin;

            UseAccount(pin);
            choice = AccountManagerChooser();
            break;
        }
    case 3:
        {
            //Remove a bank account
            char yn;
            cout << "Enter PIN: ";
            string pin;
            cin >> pin;
            if (accountList.Get(pin) != NULL)
            {
                cout << "Are you sure? (Y/N) ";
                cin >> yn;
                if (yn == 'y' || yn == 'Y')
                {
                    accountList.Remove(pin);
                    cout << "Account Removed Successfully" << endl;
                }
            }
            else
            {
                cout << "Invalid PIN or Account does not exist" << endl;
            }
            choice = AccountManagerChooser();
            break;
        }
    case 4:
        //Print Customer Details
        printDetails();
        choice = 0;
        break;
    case 5:
        {
            //Change Customer Details
            int detailChange = 0;

            while (detailChange != -1)
            {
                cout << "1 Name" << endl;
                cout << "2 Address" << endl;
                cout << "3 Telephone No" << endl;
                cout << "4 Gender" << endl;
                cout << "5 Date of Birth" << endl;
                cout << "Which piece of detail do you want to change? ";
                cin >> detailChange;
                string str;
                getline(cin, str);
                cout << endl;

                switch (detailChange)
                {
                case 1:
                    {
                        string newName;
                        cout << "Enter new name: ";
                        getline(cin, newName);
                        setName(newName);
                        break;
                    }

                case 2:
                    {
                        string newAddress;
                        cout << "Enter new Address: ";
                        getline (cin,newAddress);
                        setAddress(newAddress);
                        break;
                    }
                case 3:
                    {
                        string newTelephone;
                        cout << "Enter new Telephone Number: ";
                        getline (cin,newTelephone);
                        setTelephoneNo(newTelephone);
                        break;
                    }
                case 4:
                    {
                        string newGender;
                        cout << "Enter Gender" << endl;
                        getline (cin,newGender);
                        gender = newGender;
                        break;
                    }
                case 5:
                    int newDay = 0;
                    int newMonth = 0;
                    int newYear = 0;
                    cout << "Enter Day: ";
                    cin >> newDay;
                    cout << "Enter Month: ";
                    cin >> newMonth;
                    cout << "Enter Year: ";
                    cin >> newYear;

                    setDOB(newDay,newMonth,newYear);
                    break;
                }

                char yn = 0;
                cout << "Would you like to change anything else? (Y/N) ";
                cin >> yn;

                if (yn == 'Y' || yn == 'y')
                {
                    detailChange = 0;
                    cout << endl;
                }
                else
                {
                    detailChange = -1;
                    cout << endl;
                }
            }
            choice = AccountManagerChooser();
            cout << endl;
        }
        break;
    case 6:
        //Create a mortgage
        {
            time_t t = time(0);
            struct tm * now = localtime( & t );

            CreateMortgageManager();

            choice = AccountManagerChooser();
            cout << endl;
        }
        break;

    case 7:
        //Use a mortgage
        {
            string str;
            string pin;
            getline(cin,str);
            cout << "Enter PIN: ";
            getline(cin,pin);
            UseMortgage(pin);
            choice = AccountManagerChooser();
            cout << endl;
        }
        break;

    case 8:
        //Remove a mortgage
        {
            string str;
            string pin;
            getline(cin,str);
            cout << "Enter PIN: ";
            getline(cin,pin);
            RemoveMortgage(pin);
            choice = AccountManagerChooser();
            cout << endl;
        }
        break;
    case 9:
        break;
    default:
        cout << endl;
        choice = AccountManagerChooser();
        break;
    }

    if (choice == 9)
    {
        cout << "Thank you for your time!\n\n" << endl;
    }
    else if (choice == 0)
    {
        choice = AccountManagerChooser();
    }
}
}

int Customer::AccountManagerChooser()
{
cout << "What would you like to do?" << endl;
cout << "1: Create a new account" << endl;
cout << "2: Use an account" << endl;
cout << "3: Close an account" << endl;
cout << "4: Show Personal Details" << endl;
cout << "5: Update Personal Details" << endl;
cout << "6: Create a Mortgage" << endl;
cout << "7: Use a Mortgage" << endl;
cout << "8: Remove a Mortgage" << endl;
cout << "9: Exit" << endl;
cout << "Enter Choice: ";
int choice;
cin >> choice;
cout << endl;
return choice;
}

void Customer::CreateAccountManager()
{
int choice = 0;

while (choice != -1)
{
    time_t t = time(0);
    struct tm * now = localtime( & t );

    cout << "What account do you wish to create?" << endl;
    cout << "1: Corporate Savings" << endl;
    cout << "2: Current Account" << endl;
    cout << "3: Junior Account" << endl;
    cout << "4: Student Savings Account" << endl;
    cout << "5: Cancel" << endl;
    cout << "Enter Choice: ";
    cin >> choice;
    cout << endl;

    switch (choice)
    {
    case 1:
        //Corporate Savings Account Made
        //Grabs age from current date
        if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) >= 16)
        {
            cout << "Please enter how much you wish to deposit: ";
            double initDeposit;
            cin >> initDeposit;

            cout << "Please enter a four digit number to set as the PIN: ";
            string PIN;
            cin >> PIN;

            cout << "Please enter a 9 digit number to set as the account number: ";
            string AccountNo;
            cin >> AccountNo;

            AddAccount(PIN, new CorporateSavings(AccountNo, initDeposit, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
            cout << "Corporate Savings Account Created" << endl;
            choice = -1;
        }
        else if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) < 16)
        {
            cout << "Corportate Savings Account is only available to customers over the age of 16" << endl;
        }
        break;
    case 2:
        //Current Account Made
        //Grabs age from current date
        if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) >= 16)
        {
            cout << "Please enter how much you wish to deposit: ";
            double initDeposit;
            cin >> initDeposit;

            cout << "Please enter a four digit number to set as the PIN: ";
            string PIN;
            cin >> PIN;

            cout << "Please enter a 9 digit number to set as the account number: ";
            string AccountNo;
            cin >> AccountNo;

            AddAccount(PIN, new CurrentAccount(AccountNo, initDeposit, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
            cout << "Current Account Created" << endl;
            choice = -1;
        }
        else if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) < 16)
        {
            cout << "Current Account is only available to customers over the age of 16" << endl;
        }
        break;
    case 3:
        //Junior Current Account Made
        //Grabs age from current date
        if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) <= 16)
        {
            cout << "Please enter how much you wish to deposit: ";
            double initDeposit;
            cin >> initDeposit;

            cout << "Please enter a four digit number to set as the PIN: ";
            string PIN;
            cin >> PIN;

            cout << "Please enter a 9 digit number to set as the account number: ";
            string AccountNo;
            cin >> AccountNo;

            AddAccount(PIN, new JuniorCurrentAccount(AccountNo, initDeposit, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
            cout << "Junior Account Created" << endl;
            choice = -1;
        }
        else if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) > 16)
        {
            cout << "Junior Account is only available to customers under the age of 16" << endl;
        }
        else if (parent != 0)
        {
            cout << "Customers applying for Junior Account must have an adult registered as a guardian" << endl;
        }

        break;
    case 4:
        //Student Savings Account Made
        //Grabs age from current date
        if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) >= 18)
        {
            cout << "Please enter how much you wish to deposit: ";
            double initDeposit;
            cin >> initDeposit;

            cout << "Please enter a four digit number to set as the PIN: ";
            string PIN;
            cin >> PIN;

            cout << "Please enter a 9 digit number to set as the account number: ";
            string AccountNo;
            cin >> AccountNo;

            AddAccount(PIN, new StudentSavings(AccountNo, initDeposit, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
            cout << "Student Account Created" << endl;
            choice = -1;
        }
        else if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) < 18)
        {
            cout << "Student Account is only available to customers over the age of 18" << endl;
        }
        break;
    case 5:
        choice = -1;
        break;
    default:
        cout << "Not a valid choice" << endl;
        break;
    }
}
}

void Customer::AddAccount(string PIN, Account * a)
{
accountList.Add(PIN, a);
}

bool Customer::UseAccount(string PIN)
{
if (accountList.Get(PIN) != NULL)
{
    int choice = 0;

    while (choice != -1)
    {
        cout << "What would you like to do?" << endl;
        cout << "1: Deposit Cash" << endl;
        cout << "2: Deposit Cheque" << endl;
        cout << "3: Withdraw Cash" << endl;
        cout << "4: Show Balance" << endl;
        cout << "5: Exit" << endl;
        cout << "Enter Choice: ";
        cin >> choice;
        cout << endl;

        switch (choice)
        {
        case 1:
            {
                cout << "Enter Deposit Amount: ";
                double amount;
                cin >> amount;
                if (accountList.Get(PIN)->depositAmount(amount))
                {
                    time_t t = time(0);
                    struct tm * now = localtime( & t );

                    ofstream output;
                    output.open("Transactions.txt", ios::app);
                    output << "Name: " << name << " - Account Number: " << accountList.Get(PIN)->AccountNumber() << " - Deposit: £" << 
                        amount << " - Date: " << now->tm_mday << "/" << now->tm_mon + 1 << "/" << now->tm_year + 1900 << endl;
                    output.close();
                    cout << "Amount Deposited Successfully" << endl;
                }
                else
                    cout << "Deposit Invalid" << endl;

                choice = 0;
            }
            break;
        case 2:
            {
                time_t t = time(0);
                struct tm * now = localtime( & t );

                ofstream output;
                output.open("Transactions.txt", ios::app);
                output << "Name: " << name << " - Account Number: " << accountList.Get(PIN)->AccountNumber() << " - Cheque Deposit: £" 
                    << " - Date: " << now->tm_mday << "/" << now->tm_mon + 1 << "/" << now->tm_year + 1900 << endl;
                output.close();
                cout << "Amount Deposited Successfully" << endl;
            }
            break;
        case 3:
            {
                cout << "Enter Withdraw Amount: ";
                double amount;
                cin >> amount;
                if (accountList.Get(PIN)->widthdrawAmount(amount))
                {
                    time_t t = time(0);
                    struct tm * now = localtime( & t );

                    ofstream output;
                    output.open("Transactions.txt", ios::app);
                    output << "Name: " << name << " - Account Number: " << accountList.Get(PIN)->AccountNumber() << " - Withdrawal: £" << 
                        amount << " - Date: " << now->tm_mday << "/" << now->tm_mon + 1 << "/" << now->tm_year + 1900 << endl;
                    output.close();
                    cout << "Amount Withdrawn Successfully" << endl;
                }
                else
                    cout << "Withdraw Invalid" << endl;

                choice = 0;
            }
            break;
        case 4:
            {
                time_t t = time(0);
                struct tm * now = localtime( & t );

                accountList.Get(PIN)->addInterest(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900);

                cout << "Balance: £" << accountList.Get(PIN)->Amount() << endl;

                choice = 0;
            }
            break;
        case 5:
            choice = -1;
            break;
        default:
            choice = 0;
            break;
        }

        char yn;
        cout << "Do you want to use another service? (Y/N) ";
        cin >> yn;

        if ((yn == 'y' || yn == 'Y') && choice != -1)
        {
            choice = 0;
        }
        else
        {
            choice = -1;
        }
    }

    return true;
}
return false;
}

void Customer::RemoveAccount(string PIN)
{
char choice;

cout << "Are you sure? (Y/N): ";
cin >> choice;
cout << endl;
while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
{
    cout << "Are you sure? (Y/N): ";
    cin >> choice;
    cout << endl;
}

accountList.Remove(PIN);
}

void Customer::CreateMortgageManager()
{
//Grabs age from current date
time_t t = time(0);
struct tm * now = localtime( & t );

if (getAge(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900) >= 18)
{
    int choice = 0;

    cout << "Please enter the value of your House/Apartment: ";
    double value;
    cin >> value;

    cout << "Please enter the length of the payment (years) : 1, 2 or 4" << endl;
    int length;
    cin >> length;

    cout << "Please enter the PIN number of the bank account you wish to pay installments to: ";
    string accountPIN;
    cin >> accountPIN;

    if (accountList.Get(accountPIN) == NULL)
    {
        while (accountList.Get(accountPIN) == NULL)
        {
            cout << "Account PIN not valid or Account doesn't exist\n" << endl;         
            cout << "Please enter the PIN number of the bank account you wish to pay installments to: ";
            cin >> accountPIN;
        }
    }

    while (choice != -1)
    {
        cout << "What kind of Mortgage do you wish to create?" << endl;
        cout << "1: Fixed Rate Mortgage : " << ((value*0.8)+50)/(length * 12) << " per month with 5% Interest" << endl;
        cout << "2: Discount Mortgage   : " << ((value*0.8)+80)/(length * 12) << " per month with 3.8% Interest (5% Interest after 2 years)" << endl;
        cout << "3: Buy to Let Mortgage : "  << ((value*0.8)+120)/(length * 12) << " per month with 7.35% Interest" << endl;
        cout << "4: Cancel" << endl;
        cout << "Enter Choice: ";
        cin >> choice;
        cout << endl;

        string str;
        getline(cin,str);

        switch (choice)
        {
        case 1:
            {
                cout << "Please enter a PIN, so you can access your mortgage securely: ";
                string PIN;
                getline(cin,PIN);

                AddMortgage(PIN, new FixedRateMortgage(value, 50.0, accountList.Get(accountPIN), length, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
                cout << "Fixed Rate Mortgage Created" << endl;
                choice = -1;
            }
            break;
        case 2:
            {
                cout << "Please enter a PIN, so you can access your mortgage securely: ";
                string PIN;
                getline(cin,PIN);

                AddMortgage(PIN, new DiscountMortgage(value, 45.0, accountList.Get(accountPIN), length, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
                cout << "Discount Mortgage Created" << endl;
                choice = -1;
            }
            break;
        case 3:
            {
                cout << "Please enter a PIN, so you can access your mortgage securely: ";
                string PIN;
                getline(cin,PIN);

                AddMortgage(PIN, new BuyToLetMortgage(value, 70.0, accountList.Get(accountPIN), length, now->tm_mday, now->tm_mon + 1, now->tm_year + 1900));
                cout << "Buy To Let Mortgage Created" << endl;
                choice = -1;
            }
            break;
        case 4:
            choice = -1;
            break;
        default:
            cout << "Not a valid choice" << endl;
            break;
        }
    }
}
else
{
    cout << "Mortgages are only available to customers over the age of 18" << endl;
}
}

void Customer::AddMortgage(string PIN, Mortgage * m)
{
mortgageList.Add(PIN, m);
}

void Customer::UseMortgage(string PIN)
{
if (mortgageList.Get(PIN) != NULL)
{
    int choice = 0;

    while (choice != -1)
    {
        cout << "What would you like to do?" << endl;
        cout << "1: Pay Installment" << endl;
        cout << "2: Print Payment List" << endl;
        cout << "3: Exit" << endl;
        cout << "Enter Choice: ";
        cin >> choice;
        cout << endl;

        switch (choice)
        {
        case 1:
            {
                time_t t = time(0);
                struct tm * now = localtime( & t );

                mortgageList.Get(PIN)->PayInstallment(now->tm_mday, now->tm_mon + 1, now->tm_year + 1900);

                choice = 0;
            }
            break;
        case 2:
            {
                mortgageList.Get(PIN)->PrintPaymentLog();
            }
            break;
        case 3:
            choice = -1;
            break;
        default:
            choice = 0;
            break;
        }

        char yn;
        cout << "Do you want to use another service? (Y/N) ";
        cin >> yn;

        if ((yn == 'y' || yn == 'Y') && choice != -1)
        {
            choice = 0;
        }
        else
        {
            choice = -1;
        }
    }
}
}

void Customer::RemoveMortgage(string PIN)
{
char choice;

cout << "Are you sure? (Y/N): ";
cin >> choice;
cout << endl;
while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
{
    cout << "Are you sure? (Y/N): ";
    cin >> choice;
    cout << endl;
}

mortgageList.Remove(PIN);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:47:06+00:00Added an answer on June 15, 2026 at 2:47 am

    What happens if you have a 1-element list and you call Get?

    Tvalue Get(Tkey key)
    {
        Node<Tkey, Tvalue> *p;
    
        p = head;
    
        while (p->next != NULL)
        {
            if (p->keyData == key)
            {
                return p->valueData;
            }
            p = p->next;
        }
    
        return NULL;
    }
    

    p is not NULL, but p->next is NULL, which means you’ll never get into the body of the while loop. That means you’ll return NULL, and if you try to subsequently dereference that:

    customerList.Get(1)->AddAccount("9081", new JuniorCurrentAccount("100126764", 50, 25,12,2010));
    

    …then you could get an access violation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.