Title: Homogeneous aggregate
1Homogeneous aggregate
name Tom, John, student-3,
student_4,........, student-20
mid1 70, 67, 86,
59, ........, 80
final 69, 77, 79,
64, ........, 90
GPA 3.02, 2.89, 3.21,
2.78, ........, 3.67
// Using array string name20 int
mid120 int final20 double
GPA20 name0 "Tom" GPA2 3.21
// Using tvector class include
"tvector.h" .............. tvectorltstringgt
name(20) tvectorltintgt mid1(20) tvectorltintgt
final(20) tvectorltdoublegt GPA(20) name1
"John" GPA19 3.67
2Search in a tvector
// Using tvector class include
"tvector.h" .............. tvectorltstringgt
name(20) tvectorltintgt mid1(20) tvectorltintgt
final(20) tvectorltdoublegt GPA(20) ..... .....
// What is Susan's GAP? for (int i0 i lt
name.length() i) if (namei "Susan")
cout ltlt GPAi
3What can be in an Array
// Using tvector class ..... ..... struct
student string name int mid1 int
final double GPA ...... struct student
class10120 ..... // What is Susan's GAP?
for (int i0 i lt class101.length() i)
if ( (class101i).name "Susan") cout ltlt
(class101i).GPA
4Enumerated Types
Sunday Monday Tuesday Wednesday Thursday Friday
Saturday
Monday Tuesday Wednesday Thursday Friday Saturday
Sunday
enum day Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday, Sunday tvectorltintgt
MyclassHr(7) MyclassHrMonday
2 MyclassHrTuesday MyclassHrThursday
0 MyclassHrWednesday 4 day
ThreeDays3 day ADay ThreeDay0Saturday ...
... if (ADay Saturday ADay Sunday)
cout ltlt "It's weekend" day FirstDay day(0)
5Two dimensional array, Matrix
1 3 2
1 1 3
0 1 2
2 4 0
2 1 1
0 2 1
3 7 2
3 2 4
0 3 3
// Using array int A33 int B33 int
C33 A12 3 A11 1 C21
A21B21
// Using apmatrix class include
"apmatrix.h" .............. apmatrixltintgt
A(3,3) apmatrixltintgt B(3,3) apmatrixltintgt
C(3,3) A12 3 A11 1 C21
A21B21
6Operation on Matrix
// Using apmatrix class include
"apmatrix.h" .............. apmatrixltintgt
A(3,3) apmatrixltintgt B(3,3) apmatrixltintgt
C(3,3) int i,i ..... ..... for
(i0iltA.numrows()i) for (j0jltA.numcols()j
) Cij Aij Bij
Easy problem How to printout a matrix?
Challenging problem How to do multiplication?