Professional Documents
Culture Documents
Tutorial 2 Structures II
Tutorial 2 Structures II
Use typedef to declare a structure called Personal which has the following members:
An array called name of type character with 20 elements.
A variable called sex of type character.
A variable called birthday of the structure type declared above (nested).
Declare a variable called strong of the structure type that you have just created.
(i) Declare a tagged structure called Employee to hold the above information.
(ii) Define an array emp of type Employee (as in (i) above) that can store 100 sets of employee information.
(iii) Write statements to accept 100 sets of employee data and store them all into the array declared in (ii).
(iv) Write a statement to change the employeeName of the last employee in the array emp in (ii) to
“Anthony Swamy”.
(v) Use typedef to declare a structure called Boss with the following members (including a nested structure):
An array called departmentCode of type character with 6 elements.
An array called managerName of type character with 20 elements.
A variable employee of the type struct Employee (defined in (i) above).
Define a variable called boss of the structure type you have just declared.
---------------------------------------------------------------------------------------------------------------------------------------
Page 1 of 3
Tutorial 2 Structures II AACS1084 PCDII
4.
(i) Using typedef, declare a structure called Employee which can hold the following details of an employee.
ID
Name
Position (3m)
(ii) Using the keyword struct (without typedef), declare a structure called Wrk to store the employee
working record consisting of the following details.
(You must make use of the structure declared in part (i) above.)
emp (as in (i) above)
rate
hours
basic (4m)
(iii) Define an array, called empWrk, of 10 structures of type Wrk declared in part(ii) above. Initialize the
first two records with details as follows:
5.
(i) Using typedef, declare a structure called Schedule which can hold the following details of a class
schedule.
subject (e.g. PROGRAMMING)
time (e.g. 10)
day (e.g Monday) (4m)
(ii) Using the keyword struct (without typedef), declare a structure called Address to store an address
consisting the following strings:
street
city
state
zip (4m)
(iii)Use typedef to declare a structure called StudentData that can be used to store the following student data.
You must make use of the structures declared in part (i) and (ii) above.
Registration Number (string)
Address (as in (ii) above)
GPA (double)
Schedule ( for six different classes) (as in (i) above) (4m)
(iv) Define a variable stud1 of the type declared in part (iii) above. (1m)
(v) Write a statement to assign the string ”PROGRAMMING” to the member subject in the first class
schedule in stud1. (2m)
(vi) Write a statement to assign the value 10 to the member time in the last class schedule in stud1. (1m)
---------------------------------------------------------------------------------------------------------------------------------------
Page 2 of 3
Tutorial 2 Structures II AACS1084 PCDII
6.
(i) Declare a tagged structure called Date which consists of the following members: (2m)
month (eg. 12)
day (eg. 5)
year (eg. 2001)
A graphic representation of the structure is shown below:
Date
month day year
(ii) Using typedef, declare a structure called Student with the following members: (4m)
studentName (eg. Wilson Tan Wing Soon)
icNo (eg. 980225-06-0025)
birthDate (eg. as in (i) shown above)
A graphic representation of the structure is shown below:
Student
studentName icNo birthDate
month day year
(iii) Using typedef, declare a structure called Programme which is used to store data about the
programme. The structure must contain the following details: (5m)
programmeTitle (eg. Diploma in Computer Studies)
commencingDate (eg. as in (i) above)
studentData (eg. as in (ii) above, there are 10 of these)
A graphic representation of the structure is shown below:
Programme
programmeTitle commencingDate
month day year
studentData
studentName studentName studentName
(iv) Define a variable called ibProgramme of the type Programme which was declared in (iii). (1m)
(v) Write a C program segment that prompts the user to input 10 sets of student records. Store the data
entered into the member studentData in the variable ibProgramme defined in (iv). (9m)
---------------------------------------------------------------------------------------------------------------------------------------
Page 3 of 3