Download presentation
Presentation is loading. Please wait.
Published byNoel Stevens Modified over 9 years ago
1
Tutorial 9 String and Structure NUS SCHOOL OF COMPUTING CS1010E PROGRAMMING METHODOLOGY 1 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
2
Quick Summary 1.Structure introduces the concept of an Object. The Object can contain many attributes. (Person: Gender, Age, etc.) 1.Two ways to declare a structure: typedef struct{…}[identifier]; struct [identifier]{…}; 2.To retrieve the attributes of a structure use “.” operator: Person.Gender = “male”; Person.Age = 20; 3.For Structures with pointers: Person->Gender = “male”; Person->Age = 20; 2 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
3
Q1: Self Implementation of 3 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
4
4 Q1: Self Implementation of RADAR\0Left Right strlen = right – left; CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
5
5 Q1: Self Implementation of RADAR\0 s1s1 s2s2 t CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
6
6 Q1: Self Implementation of RADAR\0 RA s1s1 s2s2 t my_strcpy(s1,s2); RARADAR\0 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
7
7 Q1: Self Implementation of RADAR\0 RADAR s1s1 s2s2 Loop until (s1 becomes \0) or (a difference is found): Return the difference CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
8
Q2: Christmas Carol 8 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
9
Q2: Christmas Carol 9 On any particular day: CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO Constant strings: “On the ” “day of Christmas,\n” “my true…\n” “and ”
10
10 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
11
11 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
12
12 Q2: Christmas Carol Because a word ends with either of the following: Space, Comma, Fullstop. CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
13
13 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
14
Q3: Overlapping Rectangles 14 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
15
Q3: Overlapping Rectangles 15 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
16
Q3: Overlapping Rectangles 16 If the points do not fulfil the pre-condition required, we just need to swap the two points. CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
17
17 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
18
18 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO It is easier to check if the two rectangles do not overlap:
19
19 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
20
Q4: Snapback Problem 20 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
21
21 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
22
22 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
23
23 Q4: Snapback Problem Bubble sort algorithm is used. This is an improved version of the bubble sort. What is the difference? CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
24
24 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
25
25 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
26
26 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO 10011…110 In the binary sequence, 1 means take the item number j, 0 means omit the item number j. We use this binary sequence approach to enumerate all the possible ways to take the items available and compare the value.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.