Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the CPP file /* Lab 10 - Linked List Experiment */ #include #include struct tax_node { char form; // tax form letter int

Here is the CPP file

/* Lab 10 - Linked List Experiment */ #include  #include  struct tax_node { char form; // tax form letter int version; // tax form number tax_node *next; // pointer to next node }; typedef tax_node* tax_ptr; using namespace std; int main(int argc, char *argv[]) { tax_ptr ptr1, ptr2, ptr3, mover; ptr1 = new tax_node; ptr1 -> form = 'w'; ptr1 -> version = 2; cout << " "; return 0; } 

Questions to add to the program:

Write a function prototype and definition for print_contents. print_contents takes a pointer to a node as its only parameter. It does not return a value. The function goes to a new line on output and prints the information in the node referenced by the pointer. For example if the following code was executed for the above example:

print_contents (ptr2);

The function would print:

e17

Write a loop in main that controls a pointer moving through the given list starting at ptr1. For each element of the list, print_contents should be called to print that elements information. Even though we know that the list in the example is three elements, the loop should work for any size list.

Answer the following questions:

1. Print ptr1 -> next -> form just before the cout << . What value is printed and why?

2. Change the value printed to ptr1 -> next. Explain why this value is printed. What does it point to?

3. Change the code to print ptr3 -> next. What does this value represent?

4. Change the code to print ptr3 -> next -> version. What happens and why?

Remove this print statement.

5. Put the following assignment statement just before the printing loop in main:

ptr3 -> next = ptr1;

Run your program. What happens? Explain why. Draw a box and arrow diagram to help in the explanation.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

9. System creates a large, diverse talent pool.

Answered: 1 week ago