enum Enum Day Of Weeksun 1 mon tue

  • Slides: 35
Download presentation

ตวอยางการกำหนดคา enum Enum Day. Of. Week{sun=, 1 mon, tue , wen, thu, fri, sat

ตวอยางการกำหนดคา enum Enum Day. Of. Week{sun=, 1 mon, tue , wen, thu, fri, sat ; { คาคอ sun=1, mon=2, tue=3, wen=4, thu=5 , fri=6 , sat = 7

ตวอยางการกำหนดคา enum Day. Of. Week{sun=, 1 mon, tue, wen=50, thu, fri, sat; { คาคอ

ตวอยางการกำหนดคา enum Day. Of. Week{sun=, 1 mon, tue, wen=50, thu, fri, sat; { คาคอ sun=1, mon=2, tue=3, wen=50, thu=51 , fri=52, sat=53

. 3. 1การใช คำสง struct สรางตวแปรชนด โดยตรง student คอ ประกาศตวแปรไปพรอมกบการสราง struct STD { char

. 3. 1การใช คำสง struct สรางตวแปรชนด โดยตรง student คอ ประกาศตวแปรไปพรอมกบการสราง struct STD { char code[9]; char name[31]; int midterm; int final; char grade; } student; struct product { int weight; float price; } apple, banana, melon;

3. 2การใช คำสง struct สรางตวแปรชนด student ผานตวแปร STD คอ ประกาศตวแปร หลงจากสราง struct STD แลว

3. 2การใช คำสง struct สรางตวแปรชนด student ผานตวแปร STD คอ ประกาศตวแปร หลงจากสราง struct STD แลว structure struct product { char code[9]; { int weight; char name[31]; int midterm; float price; int final; }; char grade; product apple; }; product banana, melon; STD student; // ����� Student ����� STD

3. 3การใช คำสง typedef เพอสรางตวแปรชนด struct student ผานตวแปร typedef struct { char code[9]; char

3. 3การใช คำสง typedef เพอสรางตวแปรชนด struct student ผานตวแปร typedef struct { char code[9]; char name[31]; int midterm; int final; char grade; } STD; STD student; STD #define MAX_LEN 12 /* Length of name */ typedef struct { char name[MAX_LEN]; int id; float gpa; char major[10]; } product; product stu 1, stu 2, stu 3;

ตวอยางโปรแกรม typedef struct { int month, day, year; } DATE; void main( ) {

ตวอยางโปรแกรม typedef struct { int month, day, year; } DATE; void main( ) { DATE d 1; d 1. month = 12; d 1. day = 2; d 1. year = 1970; }

การกำหนดคาเรมตนใหกบตวแป ร struct CAR { char color[10] = “Black”; long price = 40000; }

การกำหนดคาเรมตนใหกบตวแป ร struct CAR { char color[10] = “Black”; long price = 40000; } mycar; w [C++ Error] ………. cpp(6): E 2233 Cannot initialize a class member here

ตวอยาง : การกำหนดคาเรมตนใหกบตวแป ร struct CAR { char color[10] = “Red”; long price =

ตวอยาง : การกำหนดคาเรมตนใหกบตวแป ร struct CAR { char color[10] = “Red”; long price = 30000; } hiscar; w [C++ Error] ………. cpp(6): E 2233 Cannot initialize a class member here

. 5การกำหนดคาคงทใหกบสมาชกของ structure struct STD { char code[9]; char name[31]; int midterm; int final;

. 5การกำหนดคาคงทใหกบสมาชกของ structure struct STD { char code[9]; char name[31]; int midterm; int final; char grade; }student, stud; ������� STD ������� student , stud �������

5. 1. กำหนดคาคงทใหกบ เขยนไดดงน structure strcpy(student. code, "40214514"); //เนองจากเปน string ตองใช strcpy() strcpy(student. name,

5. 1. กำหนดคาคงทใหกบ เขยนไดดงน structure strcpy(student. code, "40214514"); //เนองจากเปน string ตองใช strcpy() strcpy(student. name, "Somsak; (" student. midterm = 45 ; student. final = 30 ; student. grade=75 ;

5. 2. การกาหนดคาของตวแปร ใหกบ structure เขยนไดดงน char co[9]=” 10015210”; strcpy(student. code, co); int x

5. 2. การกาหนดคาของตวแปร ใหกบ structure เขยนไดดงน char co[9]=” 10015210”; strcpy(student. code, co); int x = 25; student. midterm = x;

6. อารเรยของ structure struct STD //สราง structure ชอ } char code[9]; char name[31]; int

6. อารเรยของ structure struct STD //สราง structure ชอ } char code[9]; char name[31]; int midterm; int final; char grade; }; STD student[5]; //ประกาศตวแปรชอ student เปนอารเรยรายการ 5 STD

7. โครงสรางแบบซอนใน § โครงสรางอาจมการซอนกนไดเชน struc { date int int }; date; month; year; struc

7. โครงสรางแบบซอนใน § โครงสรางอาจมการซอนกนไดเชน struc { date int int }; date; month; year; struc emprec { char name[21]; char address[21]; char town[21]; char postcode[9]; struc date start; } employee;