C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 18, Problem 8SA

Explanation of Solution

The following is the complete code for the code segment

 

//include the required header files

#include <iostream>

#include <stack>

#include <cassert>

using namespace std;

//create a structure

struct node_Type

{

  int info;

  node_Type *nxt;

};

 

//definition of a class linkedStackType

class linkedStackType

{

  //declare some basic functions of stack

public:

    linkedStackType();

    void push(int n);

    void pop();

    int top();

    bool isEmptyStack();

    void clear_Stack();

private:

    node_Type *s_Top;

};

//end of the class

 

//definition of the function linkedStackType()

linkedStackType::linkedStackType()

{  

    s_Top = NULL;

}

 

//definition of the function isEmptyStack

bool linkedStackType::isEmptyStack()

{

    return (s_Top == NULL);

}

 

//definition of the function push()

void linkedStackType::push(int item)

{

    node_Type *new_Node = new node_Type;

  new_Node->info = item;

 

  new_Node->nxt = s_Top;

  s_Top = new_Node;

}

 

//definition of the function top()

int linkedStackType::top()

{

    assert(!isEmptyStack());

  

    return s_Top->info;

}

 

//definition of the function pop()

void linkedStackType::pop()

{

    if(isEmptyStack())

        cout<<"Stack is empty" << endl;

    else

  {

        node_Type *current = s_Top;

    s_Top = s_Top->nxt;

    delete current;

  }

}

 

//definition of the function clear_Stack()

void linkedStackType::clear_Stack()

{

  while(s_Top != NULL)

  {

    node_Type *current = s_Top;

    s_Top = s_Top->nxt;

    delete current;

  }

}

 

//definition of the main function

int main() {

  linkedStackType stack;

  long long num;

  int temp;

  int secretNum = 0;

  cin >> num;//837298651020706

  num = abs(num);

  while (num > 0)

  {  

    stack...

Blurred answer
Students have asked these similar questions
Can I get help with this case please, thank you
I need help to solve the following, thank you
reminder it an exercice not a grading work             GETTING STARTED Open the file SC_EX19_EOM2-1_FirstLastNamexlsx, available for download from the SAM website. Save the file as SC_EX19_EOM2-1_FirstLastNamexlsx by changing the “1” to a “2”. If you do not see the .xlsx file extension in the Save As dialog box, do not type it. The program will add the file extension for you automatically. With the file SC_EX19_EOM2-1_FirstLastNamexlsx still open, ensure that your first and last name is displayed in cell B6 of the Documentation sheet. If cell B6 does not display your name, delete the file and download a new copy from the SAM website. Brad Kauffman is the senior director of projects for Rivera Engineering in Miami, Florida. The company performs engineering projects for public utilities and energy companies. Brad has started to create an Excel workbook to track estimated and actual hours and billing amounts for each project. He asks you to format the workbook to make the…

Chapter 18 Solutions

C++ Programming: From Problem Analysis to Program Design

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Fundamentals of Information Systems
Computer Science
ISBN:9781337097536
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning