Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* Linked List Experiment */ #include #include struct tax_node { char form; // t

ID: 3767442 • Letter: #

Question


/*
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;
}

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 element’s information. Even though we know that the list in the example is three elements, the loop should work for any size list

Explanation / Answer

#include <cstdlib>
#include <iostream>
struct tax_node
{
char form;   
int version;
tax_node *next;
void print_contents (tax_node*& point);
};
typedef tax_node* tax_ptr;
using namespace std;
void print_contents (tax_ptr*& point)
{
tax_ptr printer;
cout << printer -> form;
cout << printer -> version;
cout << " ";
}
int main(int argc, char *argv[])
{
tax_ptr ptr1, ptr2, ptr3, mover;
ptr3 = new tax_node;
ptr3 -> form = 'e';
ptr3 -> version = 17;
ptr2 = new tax_node;
ptr2 -> form = 'd';
ptr2 -> version = 6;
ptr1 = new tax_node;
ptr1 -> form = 'w';
ptr1 -> version = 2;
print_contents(ptr2);
//for (mover= !=NULL; mover = mover -> next)
// cout << ptr1 -> form << endl;
cout << ptr3 -> form << ptr3 -> version;
cout << ptr2 -> form << ptr2 -> version;
cout << ptr1 -> form << ptr1 -> version;
cout << " ";
system("PAUSE");
return EXIT_SUCCESS;
}