Taiwo A.

asked • 04/08/22

how do i implement this? I got tis errors

to implement the print method to print out the items in the list. Each node is printed on a line with the account number, then a tab, and finally the balance. To output a tab character, use cout << "\t"; Do not output any labels. Just print the contents (payload) of the node. For instance
1114 395.67

#include "structs.h"

//This is the constructor for the ListClass object
ListClass::ListClass()
{
head = nullptr;
}//end of constructor

//This is the destructor for the ListClass object
ListClass::~ListClass()
{
NodePtrType q = head;
while (q != nullptr)
{
head = head->next;
q->next = nullptr;
delete q;
q=head;
}
}//end of destructor

//This is the function to print out records in the list
void ListClass::printList()
{
NodePtrType temp = head;
while(temp != nullptr){
cout<<temp ->data.acctNum<<"\t"<<temp->data.balance<<endl;
temp = temp->next;
}
}
//Place code here to check to see if the list is empty
//if it is, print a message saying there are no items
//in the list.




//Place code here to check move from node to node, printing
//the account number, a tab, then the balance on one line
//with no labels. For example
//1114 395.67
{
...
NodePtrType temp = head;
while(temp != nullptr)
}
cout<<temp ->data.accountNumber<<"\t"<<temp->data.balance<<endl;
temp = temp->next;
{
...
}
// This function appends the record 'newData' onto the end of the linked list.
// If the list is empty, the new node is the new head of the list.
void ListClass::insertAtEnd(RecordType newData)
// INOUT IN
{
NodePtrType newNode, prev;

// Create a new node to hold the record.
newNode = new Node;
newNode->data = newData;
newNode->next = nullptr;

if (head==nullptr)
{
// The list is empty. Make the new node the head of the list.
head = newNode;
}
else
{
// The list is not empty, scan down to the end of the list and
// put the new node there.
prev = head;
while (prev->next != nullptr)
prev = prev->next;
prev->next = newNode;
}
}//end of insertAtEnd function

inlab18.cpp:53:1: error: expected unqualified-id before ‘{’ token
{
^
inlab18.cpp:58:2: error: ‘cout’ does not name a type
cout<<temp ->data.accountNumber<<"\t"<<temp->data.balance<<endl;
^~~~
inlab18.cpp:59:2: error: ‘temp’ does not name a type
temp = temp->next;
^~~~
inlab18.cpp:60:1: error: expected unqualified-id before ‘{’ token
{
^


1 Expert Answer

By:

Laury C. answered • 07/16/22

Tutor
5 (1)

Software Tutor from a FAANG Software Engineer

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.