CSCI 159 Structs and Pointers Lab (Prep for Quiz 3)

CSCI 159: Fall 2024 Lab 6

Struct and Pointers (Prep for Quiz 3)

  1. In a directory of your making (it could be a lab6 directory in csci159dev), write a program that asks the user for five integers. Put the values in variables called a, b, c, d, e.
  2. Make a pointer variable maxPtr that points to the maximum value among the five variables a, b, c, d, e. Do so using the inline comparison operator. An example of its use is:
    
    			int *maxPtr;
    			maxPtr = (a>b) ? &a: &b;
    			
    etc. It will take three more to get maxPtr right.
  3. Add 5 to the largest integer by referencing maxPtr.
  4. cout the five variables in the order a,b,c,d,e.
  5. Write a different program. Call it struct.cpp In this program, create a struct PerStruct. PerStruct has two fields, a string 'name', and 'likes', a pointer to a perStruct.
  6. Make four PerStructs called bob, abby, lolly and sim. Make bob "like" abby, abby "like" lolly, lolly "like" abby, and sim "like" lolly.
  7. For all four PerStructs, print their names and the person they like.
  8. Declare a pointer to a PerStruct, call it bobLikes. Assign to it a pointer to the PerStruct that bob likes. Print out the name field of bobLikes.


Useful Links: Gara Pruesse's Homepage
Computing Science Homepage
Vancouver Island University Homepage
X2Go