Name ___________________

CPTR246 Spring '99 (100 total points) Exam 1

  1. Short answer questions
  1. What is a pointer? (5 points)
  2.  

     

     

     

     

     

  3. What is the output produced by the following code? (5 points)
  4. int x(10);

    int * a;

    a = &x;

    *a = *a * x;

    cout << x << endl;

     

     

  5. Arrays and structures are both collections of objects. However there is a fundamental difference between the two. Explain how structures differ from arrays? (10 points)
  6.  

     

     

     

     

     

     

     

  7. Explain what redirection is and how it works. (10 points)
 
 

Structures: (20 points)

  1. Define a structure called studentSchedule that contains the following information
Student ID number (an integer)

Student name (a string of at most 30 characters)

Number of courses this semester

At most 6 course numbers (each an integer)

 

 

 

 

 

 

 

 

b. Define a studentSchedule object for a student by the name of Jack J. Jones and initialize its data members as follows: ID number is 123456. Jack is taking 4 courses. The numbers of the courses are 30121, 50200, 42101, and 21230.

 

 

 

 
 

 Formatting output: (25 points) Write a function called printAddressBook that takes the array of Address structures defined below and prints out the information in the following format (don't worry about headings):
 
 
 
 
 
 
 

Parsing input: (25 points) A file has been created that contains employee information, specifically employee ID (an integer), full name (a string), and this week's calculated pay (a real number). The file is formatted so that the information for each employee is on one line and the values are separated by pound signs (#). For example, the file might contain:

123456789#John J. Jones#527.76#

987654321#Mary Q. Public#500.00#

1212121#Sam Smith#620.10#
. . . .
 
 

Write a function called getNextEmployee that will read the information for the next employee on file and place the information in the parameters passed to it. (You may assume that the information in the file is formatted correctly.)

An example of the function's use:

int ID;
char name[30];
double pay;
ifstream inFile("weekly.dat");

. . .

// sample call to function
getNextEmployee(inFile, ID, name, pay);

. . . // ID, name, and pay are used in later code