Question: CSE 1 3 8 4 - Stacks and Queues Lab 8 Objectives: Continue practicing past concepts Practice using stacks and queues in C + +
CSE Stacks and Queues
Lab
Objectives:
Continue practicing past concepts
Practice using stacks and queues in
Background:
This week's lab will involve octal to decimal conversion. As such, here's some
backgroundexplanation as to how that works if you haven't worked with it before.
Assume you have a four digit octal number starting from the RIGHTmost digit, this will start at
and work your way up from for every consecutive digit. So four digits will have a
LEFTmost digit that represents This adjusts for every size, where your leftmost digit ends
up representing brought to the power of the size A diagram of this concept is found below.
For octal, digits can take the form of limited decimal values: PLEASE NOTE: is not valid.
Now, for conversion, you're adding the coinciding 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. and node. 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 addremove 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 yesno 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:
Your number converted is:
Would you like to enter another octal number yesno yes
Enter in a octal number to convert:
Your number converted is:
Would you like to enter another octal number yesno no
Goodbye! Node.h code
#ifndef NODEH
#define NODEH
class Node
public:
char data;
Node next;
zero constructor
Node
data ;
next nullptr;
Nodechar data, Node next
thisdata data;
thisnext next;
;
;
#endif NODEH
Stack.h code
#include "node.h
#ifndef STACKH
#define STACKH
class Stack
private:
int size;
Node headtail;
public:
Stack;
~Stack;
void addchar item;
char remove;
;
#endif STACKH
main cpp
#include
#include
#include
#include "stack.h
using namespace std;
string verifyValidOctstring oct;
int main
return ;
string verifyValidOctstring 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
int num oct.findfirstnotof;
runs while a char other than what we want is present
whilenum
error message
cout endl "Error. An invalid character was present in the octal number." endl;
cout "Please try again with characters only." endl;
and new input
cout endl "Enter in a octal number to convert: ;
getlinecin oct;
retests...
num oct.findfirstnotof;
returns validated number
return oct;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
