1
h16
CS16 F16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
9am or 10:30am
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h16: Homework 16

ready? assigned due points
true Tue 11/29 02:00PM Thu 12/01 02:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


Please:

  • No Staples.
  • No Paperclips.
  • No folded down corners.

Reading: Read Chapter 10.1 and 10.2. If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”.

PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL! FOR BEST RESULTS, SAVE THIS PAGE AS A PDF, THEN PRINT THE PDF.

1.(8 pts) Write a definition for a structure type for records consisting of a person’s wage rate, accrued vacation (in whole days), and status (hourly or salaried - represent the status as one of the two character values ‘H’ and ‘S’). Call the type EmployeeRecord.

2.(3 pts) Describe the difference between a class and a structure?

3.(3 pts) Explain why member variables are usually private?

4.(3 pts) Describe the purpose of a constructor?

5.For the next 3 questions (a-c), refer to Display 10.6 in the text book.

a.(3 pts) Why are there 3 different constructors in the BankAccount class?

b.(3pts) What is line 38 in the program doing?

c.(3 pts) Can the main program use the BankAccount member function called fraction()? Explain why or why not?

6.(14 pts) Write a program that has a definition for a structure type called UndergradStudents. This structure should contain student ID numbers, first and last names, major, and GPA scores for each undergraduate year. The program should declare and then initialize an array of 3 objects of this class (hint: you can do this with the same approach you define/initialize an array of any other type). You must initialize the values in the program, not by user input. The initial values are shown in the table below. The program should then print out some of the values of the array of objects as shown in the sample below, along with each student AVERAGE GPA score (which you should calculate, with a precision of 2 decimal places). You must use a loop to print the output.

If you cannot write out the program in the space provided below, then print out the program on a separate sheet of paper and attach that to this homework. Please do not use more than 1 page, one sided.

ID First name Last Name Major GPA Yr1 GPA Yr2 GPA Yr3 GPA Yr4
1 Joe Shmoe EE 3.8 3.3 3.4 3.9
2 Macy Chen CS 3.9 3.9 4.0 4.0
3 Patrick Sadface ME 3.8 3.0 2.4 1.9

OUTPUT:

These are the student records:
ID# 1, Shmoe, Joe, Major: EE, Average GPA: 3.60
ID# 2, Chen, Macy, Major: CS, Average GPA: 3.95
ID# 3, Sadface, Patrick, Major: ME, Average GPA: 2.77