Question

8. Given: struct STACK INF RC 1301 int top that the following functions have already been declared in a stack tolkit and are available for create stack(s) push(s, item) pop(s, item) topls, item) empty(s) Boolean function use some or all of them to write the complete definition code for a function that passes in a stack (as an argument), removes the SECOND assume that there are at least two items in the stack). item (from the top) in the stack, and returns it (as an argumen). You may Example: 7 ←top of stack returns:8 10 points Write the required statements to declare a variable of type double with a value of 12.818, declare a pointer variable that can hold the address of a double, assign the address of the double variable to the pointer variable, and print out the value of the double variable through the use of the pointer variable. 9. a. Write the statements required to: declare a pointer variable that can hold the address of a dow dynamically allocate memory to hold a double and assign the address of this area to the pointer var the value: 13.241 in the allocated memory area, print out the stored value, deallocate the me
0 0
Add a comment Improve this question Transcribed image text
Answer #1

8.

secondItem(s,item ) // s= STACK and item = argument to hold the second item(from top of the stack)

{

pop(s,item1); // pop the top item from stack s to item1

pop(s,item); // pops the second item from top of stack to item

push(s,item1); // push the item1 to top of stack

// item will contain the second item from top of the stack

}

9(a)

C++ statements :

double a=12.818;
double *a_ptr;
a_ptr = &a;
cout<<*(a_ptr);

9(b)

C++ statements:

double *a;
double *a_ptr = new double;
a = &a_ptr;
*a_ptr = 13.241;
cout<<*a_ptr;
delete a_ptr;

Add a comment
Know the answer?
Add Answer to:
8. Given: struct STACK INF RC 1301 int top that the following functions have already been...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include<string> #include<vector> using namespace std; struct patient { string name; char Gender; int d,m,y;...

    #include <iostream> #include<string> #include<vector> using namespace std; struct patient { string name; char Gender; int d,m,y; string nationality; int civilID; int phoneNumber; string TypeOfInsurance; }; Activities I. Declare a variable from the struct Patient called pat. II. Fill out the information of pat by reading them from the input. III. Declare a pointer of type Patient called pat_ptr and assign the address of pat to it. IV. Change the value of name field of pat by accessing it through pat_ptr....

  • In C, Implement each of the functions to create a working stack 6 II-Implement each of...

    In C, Implement each of the functions to create a working stack 6 II-Implement each of the functions to create a working stack. 7 II -Do not change any of the function declarations I-(i.e. stack t* create stack) should not have additional arguments) II-You should not have any 'printf' statements in your stack functions 10 II(You may consider using these printf statements to debug, but they should be removed from your final version) 12 #ifndefMYSTACK_A 13 #define MYSTACKH 14 15...

  • using visual studio 2) For each of the following, write C++ statements that perform the specified...

    using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...

  • CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification:...

    CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification: A stack is a container that can be defined in terms of an array where all adds are preformed at the end of the sequence of existing values, and all removes are also preformed at end of the sequence of existing values. An empty stack is one that has no existing values in the array at all. We use the notion of top of...

  • Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...

    Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • (C++) Two stacks of the same type are the same if they have the same number...

    (C++) Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various overloaded operators and functions of classstackType. **Please...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to...

    LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to a function and returning values. Everything is stored on the runtime stack so that space is used only when the function is executing. As a result the actual address of arguments and locals may change from call to call. However, the layout of the stack frame (activation record) is constant. Thus, the offests from the frame pointer (FP) to the parameters/locals are constant. All...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT