Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ please Program 2 - Stacks Objectives: - Practice utilization of dynamic memory and objects - Practice altering and extending existing code base to meet
c++ please
Program 2 - Stacks Objectives: - Practice utilization of dynamic memory and objects - Practice altering and extending existing code base to meet new criteria - Better understand usage of Stacks to achieve a particular algorithm Assignment: The goal of this assignment is to implement an algorithm using one of our existing Linear Data Structures: The Stack. The algorithm in question will be to Convert Decimal Values to Their Binary Representation. - decimal: 21 - binary: 10101 The best approach for this is to utilize a simple algorithm involving modulo and integer division. - First Step - 21%2=1 - Push(1) // This is the modulo result - 21/2=10// We do not retrain a floating point remainder as we are handling integers - Second Step - 10%2=0//10 is our previous integer division result - Push (0)// This is the modulo result - 10/2=5 The goal of this assignment is to implement an algorithm using one of our existing Linear Data Structures: The Stack. The algorithm in question will be to Convert Decimal Values to Their Binary Representation. - decimal: 21 - binary: 10101 The best approach for this is to utilize a simple algorithm involving modulo and integer division. - First Step - 21%2=1 - Push(1) // This is the modulo result - 21/2=10//We do not retrain a floating point remainder as we are handling integers - Second Step - 10%2=0//10 is our previous integer division result - Push(0) // This is the modulo result - 10/2=5 - Continue this pattern until you reach 0 - Pop the results from the stack Use the following links for the code base and explanation of the code base. Do note that the videos will be using examples in C. You can easily use clang ++ for the C++ compiler. - Understanding Stacks - Code Review for Stacks - Ct+ Codebase for Stacks I would suggest altering the scope of the Stack's length and making Pop actually return a value for the user to use back in the main function. You should be able to convert any positive integer to its binary from. DO NOT WORRY ABOUT NEGATIVE VALUES As with the previous assignment, I do still expect the same compiler to be used and the commands used will be a portion of the submission. Output: We will need to use the following sequence of compiling our files to a binary and running said binary... Endeavour0S | fsh | [12:50:14] devin @ devin-endeavour-7950x in Course-DataStruct/Stack clang++ main.cpp Stack.cpp -o Stack.exe EndeavouroS | fsh | [12:50:27] devin @ devin-endeavour-7950x in Course-DataStruct/Stack . IStack. exe value to convert: 0 Stack [ 1 ] [ 0 ] [ 1 ] [ 1 ] [ 1 ] Binary Form: 10111 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started