Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help completing this problem! Please can someone help me! In class, we discussed an Integer Linked List, which means the node of the

I need help completing this problem! Please can someone help me!

In class, we discussed an Integer Linked List, which means the node of the linked list

contains an integer value (and a pointer field, of course). Understand, modify, and test

tthe code Provided based on the following requirements.

You should define a new linked list. The node of the new linked list should contain

three regular data fields (account_number, which is an integer; name, which is a

string; balance, which is a double number) and a pointer (next, used to link to

another node).

Modify the definition of class node so that it reflects the above structure.

Modify the constructor of class node so that it accepts three parameters (account

number, name, and balance).

Change the class name of the linked list from Integer_List to Account_List.

Modify (if needed) the constructor of class Account_List so that it will create an

empty liked list. The signature of the constructor is

Account_List();

Modify (if needed) the destructor of class Account_List so that it will de-allocate

space of the remaining nodes in the list. The signature of the constructor is

~Account_List();

Modify the method insert_to_head in class Account_List so that it has the

following signature. This method should create an instance of node using the given

parameters and insert it to the head of the linked list.

void insert_to_head(int v, string n, double b);

Modify method list_all()in class Account_List so that it can display all the

information (account number, name, and balance ) of every account (node) in the

linked list.

Modify the method search in class Account_List. It will search account (node) in

the linked list by name. If it finds the name in any account, return true, else, return

false. The signature of this method is

bool search(string name)

You might need to include library at the beginning of the program.

Function string.compare(string) can be used to compare the values of two string

objects.

If test your program using the following code

int main()

{

Account_List List;

List.insert_to_head(2002, "Janet Smith", 100.99);

List.insert_to_head(1001, "Alex Bush", 99.88);

List.insert_to_head(3003, "John Rosa", 5.55);

List.list_all();

if(List.search("Alex Bush")==true) cout << "Found Alex ";

else cout << "Cound not find Alex ";

if(List.search("Bush Alex")==true) cout << "Found Bush ";

else cout << "Could not find Bush ";

return 1;

}

The result should be:

3003 John Rosa 5.55

1001 Alex Bush 99.88

2002 Janet Smith 100.99

Found Alex

Could not find Bush

Submission: Print your final programs and bring hard copies to class.

#include

using namespace std;

class node

{

public:

int value;

node * next;

public:

node(int value);

};

node::node(int value)

{

this->value = value;

this->next = NULL;

}

class Integer_List

{

private:

node * head;

public:

Integer_List();

~Integer_List();

void insert_to_head(int n);

void list_all();

bool search(int n);

};

Integer_List::Integer_List()

{

head = NULL;

}

Integer_List::~Integer_List()

{

while(head != NULL)

{

node * temp = head;

head = head->next;

delete temp;

}

}

void Integer_List::insert_to_head(int n)

{

node * temp = new node(n);

temp->next = head;

head = temp;

}

void Integer_List::list_all()

{

node * temp= head;

while(temp!=NULL)

{

cout << temp->value << endl;

temp = temp->next;

}

}

bool Integer_List::search(int n)

{

node * temp= head;

while(temp!=NULL)

{

if(temp->value==n) return true;

else temp = temp->next;

}

return false;

}

int main()

{

Integer_List List;

List.insert_to_head(1);

List.insert_to_head(22);

List.insert_to_head(3);

List.insert_to_head(11);

List.insert_to_head(32);

List.insert_to_head(13);

List.insert_to_head(2);

List.list_all();

if(List.search(20)==true) cout << "found 20 ";

else cout << "Could not find 20 ";

if(List.search(13)==true) cout << "Found 13 ";

else cout << "could not find 13 ";

return 1;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions