Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having some issues with some errors in my main program when i run this program it gets the error no match for 'operator=' (operand

I'm having some issues with some errors in my main program when i run this program it gets the error no match for 'operator=' (operand types are node and 'long long int') and a couple that say boolean and list not declared in this scope. I'm unsure how to fix this and was looking for some help thank you

Here's the a3.txt:

%insert Noah 99 %insert Emma 100 %insert Liam 75 %insert Olivia 82 %insert Mason 87 %insert Sophia 95 %insert Jacob 79 %insert Ava 97 %insert William 89 %insert Isabella 77 %insert Ethan 91 %insert Mia 94 %insert James 88 %insert Abigail 98 %write %erase William %erase Isabella %erase Michael %write %search Noah %search Emma %search Michael %sort %write %end

Here's the main program that reads that file:

#include #include #include #include #include

#include "node.h"

#include "llist.h"

using namespace std;

int main() { // stream to input instructions and information ifstream instrFile; // open file with list of people and their data instrFile.open("a3.txt"); if (!instrFile) { cout << "Cannot open file 'a3.txt'" << endl; }

string instruction, name, tempStr; int score; node *currNode;

// Set "curNode" value to NULL

*currNode = NULL;

// Create Object for llist class in list.h header file

llist obj;

while(!instrFile.eof()) { getline(instrFile, instruction, ' '); if (instruction == "%insert") { getline(instrFile, name, ' '); getline(instrFile, tempStr, ' '); const char* temp = tempStr.c_str(); score = atoi(temp); cout << instruction << " " << name << " " << score << endl; //your code

currNode = obj.insert(currNode, name, score); } else if (instruction == "%erase") { getline(instrFile, name, ' '); cout << instruction << " " << name << endl; //your code

// Search for element in list, ''search" returns the element position then erase it

currNode = obj.search(name);

obj.erase(currNode); } else if (instruction == "%search") { getline(instrFile, name, ' '); cout << instruction << " " << name << endl; //your code

// Search the list using the name given in the list if present do something else do another thing

boolean present = list.search(name);

// present is true if given name is presetn in list else false

} else if (instruction == "%write") { instrFile.ignore(100, ' '); cout << instruction << endl; //your code

// Simply call writeList, it will print all the elements in the list

list.writeList(); } else if (instruction == "%sort") { instrFile.ignore(100, ' '); cout << instruction << endl; //your code

//call sortAssend to sort in ascending order.

list.sortAssend(); } else if (instruction == "%end") { break; } }

int hold; cin >> hold; }

Here's the list.h header:

#ifndef LLIST_H_INCLUDED #define LLIST_H_INCLUDED

#include #include "node.h"

using namespace std;

class llist { public:

//default constructor llist();

//destructor ~llist();

//Inserts node at before node at pointer currNode node *insert(node *currNode, string name, int score);

//Uses insert function to add names and scores to the in alphabetical order void insertInOrder(string name, int score);

//Search for a name and print it out node *search(string name);

//Erase a name from the list void erase(node *currNode);

//Write out the current list void writeList();

//Write out a single node (name and score) void writeNode(node *currNode);

//Swap two nodes in the list used by sort void swapNode(node *nodeA, node *nodeB);

//Sort the by scores in ascending order void sortAssend();

node *header;

private:

int listSize;

};

llist::llist() { header = new node; header->prev = header; header->next = header; listSize = 0; }

llist::~llist() { node *currNode, *tempNode; currNode = header->next; while(currNode != header) { tempNode = currNode; currNode = currNode -> next; delete tempNode; } delete header; }

void llist::writeList() { cout << endl << "list" << endl; node *currNode; currNode = header->next; while(currNode != header) { cout << setw(10) << currNode->name << "\t" << currNode->score <

currNode = currNode->next;

} cout << endl; } node *llist::insert(node *currNode, string name, int score) { node *newNode, *prevNode; prevNode = currNode->prev;

newNode = new node; newNode->name = name; newNode->score = score; ++listSize;

newNode->prev = currNode->prev; newNode->next = prevNode->next;

prevNode->next = newNode; currNode->prev = newNode;

return newNode; }

void llist::insertInOrder(string name, int score) { node *currNode; currNode = header->next; while(currNode != header) { if(name < currNode->name) { insert(currNode, name, score); break; } currNode= currNode-> next; } if (currNode == header) { insert(currNode, name, score); } }

node *llist::search(string name) { node *currNode; currNode = header->next; while(currNode != header) { if(currNode->name == name) { return currNode; break; } currNode = currNode->next; } return NULL; }

void llist::erase(node *currNode) { node *prevNode, *succNode; prevNode = currNode->prev; succNode = currNode->next;

prevNode->next = succNode; succNode->prev = prevNode;

delete currNode; --listSize; }

void llist::writeNode(node *currNode) { cout << endl << "Node" << endl; if(currNode != NULL) { cout << setw(10) << currNode->name << "\t" << currNode->score << endl; } }

void llist::swapNode(node *nodeA, node *nodeB) { string tempName; int tempScore;

tempName = nodeA->name; tempScore = nodeA->score;

nodeA->name = nodeB->name; nodeA->score = nodeB->score;

nodeB->name = tempName; nodeB->score = tempScore; } void llist::sortAssend() { node *passNode, *smallNode, *jNode; int pass, j;

passNode= header->next; for(pass = 0; pass < listSize-1;pass++) { smallNode = passNode; jNode = passNode->next; for(j= pass+1;jscore < smallNode->score) { smallNode = jNode; } jNode = jNode->next; } if(smallNode != passNode) { swapNode(passNode,smallNode); //passNode = smallNode; FOR OTHER WAY OF SWAPPING } passNode= passNode->next; }

} #endif // LLIST_H_INCLUDED

Here's the simple node.h header:

#ifndef NODE_H_INCLUDED #define NODE_H_INCLUDED

#include

using namespace std;

struct node { string name; int score; node *prev; node *next; };

#endif // NODE_H_INCLUDED

SAMPLE OUTPUT BASED ON THE a3.txt: ( This is what comes out after the first %write)

Noah 99 Emma 100 Liam 75 Olivia 82 Mason 87 Sophia 95 Jacob 79 Ava 97 William 89 Isabella 77 Ethan 91 Mia 94 James 88 Abigail 98

After the second %write:

Noah 99 Emma 100 Liam 75 Olivia 82 Mason 87 Sophia 95 Jacob 79 Ava 97 Ethan 91 Mia 94 James 88 Abigail 98

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

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

Explain the stewardship role of financial reporting in accounting

Answered: 1 week ago

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago