Searching and Sorting

Size: px
Start display at page:

Download "Searching and Sorting"

Transcription

1 Introduction to Programming ( 數 ) Lecture 10 Spring 2005 May 13, 2004 NCCU C prog. 1

2 Topics More on Strings, Arrays, Pointers Static variables Structure: struct NCCU C prog. 2

3 Review of String Basics Strings = arrays of chars with NULL ( \0 ) termination. o char a[ ] = "xyz ; o char a[ ] = {'x', 'y', 'z', '\0'}; /* same thing */ Strings are often handled through pointers o Char *cp = A string ; Strings I/O o scanf, fscanf, gets, fgets, puts, fputs String Operations (<string.h>) o strlen, strcpy, strcat, strcmp, NCCU C prog. 3

4 string declaration and memory layout char a[3]; char *p; char *p = "abc"; char a[] = "abc"; p??? p a??? a?????? a b c \0 a b c \0 NCCU C prog. 4

5 Review: Things You Can and Can't Do You can't use = to assign one string variable to another (use library functions strcpy etc.) You can't use == to directly compare strings (use library functions strcmp etc.) You can directly scanf or printf strings (use %s) Many Functions in <string.h> NCCU C prog. 5

6 String Assignment: Dangers #include <string.h>... char medium[ ] = Four score and seven ; char big[1000] ; char small[5] ; strcpy(big, medium) ; strcpy(big, Bob ) ; strcpy(small, big) ; strcpy(small, medium) ; /* looks like trouble... */ NCCU C prog. 6

7 Cont d: strcpy results medium: Four score and seven\0 big: big: small: small: Four score and seven\0?????... Bob\0 score and seven\0?????... Bob\0? Four score and seven\0 Major Pitfall: overrunning allowed length NCCU C prog. 7

8 Ex: Reading strings from a file main(void) /* #define LINE_LEN 80 #define NAME_LEN 40 */ { char line[line_len], inname[name_len], outname[name_len]; FILE *inp, *outp; char *status; int i = 0; } printf("name of input file> "); scanf("%s", inname); printf("name of output file> "); scanf("%s", outname); inp = fopen(inname, "r"); outp = fopen(outname, "w"); for (status = fgets(line, LINE_LEN, inp); status!= 0; //NULL status = fgets(line, LINE_LEN, inp)) { if (line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0'; fprintf(outp, "%3d>> %s\n", ++i, line); } return (0); NCCU C prog. 8

9 File used as input In the early 1960s, designers and implementers of operating systems were faced with a significant dilemma. As people's expectations of modern operating systems escalated, so did the complexity of the systems themselves. Like other programmers solving difficult problems, the systems programmers desperately needed the readability and modularity of a powerful high-level programming language. Output file 1>> In the early 1960s, designers and implementers of operating 2>> systems were faced with a significant dilemma. As people's 3>> expectations of modern operating systems escalated, so did 4>> the complexity of the systems themselves. Like other 5>> programmers solving difficult problems, the systems 6>> programmers desperately needed the readability nd 7>> modularity of a powerful high-level programming language. NCCU C prog. 9

10 見 列 NCCU C prog. 10

11 Char Pointers <> String A Char pointer does NOT hold the space for character strings! char *sp; printf("\n enter a string: "); scanf( %s, s); /* ERROR */ printf("\n *sp = %s", sp); How to fix it? NCCU C prog. 11

12 constant and variable strings char *p, a[3], b[] = "abc"; p = "xyz"; /* OK. Assigns pointer to p */ a = "xyz"; /* NO, a is a constant */ a[] = "xyz"; /* NO, syntax error */ p = b; /* OK. b (pointer) assigned to p */ a[] = p; /* NO, involves copying all elements, use strcpy()*/ a[] = b[]; /* NO, same problem as above */ NCCU C prog. 12

13 Arrays, Pointers, & Strings An array name is a read-only pointer to the 0 th element of the array int a[10], *ip; ip = &a[0]; /* or ip = a; */ But a = ip; is error! Pointer arithmetic: ip+1 points to a[1] ; *(a+1) points to a[1], too. 列 參數 參數 Pointer NCCU C prog. 13

14 Arrays, Strings, and Pointers /* Passing an array to a function == passing the beginning address of the array*/ #include <stdio.h> #include <string.h> void mysub ( char [ ] ) ; /* mysub(char *) */ int main ( ) { char name[20] = "Richard J. Freuler" ; mysub (name) ; } NCCU C prog. 14

15 Arrays, Strings, and Pointers void mysub ( char text[ ] ) /* mysub(char *text) */ { int len, k ; len = strlen (text) ; printf ("%d\n", len ) ; for (k = 0 ; k < len ; k++) printf ("%c", text [k] ) ; } /*Program Output */ blanks 18 RichardJ. Freuler NCCU C prog. 15

16 Arrays/Pointers An array name is a read-only pointer to the 0 th element of the array. An array parameter can be declared as an array or a pointer; an array argument can be passed as a pointer. int strlen(char s[]) { int n = 0; while (s[n]!= 0) n++; return n; } Could be written: while (s[n]) int strlen(char *s) { int n = 0; while (*s++!= 0) n++; return n; } Could be written: while (*s) NCCU C prog. 16

17 An Interesting String Example void guess_me (char *s, char *r) { } while (*s++ = *r++); What does it do? How to use it? char str1[length], str2[length] = abcd ; guess_me(str1, str2); NCCU C prog. 17

18 Array of Strings & Array of Pointers NCCU C prog. 18

19 Arrays of Strings A string is a 1-D array of characters, so a 2-D array of characters would be an array of strings char names[4][10] = {"Robert","Adam", "Charles","Benjamin"}; 4 省略 R o b e r t \0 \0 \0 \0 A d a m \0 \0 \0 \0 \0 \0 C h a r l e s \0 \0 \0 B e n j a m i n \0 \0 This will declare an array of 4 strings with each string having a maximum of 10 characters names[0] names[1] names[2] names[3] for (i=0; i<4; i++) printf( %s, names[i]); NCCU C prog. 19

20 Arrays of strings 例 度 串 度不 array of (char *), 不 (char [ ][ ]). char *s[] = {"one", "two", "three"}; This is an array of pointers that point to arrays of characters, thus it is a 2-D array. S o n e \0 t w o \0 t h r e e \0 NCCU C prog. 20

21 In memory we have: char *s[] = {"one", "two", "three"}; printf( %c %c %c, s[1][1], *s[1], **s); Output: w t o s[0] s[1] s[2] o n e \0 t w o \0 t h r e e \0 NCCU C prog. 21

22 Array of strings vs. 2-D array of char char *s[] = {"ab", "cd"}; Is not the same as char t[][3] = {{'a','b','\0'}, {'c','d','\0'}}; Former is an array of pointers pointing to strings. Latter is linear sequence of characters. What s the difference? Recall that array names are constant pointers. NCCU C prog. 22

23 The memory picture s[0] s[1] a b \0 c d \0 t[0] t[1] a b \0 c d \0 char *s[] = {"ab", "cd"}; /* s[0], s[1] are variables*/ s[0] = new string ; is OK, char t[][3] = {{'a','b','\0'}, {'c','d','\0'}}; /* t[0], t[1] are constants */ t[0] = new string ; is error! NCCU C prog. 23

24 1-D Array of Strings char *days[] = { }; M O N D A Y \0 T U E S D A Y \0 W E D N E S D A Y \0 T H U R S D A Y \0 F R I D A Y \0 S A T U R D A Y \0 S U N D A Y \0 NCCU C prog. 24

25 Command-line arguments, Call-by-reference NCCU C prog. 25

26 Command-line arguments winword.exe mypaper.doc The command-line: msword.exe mypaper.doc Two command-line arguments: (1) winword.exe, (2) mypaper.doc (command-line arguments are character strings) (1) winword.exe - Name of the program for Windows to run. (Microsoft Word for Windows) (2) mypaper.doc - Name of the file for Word to open. The program winword.exe uses the command line argument mypaper.doc. NCCU C prog. 26

27 Can our C programs use arguments on the command line? Example: A filename hard-coded into the program: histogram This program histogram will ALWAYS read from data_in.txt. NCCU C prog. 27

28 Can our C programs use arguments on the command line? Example: A filename hard-coded into the program: histogram This program histogram will ALWAYS read from other_data.txt. NCCU C prog. 28

29 Better: A filename provided by the user on the command-line. histogram new_data.txt How do we get command-line arguments into our C programs? Parameters to function NCCU C prog. 29

30 int main( int argc, char *argv[ ] ) argc: argument count - Number of command-line arguments argv[ ]: argument vector - Array containing the command line strings msword.exe mypaper.doc 1 2 = 2 Note: argc 1 always! (why?) is msword.exe is mypaper.doc

31 Command-Line Arguments argc and argv o When main is called to begin execution, it is called with two arguments argc and argv argc : The first (conventionally called argc) is the number of commandline arguments the program was invoked with argv : The second (conventionally called argv) is a pointer to an array of character strings that contain the arguments, one per string. Example: if echo is a program and executed on phoenix prompt, such as C:\> echo hello world argv argc 3 pointer array null e c h o \0 h e l l o \0 w o r l d \0 char *argv[] : array of char pointers (strings) NCCU C prog. 31

32

33

34

35 void usage( char *program_name ) { printf( Usage: %s <name>\n, program_name ); printf( where <name> is the name of an input data file.\n ); }

36 Pass-by-Address (Output Parameters) Call-By-Reference NCCU C prog. 36

37 Pointers as function parameters call by reference x = 0 x = Contents Address NCCU C prog. 37

38 Call by reference: output parameters 1. Define a formal parameter as a pointer. 2. Use a pointer for the corresponding function call argument. Note: A function can have both input and output parameters. NCCU C prog. 38

39 Input Output

40 swap main s n1 111 main s n2 222 swap s temp swap s a swap s b n1=111 n2=222 n1=222 n2=111 NCCU C prog. 40

41 Character Handling Library Character handling library o Includes functions to perform useful tests and manipulations of character data o Each function receives a character (an int) or EOF as an argument The following slide contains a table of all the functions in <ctype.h> NCCU C prog. 41

42 Character Handling Library Prototype int isdigit( int c ) int isalpha( int c ) int isalnum( int c ) int isxdigit( int c ) int islower( int c ) int isupper( int c ) int tolower( int c ) int toupper( int c ) int isspace( int c ) int iscntrl( int c ) int ispunct( int c ) int isprint( int c ) int isgraph( int c ) Description Returns true if c is a digit and false otherwise. Returns true if c is a letter and false otherwise. Returns true if c is a digit or a letter and false otherwise. Returns true if c is a hexadecimal digit character and false otherwise. Returns true if c is a lowercase letter and false otherwise. Returns true if c is an uppercase letter; false otherwise. If c is an uppercase letter, tolower returns c as a lowercase letter. Otherwise, tolower returns the argument unchanged. If c is a lowercase letter, toupper returns c as an uppercase letter. Otherwise, toupper returns the argument unchanged. Returns true if c is a white-space character newline ('\n'), space (' '), form feed ('\f'), carriage return ('\r'), horizontal tab ('\t'), or vertical tab ('\v') and false otherwise Returns true if c is a control character and false otherwise. Returns true if c is a printing character other than a space, a digit, or a letter and false otherwise. Returns true value if c is a printing character including space (' ') and false otherwise. Returns true if c is a printing character other than space (' ') and false otherwise. NCCU C prog. 42

43 Part 1: Case Conversion Fuction /* * Converts the lowercase letters of its string argument to uppercase * leaving other characters unchanged. */ char * string_toupper(char *str) /* input/output - string whose lowercase letters are to be replaced by uppercase */ { int i; for (i = 0; i < strlen(str); ++i) if (islower(str[i])) str[i] = toupper(str[i]); } return (str); NCCU C prog. 43

44 Upper/Lower case Source Code NCCU C prog. 44

45 String-to-Number & Number-to-String Conversions string 17 int (17) // string double ( ) NCCU C prog. 45

46 String to int Conversion #include <ctype.h> int stringtointeger (char *s, int *n) { int i = 0, r = 0; while (isdigit (s[i])) { int d = s[i] - '0'; r = r * 10 + d; ++i; } if (s[i] == '\0' && i > 0) { *n = r; return 1; } else { return 0; } char str[] = 3129 ; int k, status; } Status = stringtointeger(str, &k); NCCU C prog. 46

47 Diagram Your Approach... We will build up the string left-to-right We will add one digit each step offset: workarea string: \0 value now: 3129 value now: 129 r = r * 10 + d; value now: 29 r = r * 10 + d; value now: 9 r = r * 10 + d; value now: r = r * 10 + d; done, return the string NCCU C prog. 47

48 String Conversion Functions Conversion functions o In <stdlib.h> (general utilities library) Convert strings of digits to integer and floating-point values Prototype double atof( const char *nptr ) int atoi( const char *nptr ) long atol( const char *nptr ) double strtod( const char *nptr, char **endptr ) long strtol( const char *nptr, char **endptr, int base ) unsigned long strtoul( const char *nptr, char **endptr, int base ) Description Converts the string nptr to double. Converts the string nptr to int. Converts the string nptr to long int. Converts the string nptr to double. Converts the string nptr to long. Converts the string nptr to unsigned long. char str[] = 3129 ; int k; k = atoi(str); NCCU C prog. 48

49 1 /* Example of 2 Using atof */ 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 int main() 7 { 8 double d; 9 10 d = atof( "99.0" ); // convert a string to double 11 printf( "%s%.3f\n%s%.3f\n", 12 "The string \"99.0\" converted to double is ", d, 13 "The converted value divided by 2 is ", 14 d / 2.0 ); 15 return 0; 16 } The string "99.0" converted to double is The converted value divided by 2 is NCCU C prog. 49

50 Converting numbers to strings Can be done with sprintf() function <stdio.h> The printf() function converts values to characters and writes them to the output buffer The sprintf() function converts values to characters and then writes them to a string stored in memory #include <stdio.h> Output: void main(void) { Pay is $ char paycheck[40]; double hours = 36.7, rate = 12.36; sprintf(paycheck, "Pay is $%.2f.", hours * rate); puts(paycheck); } NCCU C prog. 50

51 Reading from a String using sscanf The sscanf function allows us to read from a string argument using scanf rules First argument of sscanf is string to read from, remaining arguments are as in scanf Example: char buffer[100] = A ; sscanf(buffer, %c%d%f, &ch, &inum, &fnum); /* puts A in ch, 10 in inum and 50.0 in fnum */ ch A inum 10 fnum 50.0 NCCU C prog. 51

52 Static Variables NCCU C prog. 52

53 流 next_number 不 流 int next_number(); int next_number () { int counter = 0; counter ++; return counter; Local variables. Doesn t work! } number = next_number(); // gets 1 number = next_number(); // still gets 1 NCCU C prog. 53

54 流, cont d next_number 不 流 int next_number(); int counter = 0; // global variable 數 int next_number_1 () { counter ++; return counter; } number = next_number(); // gets 1 number = next_number(); // gets 2 NCCU C prog. 54

55 流, cont d Static variable 來 next_number 不 流 int next_number () { static int counter = 0; counter ++; return counter; 行 Static variable. It works well! } number = next_number(); // gets 1 number = next_number(); // gets 2 NCCU C prog. 55

56 Static Variables Local variables 參數 (parameters) 行 行 不 Static variables (scope) 行 int next_number () { static int counter = 0; counter ++; return counter; scope } counter = 100; Error! counter : not defined. Out of scope. NCCU C prog. 56

57 Structure in C 料 不 Arrays NCCU C prog. 57

58 Structure in C ( 料 ) Array: ( ) 料 Structure: 不 料 錄 (record) 例 料 ( 串 ) 數 年 ( 數 ) 料 欄 (field) Example: struct sdata /* sdata, sdata tag */ { char name[15]; /* 欄 */ char id[10]; int math; int eng; }; struct sdata student; /* sdata 數 student */ strcpy(student.name, ); student.math = 99; /* 數 */ NCCU C prog. 58

59 -1 ( ) : struct { 料 欄 1; 料 欄 2;.. 料 欄 n; }; Example: struct sdata { char name[15]; char id[10]; int math; int eng; }; struct sdata students[50], grad, s; struct 數 1, 數 2,, 數 m; NCCU C prog. 59

60 2 ( ) : struct { 料 欄 1; 料 欄 2;.. 料 欄 n; } 數 1, 數 2,, 數 m; Example: struct sdata { char name[15]; char id[10]; int math; int eng; } students[50], grad, s; NCCU C prog. 60

61 3 ( ) : struct { 料 欄 1; 料 欄 2;.. 料 欄 n; } 數 1, 數 2,, 數 m; 不 (No Tag) Example: struct { char name[15]; char id[10]; int math; int eng; } students[50], grad, s; 數 NCCU C prog. 61

62 數 Field Selection 利 數 (.) 來 數 欄 數. 欄 例 : struct sdata student; /* 數 */ o o o o student.name student.id student.math student.eng NCCU C prog. 62

63 數 #include <stdio.h> int main(void) /* 欄 欄 */ { struct sdata /* 數 */ { char name[15]; int math; } student; printf( Student s name: ); /* 數 欄 */ scanf( %s, student.name); printf( Math score: ); /* 數 欄 */ scanf( %d,&student.math); printf( *****Output*****\n ); /* 數 */ printf( %s s Math score is %d\n, student.name, student.math); return 0; } NCCU C prog. 63

64 數 行 : Student s name: David Wang Math score: 88 *****Output***** David Wang s Math score is 88 NCCU C prog. 64

65 數 Example: struct sdata { char name[16]; int math; int eng; }; struct sdata s1, s2; 念 sizeof(struct sdata)= 24 bytes 數 來 欄. strcpy(s1.name, John ); strcpy(s2.name, Mary ); s1 J o h n \0 s2 M a r y \0 NCCU C prog. 65

66 串 Example: struct sdata { char *name; int math; int eng; }; struct sdata s1, s2; s1.name = John ; s1.math = 99; s1.eng = 98; J o h n \0 NCCU C prog. 66

67 Accessing Char Ptr Fields mystruct.myint = 42; mystruct.mychar = 'a'; mystruct.mystr = "foobar"; strcpy(mystruct.mystr, "foobar"); struct { int myint; char mychar; char mystr[20]; } mystruct; NCCU C prog. 67

68 欄 ANSI C 欄 不 不 欄 // store a date as four // separate data fields: // month, day, and year // month_name struct date { int month; int day; // date: No! int year; char month_name[4]; }; struct sdata { char *name; int math; int eng; int year; }; NCCU C prog. 68

69 數 // store a date as four // separate data fields: // month, day, and year // month_name struct date { int month; int day; int year; char month_name[4]; }; I. All at once (best for small structure variables): date today = {5, 14, 2004, May }; // each number is assigned to the // corresponding field in the structure // variable II. One field at a time: date todays_date; todays_date.month = 5; todays_date.day = 14; todays_date.year = 2004; strcpy(todays_date.month_name, May ); NCCU C prog. 69

70 Valid Operations o o o o Structure Operations Assigning a structure to a structure of the same type Taking the address (&) of a structure Accessing the members of a structure Using the sizeof operator to determine the size of a structure 不 o o You CAN T use == or!= to compare structs You CAN T use printf() / scanf() on entire structs: Assignment statements OK. Example: struct date d3 = d2; // d2 d3 NCCU C prog. 70

71 typedef: A way of giving meaningful names to existing types. typedef old_type new_type_name; Can be used to rename all current types. typedef int bool; char, int, float, double, enum, struct, and pointers to these. Mostly used with struct type typedef struct { char name[15]; double diameter; int moons; double orbit_time, rotation_time; } planet_t; NCCU C prog. 71

72 Typedef or Struct Tag 兩 typedef struct { char * dept; char * title; int number; int section; } course_t; /* 'course_t' is type*/ course_t c1, c2, c3; struct course { char * dept; char * title; int number; int section; }; /* 'struct course' is type*/ struct course c1, c2, c3; NCCU C prog. 72

73 Nested structs typedef struct { int x, y; } point_t; typedef struct { point_t p1, p2; } line_t; int main(void) { line_t ln1; ln1.p1.x = 10; /* line starting point */ ln1.p1.y = 5; ln1.p2.x = 30; /* line ending point */ ln1.p2.y = 10; } NCCU C prog. 73

74 Pointers and Structures 數 來 ( ) 來 數 欄 struct card { char *face; char *suit; }; struct card onecard, deck[ 52 ]; struct card *cptr; cptr = &onecard; cptr face = 10 ; cptr suit = Heart ; printf( "%s", cptr suit ); cptr->suit is equivalent to (*cptr).suit NCCU C prog. 74

75 Using Structures With Functions Passing structures to functions o o o Pass entire structure or pass individual members Both pass call by value It is not a good idea to pass a structure to or return from function. 率 量 The better way is passing a pointer to the structure to the functions and returning a pointer from function. To pass structures call-by-reference ( ) o o Pass its address Pass a pointer pointing to the structure Returning a structure value from a function call NCCU C prog. 75

76 Using Structures With Functions (cont d) Example of passing and returning the whole structure typedef struct { : int hour, minute, second } time_t; time_t new_time(time_t time_of_day, /* input - time to be updated */ int elapsed_secs) /* input - seconds since last update */ { int new_hr, new_min, new_sec; } new_sec = time_of_day.second + elapsed_secs; time_of_day.second = new_sec % 60; new_min = time_of_day.minute + new_sec / 60; time_of_day.minute = new_min % 60; new_hr = time_of_day.hour + new_min / 60; time_of_day.hour = new_hr % 24; return (time_of_day); NCCU C prog. 76

77 Using Structures With Functions (cont d) Example of passing address thru pointer int day_of_year(struct date *pd) // 年 { int i, day, leap; day = pd -> day; leap = pd->year%4 ==0 && pd->year %100 ==0 pd->year%400 ==0; for (i=1; i<pd -> month; i++) day += day_tab[leap][i]; return (day); } o The declaration struct date *pd; says that pd is a pointer to a structure of the type date o If p is a pointer to a structure, then p-> member_of_structure refers to the particular members, like pd -> year o p-> member_of_structure is equivalent to (*p).member_of_structure o Notice:. has higher precedence than * ; *pd.year is wrong, since pd.year is not a pointer. o Both -> and. associate from left to right. So p -> q -> member are (p->q)->member. Example: emp.birthday.month are (emp.birthday).month NCCU C prog. 77

78 Example Figure 11.3 Function Comparing Two Structured Values for Equality #include <string.h> /* * Determines whether or not the components of planet_1 and planet_2 match */ int planet_equal(planet_t planet_1, /* input - planets to */ planet_t planet_2) /* compare */ { return (strcmp(planet_1.name, planet_2.name) == 0 && planet_1.diameter == planet_2.diameter && planet_1.moons == planet_2.moons && planet_1.orbit_time == planet_2.orbit_time && planet_1.rotation_time == planet_2.rotation_time); } NCCU C prog. 78

79 Example planet_t get_planet(void) { planet_t planet; } Figure 11.6 Function get_planet Returning a Structured Result Type /* * Gets and returns a planet_t structure */ scanf("%s%lf%d%lf%lf", planet.name, &planet.diameter, &planet.moons, &planet.orbit_time, &planet.rotation_time); return (planet); typedef struct { char name[15]; double diameter; int moons; double orbit_time, rotation_time; } planet_t; NCCU C prog. 79

80 Example: Complex Numbers typedef struct { double real, imag; } complex_t; Functions for complex numbers: int scan_complex(complex_t *c); void print_complex(complex_t c); complex_t add_complex(complex_t c1, complex_t c2); complex_t subtract_complex(complex_t c1, complex_t c2); complex_t multiply_complex(complex_t c1, complex_t c2); complex_t divide_complex(complex_t c1, complex_t c2); complex_t abs_complex(complex_t c); NCCU C prog. 80

81 Input a Complex Number /* * Complex number input function returns standard scanning error code * 1 => valid scan, 0 => error, */ int scan_complex(complex_t *c) /* output - address of complex variable to fill */ { int status; } status = scanf("%lf%lf", &c->real, &c->imag); if (status == 2) // 讀 兩 return 1; else return 0; NCCU C prog. 81

82 Adding Two Complex Numbers complex_t add_complex(complex_t c1, complex_t c2) /* input - values to add */ { complex_t csum; csum.real = c1.real + c2.real; csum.imag = c1.imag + c2.imag; } return (csum); NCCU C prog. 82

83 Printing a Complex Number void print_complex(complex_t c) /* input - complex number to display */ { // (3 + 5i) (6-8i) double a, b; char sign; a = c.real; b = c.imag; printf("("); if (fabs(a) <.005 && fabs(b) <.005) { // 數 數 printf("%.2f", 0.0); } else if (fabs(b) <.005) { printf("%.2f", a); } else if (fabs(a) <.005) { printf("%.2fi", b); } else { if (b < 0) sign = '-'; else sign = '+'; printf("%.2f %c %.2fi", a, sign, fabs(b)); } printf(")"); NCCU C prog. 83 }

84 Main() for Complex Numbers int main(void) { complex_t com1, com2; /* Gets two complex numbers */ printf("enter the real and imaginary parts of a complex number\n"); printf("separated by a space> "); scan_complex(&com1); printf("enter a second complex number> "); scan_complex(&com2); } /* Forms and displays the sum */ printf("\n"); print_complex(com1); printf(" + "); print_complex(com2); printf(" = "); print_complex(add_complex(com1, com2)); NCCU C prog. 84

85 Partial Implementation of Type and Operators for Complex Numbers (cont d) NCCU C prog. 85

86 Example: Comparing Two Structures Suppose we have defined a date structure as follows. How do we compare two date structures? typedef { int year, month, day; } date_t; int compare_date(date_t d1, d2) { if (d1.year==d2.year) { // 年 if (d1.month==d2.month) { // if (d1.day == d2.day) return 0; // else if (d1.day < d2.day) return -1; else return 1; } else if (d1.month < d2.month) return -1; else return 1; } else if (d1.year < d2.year) return -1; else return 1; } NCCU C prog. 86

87 What happens in terms of memory? struct { int myint; char mychar; char mystr[20]; }; NCCU C prog. 87

88 What happens in terms of memory? struct { int myint; char mychar; char mystr[20]; }; NCCU C prog. 88

89 What happens in terms of memory? struct { int myint; char mychar; char mystr[20]; }; NCCU C prog. 89

90 What happens in terms of memory? struct { int myint; char mychar; char mystr[20]; }; NCCU C prog. 90

91 Still use base+offset concept Compiler keeps track of offsets into structure of each member in "some sort" of symbol table member offset myint 0 mychar 4 mystr 5 (Sum of sizes of all previous elements) Question: Assume "mystruct" is located at location 1000 What will be address of myint, mychar and mystr? 1000, 1004, 1005 NCCU C prog. 91

92 Size of a Struct? sizeof(mystruct) = Σ (sizes of all elements) Could also write: sizeof(struct foo) Note: Some compilers will allocate more space due to alignment issues (space vs. time) Wasteful of space but more efficient Therefore... Always use sizeof!!! NCCU C prog. 92

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

untitled

untitled 串 串 例 : char ch= a ; char str[]= Hello ; 串 列 ch=getchar(); scanf( %c,&ch); 串 gets(str) scanf( %s,str); 8-1 數 ASCII 例 : char ch= A ; printf( %d,ch); // 65 A ascii =0x41 printf( %c,ch); // A 例 : char ch;

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

untitled

untitled 不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

C/C++语言 - 分支结构

C/C++语言 - 分支结构 C/C++ Table of contents 1. if 2. if else 3. 4. 5. 6. continue break 7. switch 1 if if i // colddays.c: # include int main ( void ) { const int FREEZING = 0; float temperature ; int cold_ days

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 177 [P179] (1) - [P181] [P182] (2) - for [P183] (3) - switch [P184] [P187] [P189] [P194] 178 [ ]; : : int var; : int var[3]; var 2293620 var[0] var[1] 2293620

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

WWW PHP

WWW PHP WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

untitled

untitled Introduction to Programming ( 數 ) Lecture 3 Spring 2005 March 4, 2005 Lecture 2 Outline 數 料 If if 狀 if 2 (Standard Output, stdout): 料. ((Standard Input, stdin): 料. 類 數 數 數 說 printf 見 數 puts 串 數 putchar

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

Microsoft Word - Final Exam Review Packet.docx

Microsoft Word - Final Exam Review Packet.docx Do you know these words?... 3.1 3.5 Can you do the following?... Ask for and say the date. Use the adverbial of time correctly. Use Use to ask a tag question. Form a yes/no question with the verb / not

More information

C C

C C C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO Car DVD New GUI IR Flow User Manual V0.1 Jan 25, 2008 19, Innovation First Road Science Park Hsin-Chu Taiwan 300 R.O.C. Tel: 886-3-578-6005 Fax: 886-3-578-4418 Web: www.sunplus.com Important Notice SUNPLUS

More information

untitled

untitled 說 參 例 邏 邏 1. 說 2. 數 數 3. 8 4. 理念 李 龍老 立 1. 理 料 2. 理 料 3. 數 料 4. 流 邏 念 5. 良 6. 讀 行 行 7. 行 例 來 邏 1. 說 說 識 量 2. 說 理 類 3. 數 數 念 4. 令 5. 良 6. 流 邏 念 7. 說 邏 理 力 1. 2. 3. 4. 5. 列 念 1 參 1. ( Visual Basic 例 ) (1)

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

<4D6963726F736F667420576F7264202D2032303130C4EAC0EDB9A4C0E04142BCB6D4C4B6C1C5D0B6CFC0FDCCE2BEABD1A15F325F2E646F63>

<4D6963726F736F667420576F7264202D2032303130C4EAC0EDB9A4C0E04142BCB6D4C4B6C1C5D0B6CFC0FDCCE2BEABD1A15F325F2E646F63> 2010 年 理 工 类 AB 级 阅 读 判 断 例 题 精 选 (2) Computer mouse How does the mouse work? We have to start at the bottom, so think upside down for now. It all starts with mouse ball. As the mouse ball in the bottom

More information

Fuzzy GP

Fuzzy GP : 林 理論 數 論 1 率 2 類,, 金流量 金 利 數 益,, 3 不 異 (Multi- Valued) (Single-Valued) 數 數 數 (Local Optimum) (Global Optimum) 4 (Multi-valued) (Non-linear) (Self-learning) 5 (Genetic Programming, GP) GP 1. 亂數 2. (individuals)

More information

Microsoft PowerPoint - STU_EC_Ch02.ppt

Microsoft PowerPoint - STU_EC_Ch02.ppt 樹德科技大學資訊工程系 Chapter 2: Number Systems Operations and Codes Shi-Huang Chen Sept. 2010 1 Chapter Outline 2.1 Decimal Numbers 2.2 Binary Numbers 2.3 Decimal-to-Binary Conversion 2.4 Binary Arithmetic 2.5

More information

untitled

untitled Introduction to Programming ( 數 ) Lecture 5 Spring 2005 March 25, 2005 Topics Review Loop Statements For-Loop Condition-Loop Arrays: Part I Function Definition: Part I 1 Review of Loop Statements (Repetition

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

C

C C 2017 4 1 1. 2. while 3. 4. 5. for 6. 2/161 C 7. 8. (do while) 9. 10. (nested loop) 11. 12. 3/161 C 1. I 1 // summing.c: 2 #include 3 int main(void) 4 { 5 long num; 6 long sum = 0L; 7 int status;

More information

C/C++ - 数组与指针

C/C++ - 数组与指针 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 float candy [ 365]; char code [12]; int states [50]; 2 int array [6] = {1, 2, 4, 6, 8, 10}; 3 // day_mon1.c: # include # define MONTHS 12 int

More information

Microsoft Word - template.doc

Microsoft Word - template.doc HGC efax Service User Guide I. Getting Started Page 1 II. Fax Forward Page 2 4 III. Web Viewing Page 5 7 IV. General Management Page 8 12 V. Help Desk Page 13 VI. Logout Page 13 Page 0 I. Getting Started

More information

2/80 2

2/80 2 2/80 2 3/80 3 DSP2400 is a high performance Digital Signal Processor (DSP) designed and developed by author s laboratory. It is designed for multimedia and wireless application. To develop application

More information

例 度 讀 讀 不 不 來 念 來 了 讀 不 不 讀 不 讀行 利 了 說 更 了 讀

例 度 讀 讀 不 不 來 念 來 了 讀 不 不 讀 不 讀行 利 了 說 更 了 讀 讀 爛 來 都 力 讀 不 讀 了 讀 來 讀 了 更 不 都 六年 類 更 錄 不 都 便 路 不 不 了 讀 來不 讀 讀 刺 數 不 刺 讀 索 料 易 力 練 讀 易 料 了 讀 力 讀便不 讀 例 度 讀 讀 不 不 來 念 來 了 讀 不 不 讀 不 讀行 利 了 說 更 了 讀 年 來 句 易 說 說 易 說 讀 識 識 力 句 老 錄 朗讀 讀 了 易 臨 說讀 力 識 樂 參 練

More information

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2 第 六 讲 指 针 与 字 符 串 1 内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2 指 针 什 么 是 指 针 指 针 的 定 义 与 运 算 指 针 与 一 维 数 组 指 针 数 组 行 指 针 与 二 维 数 组 指 针 与 引 用 指 针 与 函 数 3 指 针 定 义 什 么 是 指 针 指 针 变 量, 简 称 指 针, 用 来 存 放

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

2015年4月11日雅思阅读预测机经(新东方版)

2015年4月11日雅思阅读预测机经(新东方版) 剑 桥 雅 思 10 第 一 时 间 解 析 阅 读 部 分 1 剑 桥 雅 思 10 整 体 内 容 统 计 2 剑 桥 雅 思 10 话 题 类 型 从 以 上 统 计 可 以 看 出, 雅 思 阅 读 的 考 试 话 题 一 直 广 泛 多 样 而 题 型 则 稳 中 有 变 以 剑 桥 10 的 test 4 为 例 出 现 的 三 篇 文 章 分 别 是 自 然 类, 心 理 研 究 类,

More information

untitled

untitled 1 Outline 料 類 說 Tang, Shih-Hsuan 2006/07/26 ~ 2006/09/02 六 PM 7:00 ~ 9:30 聯 ives.net@gmail.com www.csie.ntu.edu.tw/~r93057/aspnet134 度 C# 力 度 C# Web SQL 料 DataGrid DataList 參 ASP.NET 1.0 C# 例 ASP.NET 立

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc 2 5 8 11 0 13 1. 13 2. 15 3. 18 1 23 1. 23 2. 26 3. 28 2 36 1. 36 2. 39 3. 42 4. 44 5. 49 6. 51 3 57 1. 57 2. 60 3. 64 4. 66 5. 70 6. 75 7. 83 8. 85 9. 88 10. 98 11. 103 12. 108 13. 112 4 115 1. 115 2.

More information

热设计网

热设计网 例 例 Agenda Popular Simulation software in PC industry * CFD software -- Flotherm * Advantage of Flotherm Flotherm apply to Cooler design * How to build up the model * Optimal parameter in cooler design

More information

untitled

untitled 數 Quadratic Equations 數 Contents 錄 : Quadratic Equations Distinction between identities and equations. Linear equation in one unknown 3 ways to solve quadratic equations 3 Equations transformed to quadratic

More information

untitled

untitled Co-integration and VECM Yi-Nung Yang CYCU, Taiwan May, 2012 不 列 1 Learning objectives Integrated variables Co-integration Vector Error correction model (VECM) Engle-Granger 2-step co-integration test Johansen

More information

Microsoft Word - 第四組心得.doc

Microsoft Word - 第四組心得.doc 徐 婉 真 這 四 天 的 綠 島 人 權 體 驗 營 令 我 印 象 深 刻, 尤 其 第 三 天 晚 上 吳 豪 人 教 授 的 那 堂 課, 他 讓 我 聽 到 不 同 於 以 往 的 正 義 之 聲 轉 型 正 義, 透 過 他 幽 默 熱 情 的 語 調 激 起 了 我 對 政 治 的 興 趣, 願 意 在 未 來 多 關 心 社 會 多 了 解 政 治 第 一 天 抵 達 綠 島 不 久,

More information

untitled

untitled Fortran Chapter 7 Subroutine ( ) and Function 7-1 subroution 行 不 行 來 行 The general form of a subroutine is subroutine subroutine_name ( argument_list) (Declaration section) (Execution section) retrun end

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

Knowledge and its Place in Nature by Hilary Kornblith

Knowledge and its Place in Nature by Hilary Kornblith Deduction by Daniel Bonevac Chapter 7 Quantified Natural Deduction Quantified Natural Deduction As with truth trees, natural deduction in Q depends on the addition of some new rules to handle the quantifiers.

More information

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

More information

ENGG1410-F Tutorial 6

ENGG1410-F Tutorial 6 Jianwen Zhao Department of Computer Science and Engineering The Chinese University of Hong Kong 1/16 Problem 1. Matrix Diagonalization Diagonalize the following matrix: A = [ ] 1 2 4 3 2/16 Solution The

More information

<4D6963726F736F667420506F776572506F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E707074205BBCE6C8DDC4A3CABD5D>

<4D6963726F736F667420506F776572506F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E707074205BBCE6C8DDC4A3CABD5D> Homeworks ( 第 三 版 ):.4 (,, 3).5 (, 3).6. (, 3, 5). (, 4).4.6.7 (,3).9 (, 3, 5) Chapter. Number systems and codes 第 一 章. 数 制 与 编 码 . Overview 概 述 Information is of digital forms in a digital system, and

More information

epub 33-8

epub 33-8 8 1) 2) 3) A S C I I 4 C I / O I / 8.1 8.1.1 1. ANSI C F I L E s t d i o. h typedef struct i n t _ f d ; i n t _ c l e f t ; i n t _ m o d e ; c h a r *_ n e x t ; char *_buff; /* /* /* /* /* 1 5 4 C FILE

More information

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl SKLOIS (Pseudo) Preimage Attack on Reduced-Round Grøstl Hash Function and Others Shuang Wu, Dengguo Feng, Wenling Wu, Jian Guo, Le Dong, Jian Zou March 20, 2012 Institute. of Software, Chinese Academy

More information

Windows XP

Windows XP Windows XP What is Windows XP Windows is an Operating System An Operating System is the program that controls the hardware of your computer, and gives you an interface that allows you and other programs

More information

衛星影像分類

衛星影像分類 年 理 理 立 立 列 SPOT 立 年 理 2 , 量 不 料 -Raster 量,, -Vector? 立 年 理 3 料 (Binary Data) 省 理 率 料來 CCD (Charge Couple Device) (Scanner) 數, 數 錄? 立 年 理 4 :Picture Element or Pixel : 不 不 狀 X,Y Column,Row Sample,Line

More information

C/C++ - 结构体、共用体、枚举体

C/C++ - 结构体、共用体、枚举体 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 C C (struct) C 2 C C (struct) C 2 i // book.c: # include < stdio.h> # define MAX_ TITLE 41 # define MAX_ AUTHOR 31 struct book { char title [ MAX_ TITLE

More information

Microsoft PowerPoint - ch6 [相容模式]

Microsoft PowerPoint - ch6 [相容模式] UiBinder wzyang@asia.edu.tw UiBinder Java GWT UiBinder XML UI i18n (widget) 1 2 UiBinder HelloWidget.ui.xml: UI HelloWidgetBinder HelloWidget.java XML UI Owner class ( Composite ) UI XML UiBinder: Owner

More information

Microsoft PowerPoint - Lecture7II.ppt

Microsoft PowerPoint - Lecture7II.ppt Lecture 8II SUDOKU PUZZLE SUDOKU New Play Check 軟體實作與計算實驗 1 4x4 Sudoku row column 3 2 } 4 } block 1 4 軟體實作與計算實驗 2 Sudoku Puzzle Numbers in the puzzle belong {1,2,3,4} Constraints Each column must contain

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

Microsoft PowerPoint - ryz_030708_pwo.ppt

Microsoft PowerPoint - ryz_030708_pwo.ppt Long Term Recovery of Seven PWO Crystals Ren-yuan Zhu California Institute of Technology CMS ECAL Week, CERN Introduction 20 endcap and 5 barrel PWO crystals went through (1) thermal annealing at 200 o

More information

The Development of Color Constancy and Calibration System

The Development of Color Constancy and Calibration System The Development of Color Constancy and Calibration System The Development of Color Constancy and Calibration System LabVIEW CCD BMP ii Abstract The modern technologies develop more and more faster, and

More information

Microsoft PowerPoint - STU_EC_Ch08.ppt

Microsoft PowerPoint - STU_EC_Ch08.ppt 樹德科技大學資訊工程系 Chapter 8: Counters Shi-Huang Chen Fall 2010 1 Outline Asynchronous Counter Operation Synchronous Counter Operation Up/Down Synchronous Counters Design of Synchronous Counters Cascaded Counters

More information

untitled

untitled 1 Outline 類别 欄 (1) 類 類 狀 更 易 類 理 若 類 利 來 利 using 來 namespace 類 ; (2) namespace IBM class Notebook namespace Compaq class Notebook 類别 類 來 類 列 欄 (field) (property) (method) (event) 類 例 立 來 車 類 類 立 車 欄 料

More information

C

C C 14 2017 5 31 1. 2. 3. 4. 5. 2/101 C 1. ( ) 4/101 C C ASCII ASCII ASCII 5/101 C 10000 00100111 00010000 ASCII 10000 31H 30H 30H 30H 30H 1 0 0 0 0 0 ASCII 6/101 C 7/101 C ( ) ( ) 8/101 C UNIX ANSI C 9/101

More information

錄...1 說...2 說 說...5 六 率 POST PAY PREPAY DEPOSIT 更

錄...1 說...2 說 說...5 六 率 POST PAY PREPAY DEPOSIT 更 AX5000 Version 1.0 2006 年 9 錄...1 說...2 說...3...4 說...5 六...6 6.1 率...7 6.2 POST PAY...8 6.3 PREPAY DEPOSIT...9 6.4...10 6.5...11 更...12...12 LCD IC LED Flash 更 兩 RJ11 ( ) DC ON OFF ON 狀 狀 更 OFF 復 狀 說

More information

Microsoft PowerPoint - ATF2015.ppt [相容模式]

Microsoft PowerPoint - ATF2015.ppt [相容模式] Improving the Video Totalized Method of Stopwatch Calibration Samuel C.K. Ko, Aaron Y.K. Yan and Henry C.K. Ma The Government of Hong Kong Special Administrative Region (SCL) 31 Oct 2015 1 Contents Introduction

More information

Microsoft PowerPoint - CH 04 Techniques of Circuit Analysis

Microsoft PowerPoint - CH 04 Techniques of Circuit Analysis Chap. 4 Techniques of Circuit Analysis Contents 4.1 Terminology 4.2 Introduction to the Node-Voltage Method 4.3 The Node-Voltage Method and Dependent Sources 4.4 The Node-Voltage Method: Some Special Cases

More information

投影片 1

投影片 1 2 理 1 2-1 CPU 2-2 CPU 理 2-3 CPU 類 2 什 CPU CPU Central Processing Unit ( 理 ), 理 (Processor), CPU 料 ( 例 ) 邏 ( 例 ),, 若 了 CPU, 3 什 CPU CPU 了, 行, 利 CPU 力 來 行 4 什 CPU 5 2-2-1 CPU CPU 了 (CU, Control Unit) / 邏

More information

可 愛 的 動 物 小 五 雷 雅 理 第 一 次 小 六 甲 黃 駿 朗 今 年 暑 假 發 生 了 一 件 令 人 非 常 難 忘 的 事 情, 我 第 一 次 參 加 宿 營, 離 開 父 母, 自 己 照 顧 自 己, 出 發 前, 我 的 心 情 十 分 緊 張 當 到 達 目 的 地 後

可 愛 的 動 物 小 五 雷 雅 理 第 一 次 小 六 甲 黃 駿 朗 今 年 暑 假 發 生 了 一 件 令 人 非 常 難 忘 的 事 情, 我 第 一 次 參 加 宿 營, 離 開 父 母, 自 己 照 顧 自 己, 出 發 前, 我 的 心 情 十 分 緊 張 當 到 達 目 的 地 後 郭家朗 許鈞嵐 劉振迪 樊偉賢 林洛鋒 第 36 期 出版日期 28-3-2014 出版日期 28-3-2014 可 愛 的 動 物 小 五 雷 雅 理 第 一 次 小 六 甲 黃 駿 朗 今 年 暑 假 發 生 了 一 件 令 人 非 常 難 忘 的 事 情, 我 第 一 次 參 加 宿 營, 離 開 父 母, 自 己 照 顧 自 己, 出 發 前, 我 的 心 情 十 分 緊 張 當 到 達 目

More information

Microsoft Word - TIP006SCH Uni-edit Writing Tip - Presentperfecttenseandpasttenseinyourintroduction readytopublish

Microsoft Word - TIP006SCH Uni-edit Writing Tip - Presentperfecttenseandpasttenseinyourintroduction readytopublish 我 难 度 : 高 级 对 们 现 不 在 知 仍 道 有 听 影 过 响 多 少 那 次 么 : 研 英 究 过 文 论 去 写 文 时 作 的 表 技 引 示 巧 言 事 : 部 情 引 分 发 言 该 生 使 在 中 用 过 去, 而 现 在 完 成 时 仅 表 示 事 情 发 生 在 过 去, 并 的 哪 现 种 在 时 完 态 成 呢 时? 和 难 过 道 去 不 时 相 关? 是 所 有

More information

Microsoft Word - ChineseSATII .doc

Microsoft Word - ChineseSATII .doc 中 文 SAT II 冯 瑶 一 什 么 是 SAT II 中 文 (SAT Subject Test in Chinese with Listening)? SAT Subject Test 是 美 国 大 学 理 事 会 (College Board) 为 美 国 高 中 生 举 办 的 全 国 性 专 科 标 准 测 试 考 生 的 成 绩 是 美 国 大 学 录 取 新 生 的 重 要 依

More information

02

02 Thinking in C++: Volume One: Introduction to Standard C++, Second Edition & Volume Two: Practical Programming C++ C C++ C++ 3 3 C C class C++ C++ C++ C++ string vector 2.1 interpreter compiler 2.1.1 BASIC

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

Microsoft Word - (web)_F.1_Notes_&_Application_Form(Chi)(non-SPCCPS)_16-17.doc

Microsoft Word - (web)_F.1_Notes_&_Application_Form(Chi)(non-SPCCPS)_16-17.doc 聖 保 羅 男 女 中 學 學 年 中 一 入 學 申 請 申 請 須 知 申 請 程 序 : 請 將 下 列 文 件 交 回 本 校 ( 麥 當 勞 道 33 號 ( 請 以 A4 紙 張 雙 面 影 印, 並 用 魚 尾 夾 夾 起 : 填 妥 申 請 表 並 貼 上 近 照 小 學 五 年 級 上 下 學 期 成 績 表 影 印 本 課 外 活 動 表 現 及 服 務 的 證 明 文 件 及

More information

untitled

untitled 1 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object 參 類 都 object 參 object Boxing 參 boxing

More information

1 * 1 *

1 * 1 * 1 * 1 * taka@unii.ac.jp 1992, p. 233 2013, p. 78 2. 1. 2014 1992, p. 233 1995, p. 134 2. 2. 3. 1. 2014 2011, 118 3. 2. Psathas 1995, p. 12 seen but unnoticed B B Psathas 1995, p. 23 2004 2006 2004 4 ah

More information

Searching and Sorting

Searching and Sorting Introduction to Programming ( 數 ) Lecture 11 Spring 2005 May 27, 2004 NCCU C prog. 1 Topics Review More on Structures Unions Dynamic Memory Allocation Linked list, Queue NCCU C prog. 2 Structure in C (

More information

ap15_chinese_interpersoanal_writing_ _response

ap15_chinese_interpersoanal_writing_ _response 2015 SCORING GUIDELINES Interpersonal Writing: 6 EXCELLENT excellence in 5 VERY GOOD Suggests excellence in 4 GOOD 3 ADEQUATE Suggests 2 WEAK Suggests lack of 1 VERY WEAK lack of 0 UNACCEPTABLE Contains

More information

入學考試網上報名指南

入學考試網上報名指南 入 學 考 試 網 上 報 名 指 南 On-line Application Guide for Admission Examination 16/01/2015 University of Macau Table of Contents Table of Contents... 1 A. 新 申 請 網 上 登 記 帳 戶 /Register for New Account... 2 B. 填

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

untitled

untitled 1 Outline ArrayList 類 列類 串類 類 類 例 理 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object

More information

高中英文科教師甄試心得

高中英文科教師甄試心得 高 中 英 文 科 教 師 甄 試 心 得 英 語 學 系 碩 士 班 林 俊 呈 高 雄 市 立 高 雄 高 級 中 學 今 年 第 一 次 參 加 教 師 甄 試, 能 夠 在 尚 未 服 兵 役 前 便 考 上 高 雄 市 立 高 雄 高 級 中 學 專 任 教 師, 自 己 覺 得 很 意 外, 也 很 幸 運 考 上 後 不 久 在 與 雄 中 校 長 的 會 談 中, 校 長 的 一 句

More information

プログラムの設計と実現II

プログラムの設計と実現II UNIX C ls mkdir man http://www.tj.chiba-u.jp/lecture/prog2/ Ctrl+x, Ctrl+s ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall

More information

1505.indd

1505.indd 上 海 市 孙 中 山 宋 庆 龄 文 物 管 理 委 员 会 上 海 宋 庆 龄 研 究 会 主 办 2015.05 总 第 148 期 图 片 新 闻 2015 年 9 月 22 日, 由 上 海 孙 中 山 故 居 纪 念 馆 台 湾 辅 仁 大 学 和 台 湾 图 书 馆 联 合 举 办 的 世 纪 姻 缘 纪 念 孙 中 山 先 生 逝 世 九 十 周 年 及 其 革 命 历 程 特 展

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

Contents

Contents PISO-PS400 (Version 3.1) PISO-PS400 1 Warranty All products manufactured by ICPDAS Inc. are warranted against defective materials for a period of one year from the date of delivery to the original purchaser.

More information

untitled

untitled 料 2-1 料 料 x, y, z 料 不 不 料濾 料 不 料 料 不 料 錄 料 2-1 a 料 2-1 b 2003 a 料 b 料 2-1 料 2003 料 料 行 料濾 料亂 濾 料 料 滑 料 理 料 2001 料 兩 理 料 不 TIN, Triangular Irregular Network 8 2-2 a 數 量 料 便 精 2003 料 行 理 料 立 狀 連 料 狀 立 料

More information

untitled

untitled 1 Outline 流 ( ) 流 ( ) 流 ( ) 流 ( ) 流 ( ) 狀 流 ( ) 利 來 行流 if () 立 行 ; else 不 立 行 ; 例 sample2-a1 (1) 列 // 料 Console.Write(""); string name = Console.ReadLine(); Console.WriteLine(" " + name + "!!"); 例 sample2-a1

More information

台灣經濟新報資料庫

台灣經濟新報資料庫 料 易 北 路 樓 02-8768-1088 Emailtej@tej.com.tw 錄 1 料 1 列 2 3 欄 5 5 六 6 TEJ Smart Wizard 易 9 列 9 料 9 1. 10 2. 11 3. 料 11 4. 12 5. Excel 12 參 TEJ Math Pal 易 13? 13 說 14 1-1TEJ 料 說 15 1-2 料 說 16 1-3 行 料 說 19

More information

* RRB *

* RRB * *9000000000RRB0010040* *9000000000RRB0020040* *9000000000RRB0030040* *9000000000RRB0040040* *9000000000RRC0010050* *9000000000RRC0020050* *9000000000RRC0030050* *9000000000RRC0040050* *9000000000RRC0050050*

More information

UDC Empirical Researches on Pricing of Corporate Bonds with Macro Factors 厦门大学博硕士论文摘要库

UDC Empirical Researches on Pricing of Corporate Bonds with Macro Factors 厦门大学博硕士论文摘要库 10384 15620071151397 UDC Empirical Researches on Pricing of Corporate Bonds with Macro Factors 2010 4 Duffee 1999 AAA Vasicek RMSE RMSE Abstract In order to investigate whether adding macro factors

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

提纲 1 2 OS Examples for 3

提纲 1 2 OS Examples for 3 第 4 章 Threads2( 线程 2) 中国科学技术大学计算机学院 October 28, 2009 提纲 1 2 OS Examples for 3 Outline 1 2 OS Examples for 3 Windows XP Threads I An Windows XP application runs as a seperate process, and each process may

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

Microsoft PowerPoint - STU_EC_Ch04.ppt

Microsoft PowerPoint - STU_EC_Ch04.ppt 樹德科技大學資訊工程系 Chapter 4: Boolean Algebra and Logic Simplification Shi-Huang Chen Fall 200 Outline Boolean Operations and Expressions Laws and Rules of Boolean Algebra DeMorgan's Theorems Boolean Analysis

More information

年 參 類 來 識 見 錄 力 不 了 更 不 度 來說

年 參 類 來 識 見 錄 力 不 了 更 不 度 來說 年 "" 不 --- 立 年 參 類 來 識 見 錄 力 不 了 更 不 度 來說 Abstract No More Dandruff Since I have the serious dandruff problem, I try to seek, except the shampoo, the natural materials to decrease the dandruff. After consulting

More information

BC04 Module_antenna__ doc

BC04 Module_antenna__ doc http://www.infobluetooth.com TEL:+86-23-68798999 Fax: +86-23-68889515 Page 1 of 10 http://www.infobluetooth.com TEL:+86-23-68798999 Fax: +86-23-68889515 Page 2 of 10 http://www.infobluetooth.com TEL:+86-23-68798999

More information