1 |
h15 |
CS16 S17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone") |
h15: Homework 15: Structures, Dynamic Arrays, and Linked Lists
ready? | assigned | due | points |
---|---|---|---|
true | Thu 06/01 12:30PM | Tue 06/06 12:30PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
In place of that, we drop the two lowest scores (if you have zeros, those are the two lowest scores.)
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
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.(12 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.
Print out the program on a separate sheet of paper and attach it to this homework.
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
3.(8 pts) What is the output of the following program? Using a pointer diagram show the evolution of all data objects in memory. Assume the code is embedded in a correct and complete program.
int array_size = 4, *a ;
a = new int[array_size];
int *p = a;
for(int i=0; i< array_size; i++)
*(a+i) = 2*i;
p[0] = 10;
for(int i=0; i< array_size; i++)
cout<<a[i]<<" ";
cout<<endl;
4.(12 pts) In class, we went over node insertion in detail. Consider a linked list where each node is of the type struct Node
, as defined on display 13.7 on page 754. Complete the definition of the function deleteNode
(declaration is shown below), that takes as input a pointer to the head of the list, and an integer value. The function should delete all the nodes in the list whose data members have the given value. If there is no node with the given value, the function should not do anything. You can assume that the list will not be empty.
If you cannot write out the program function in the space provided below, then print it out on a separate sheet of paper and attach that to this homework.
void deleteNode(struct Node*& head, int value);