Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am developing code and it does not compile. I have came into some problems blow I have included the full list of all the

I am developing code and it does not compile. I have came into some problems blow I have included the full list of all the code files and screenshots of what parts are the problem hopefully you can fix my problem and the program can run with no problem

THIS ARE THE CODE FILES

Main.cpp

------------------------------

#include #include #include #include "LinkedStack.h"

using namespace std;

int main() { string filename, itemName; int bid; ifstream in; LinkedStack stack;

// input the filename cout

in.open(filename); // open input file

// file error, display error message and terminate the program if(in.fail()) cout

// loop till the end of file is reached while(!in.eof()) { in >> bid; // read a bid amount // stack is empty or bid amount read is greater than top bid amount of stack, insert bid at top of stack if(stack.isEmpty() || stack.peek()

}

in.close(); // close the file

if(!stack.isEmpty()) // stack is not empty, display the top bid cout

return 0; }

// end of main.cpp

--------------------------------------------------------------------------------------------------------------------------------------

Node.h

--------------------------------------------------------------------------------------------------------------------------------------------

#ifndef NODE_H #define NODE_H

class Node{

private: int bid; // bid amount Node* next; // reference to the next Node

public: Node(int bid); void setBid(int bid); void setNext(Node* next); int getBid() const ; Node* getNext() const; };

#endif

------------------------------------------------------------------------------------------------------------------

Node.cpp

------------------------------------------------------------------------------------------------------------------------

#include "Node.h"

// parameterized constructor to initialize bid to parameter and set next to null Node::Node(int bid): bid(bid), next(nullptr) {}

// setters // function to set the bid amount to parameter void Node:: setBid(int bid){ this->bid = bid; }

// function to set the next node void Node:: setNext(Node* next){ this->next = next; }

// getters // function to return the bid amount int Node:: getBid() const{ return bid; }

// function to return the next node Node* Node:: getNext() const{ return next; }

--------------------------------------------------------------------------------------

LinkedStack.h

------------------------------------------------------------------------------------------

#ifndef LINKEDSTACK_H #define LINKEDSTACK_H

#include "Node.h"

class LinkedStack { private: Node *top; // node to top of the stack

public: LinkedStack(); ~LinkedStack(); bool isEmpty() const; void push(int bid); int pop(); int peek() const; };

#endif

--------------------------------------------------------------------------------------------------------------------

LinkedStack.cpp

----------------------------------------------------------------------------------------------------------------------

#include "LinkedStack.h"

// constructor to create an empty stack LinkedStack::LinkedStack() : top(nullptr) {}

// destructor to delete the nodes of the stack LinkedStack::~LinkedStack(){

// loop over the stack deleting the nodes while(top != nullptr) { Node* temp = top; // set temp to top node top = top->getNext(); // update top to next node delete temp; // delete temp node } }

// function that returns true is stack is empty else returns false bool LinkedStack:: isEmpty() const{ return top == nullptr; }

// function to insert the bid amount at top of stack void LinkedStack:: push(int bid){

// create a new node for given bid Node *node = new Node(bid); node->setNext(top); // set next of node to top top = node; // update top to node }

// function to remove and return the bid amount at top of stack if not empty else return a default value of -1 int LinkedStack:: pop(){

int data = -1; // set data to -1(default value returned when stack is empty)

if(!isEmpty()) // stack is not empty { Node *temp = top; // get the top node data = temp->getBid(); // set data to bid of top node top = top->getNext(); // update top to node next to to top delete temp; // delete temp }

return data; }

// function to return the bid amount at top of stack without removing it int LinkedStack:: peek() const{

int data = -1; // set data to -1(default value returned when stack is empty)

// stack is not empty, set data to bid of top node if(!isEmpty()){ data = top->getBid(); }

return data; }

--------------------------------------------------------------------------------------------------------------------------

auctions.txt

----------------------------------------------------------------------------------------------------------------------------

Valuable Item 50 24 59 62 68 99 87 53 76 12 98 81 66 34

-----------------------------------------------------------------------------------------------------------------

The screenshots

-------------------------------------------------------------------------------------------------------------------

image text in transcribed

image text in transcribed

image text in transcribed

C. C.UsersJacob KoningDesktoplMaincpp - Dev-C++ 5.11 File Edit Search View Project Execute Tools AStyle Window Help C. C.UsersJacob KoningDesktoplMaincpp - Dev-C++ 5.11 File Edit Search View Project Execute Tools AStyle Window Help

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

More Books

Students also viewed these Accounting questions

Question

Organizing Your Speech Points

Answered: 1 week ago