Homework
37
Part 1 of 2: Given the
following information complete the table below:
1) If the value of a variable is an address, simply write ADDR
for the value (but still give the type)
2) If the value of a variable is a struct,
simply write STRUCT for the value (but still give the type)
Hint: Do this by hand, not by running in Visual Studio. You don't need to run/simulate the whole program above to be able to fill out the matrix, just look at the variable and figure out what its value would be. Once a variable is initialized its value is not modified.
#include <iostream>
using namespace
std;
struct myStruct {
double data;
myStruct
*next;
};
int main () {
double y = 3.7;
int a = 5;
int b = 11;
double z;
myStruct
*list;
myStruct
firstNode;
firstNode.data
= 5.3;
firstNode.next
= 0;
list
= &firstNode;
//complete
the table below as if all of the
//instructions
occurred at this point
//Assume
each line of the table is the
//only
line of code (ie assignments made
//based
on questions in the table do not
//effect
any other row of the table)
return 0;
}
|
Expression |
Type |
Value |
|
&firstNode |
|
|
|
list->next |
|
|
|
list->data |
|
|
|
z = b / a |
|
|
|
z = b / double (a) |
|
|
|
(a < 10 && b < 10) |
|
|
|
(a < 10 | | b < 10) |
|
|
|
a = 6 |
|
|
|
b == 6 |
|
|
Part 2: Modify the following code so the function printList prints the data fields of the linked list from back to front.
class Node{public:int data;
Node* next;};
void printList(Node*
p) {
if (p!=0){
cout
<< p ->data << endl;
printList(p->next);
}
}