Question: CSE 1 3 8 4 - Stacks and Queues Lab 8 Objectives: Continue practicing past concepts Practice using stacks and queues in C + +

CSE 1384- Stacks and Queues
Lab 8
Objectives:
Continue practicing past concepts
Practice using stacks and queues in C++
Background:
This week's lab will involve octal to decimal conversion. As such, here's some
background/explanation as to how that works if you haven't worked with it before.
Assume you have a four digit octal number - starting from the RIGHT-most digit, this will start at
80 and work your way up from 0, for every consecutive digit. So, four digits will have a
LEFT-most digit that represents 83. This adjusts for every size, where your left-most digit ends
up representing 2 brought to the power of the size -1. A diagram of this concept is found below.
For octal, digits can take the form of limited decimal values: 0-7. PLEASE NOTE: 8 is not valid.
Now, for conversion, you're adding the coinciding 8 exponentials multiplied by the digit in the
exponent's location. For a couple of examples:Please find further resources on octal to decimal conversion here:
Octal to Decimal video
Converter (to double check your numbers)
Assignment:
You'll be given a starting point of stack. h and node. h- your job is to complete all of the
functions in a stack.cpp file of your creation. Do NOT change either header file - your
functions must adhere to the standards set in the headers. Note: the remove function returns an
item. This should be returning the data that was contained at the node that was deleted. Create
the add/remove functions in a way that adheres to STACK principles.
main.cpp:
This is where you'll need to use your stack to perform octal conversion. A lot of this design wise
is left up to you (you can use functions to aid you, or not). However, you must fulfill these items:
Ask for an initial octal number
Display the finalized conversion result
Ask the user if they'd like to enter another octal
Validate a yes/no answer
Loop accordingly
Notice, the conversion itself will happen in main. You're using the stack to aid you in doing so.
To be compatible with the Stack class, you should be taking your user input in as a string and
iterating through each character to add an individual character to your stack.
A function in a provided main.cpp has been supplied to verify that your strings adhere to octal
standards. You MUST use this function - user input should be verifiably an octal number before
conversion is attempted.
Hints:
In order to do exponents, you can use the cmath library through: #include FULL process working together
Welcome to octal to decimal conversion.
Enter in a octal number to convert: 36
Your number converted is: 30
Would you like to enter another octal number (yes/no)? yes
Enter in a octal number to convert: 3312
Your number converted is: 1738
Would you like to enter another octal number (yes/no)? no
Good-bye! Node.h code
#ifndef NODE_H
#define NODE_H
class Node
{
public:
char data;
Node *next;
// zero constructor
Node()
{
data ='';
next = nullptr;
}
Node(char data, Node *next)
{
this->data = data;
this->next = next;
};
};
#endif // NODE_H
Stack.h code
#include "node.h"
#ifndef STACK_H
#define STACK_H
class Stack
{
private:
int size;
Node *head,*tail;
public:
Stack();
~Stack();
void add(char item);
char remove();
};
#endif // STACK_H
main cpp
#include
#include
#include
#include "stack.h"
using namespace std;
string verifyValidOct(string oct);
int main()
{
return 0;
}
string verifyValidOct(string oct)
{
// finds the index of the first character that doesn't match this set
// if there's no character not in the set it returns -1
int num = oct.find_first_not_of("01234567");
// runs while a char other than what we want is present
while(num >-1)
{
// error message
cout endl "Error. An invalid character was present in the octal number." endl;
cout "Please try again with characters 0-7 only." endl;
// and new input
cout endl "Enter in a octal number to convert: ";
getline(cin, oct);
// retests...
num = oct.find_first_not_of("01234567");
}
// returns validated number
return oct;
}
CSE 1 3 8 4 - Stacks and Queues Lab 8 Objectives:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!