麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

iOS開發之c語言基礎Lesson-07結構體上課筆記與試題練習

2019-11-14 19:21:58
字體:
來源:轉載
供稿:網友
  1 ///////////////Lesson 07 結構體  上課筆記 ////////////////  2 //結構體作用:1.是一種自定義的數據類型,可以用來定義變量  3 //            2.是一個大容器,比數組靈活,可以存儲不同數據類型的變量  4 //結構體定義 :定義就是一種格式,一種模板, 只要按照該格式就能定義出結構體  5 //定義一個學生結構體  6 //typedef, 類型重定義,給類型重新取一個名字,新的名字和原有的名字的作用是一樣的  7 //typedef兩種定義方式:1.先定義結構體, 后typedef  8 //                       2.定義結構體的同時,定義typedef  9 typedef struct student{ 10     int num; 11     char name[20]; 12     int age; 13     char gender; 14     float score; 15 }Student; 16 //點結構體 17 //struct point{ 18 //    int x; 19 //    int y; 20 //}; 21 //typedef  struct point  point; //point代替struct point 22 ////矩形結構體 23 //struct rectangle{ 24 //    float width; 25 //    float length; 26 //}; 27 ////立方體結構體 28 //struct cube{ 29 //    float width; 30 //    float height; 31 //    float length; 32 //}; 33 int main(int argc, const char * argv[]) { 34 //    @autoreleasepool { 35 //        // insert code here... 36 //        NSLog(@"Hello, World!"); 37 //    } 38      39 /////使用結構體類型(struct + 結構體名字), 定義結構體變量 40 //    struct student stu1 = {"Ashen", 24, 'm'}; 41 //    Student stu2 = {"Ying", 23, 'f'}; 42 //     43 //    struct point p1 = {12, 14}; 44 //    struct rectangle r1 = {3.0, 4.0}; 45 //    struct cube c1 = {3.0, 4.0, 5.0}; 46 //     47 ////////訪問結構體成員  結構體變量.結構體成員 48 //     49 //    strcpy(stu1.name, "Ashen-Zhao"); 50 //     printf("%s ", stu1.name); 51      52      53 ///////結構體變量的賦值操作 54 //    Student stu1 = {"Ashen", 33, 'm'}; 55 //    Student stu2 = {0}; 56 //    Student stu3 = {0}; 57 //    //1.單一成員賦值 58 //    strcpy(stu2.name, stu1.name); 59 //    stu2.age = stu1.age; 60 //    stu2.gender = stu1.gender; 61 //    //2.結構體變量整體拷貝 62 //    //如果想把一個數組中的元素,拷貝到另外一個數組中,數組不能直接通過賦值號(=)賦值, 此時可以把數組放到結構體中,通過結構體變量來完成拷貝操作。 63 //    stu3 = stu1; 64 //    printf("%s ", stu3.name); 65      66 ////////////練習 67     //    Student stu1 = {"Ashen1", 21, 'm', 90}; 68     //    Student stu2 = {"ying", 22, 'f', 80}; 69     //    Student stu3 = {"zhao", 23, 'm', 100}; 70     // 71     // 72     //    //找出分數   最高   者者者者者者者者者者者者 73     //    Student maxScoreStu = {0}; //存儲分數最高的人 74     //    //    if (stu1.score > stu2.score) { 75     //    //        if (stu1.score > stu3.score) { 76     //    //            maxScoreStu = stu1; 77     //    //        }else{ 78     //    //            maxScoreStu = stu3; 79     //    //        } 80     //    //    }else if(stu2.score > stu3.score){ 81     //    //        maxScoreStu = stu2; 82     //    //    }else{ 83     //    //        maxScoreStu = stu3; 84     //    //    } 85     // 86     // 87     //    maxScoreStu = stu1.score > stu2.score ? stu1.score > stu3.score ? stu1 : stu3 : stu2.score > stu3.score ?stu2 : stu3; 88     // 89     // 90     //    printf("name:%s, age:%d, score:%.2f", maxScoreStu.name, maxScoreStu.age, maxScoreStu.score); 91      92     //////////////結構體數組 93     ////定義結構體數組,存儲5個學生 94     //    Student students[5]={ 95     //        {1001, "Ashen", 24, 'f', 100}, 96     //        {1003, "Ying", 23, 'm', 76}, 97     //        {1004, "BenBen", 22, 'f', 90}, 98     //        {1005, "Dandan", 18, 'm', 89}, 99     //        {1002, "Love", 31, 'f', 56}100     //    };101     ////1輸出所有學生的信息102     ////    for (int i = 0; i < 5; i++) {103     ////        printf("num:%d,name:%s,age:%d,gender:%c,score:%.2f /n", students[i].num, students[i].name, students[i].age, students[i].gender, students[i].score);104     ////    }105     ////2找出成績最高者106     //    Student maxScoreStu = {0};107     //    for (int i = 0; i < 5; i++) {108     //        if (students[i].score > maxScoreStu.score) {109     //            maxScoreStu = students[i];110     //        }111     //    }112     //    printf("%.2f /n", maxScoreStu.score);113     ////3年齡最小的114     //    Student minScoreStu = students[0];  //存儲數組中第一個學生的信息,假設第一個學生的年齡最小, 與其他的學生進行比較。115     //    for (int i = 1; i < 5; i++) {116     //        if (students[i].age < minScoreStu.age) {117     //            minScoreStu = students[i];118     //        }119     //    }120     //    printf("%d/n", minScoreStu.age);121     ////4按年齡升序排序122     //123     //124     //    for (int i = 0; i < 5 - 1; i++) {125     //        for (int j = 0; j < 5 - 1 - i; j++) {126     //            if(students[j].age > students[j + 1].age){127     //                Student temp = students[j];    //交換兩個結構體變量, 而不是只交換年齡128     //                students[j] = students[j + 1];129     //                students[j + 1] = temp;130     //            }131     //        }132     //    }133     //       for (int i = 0; i < 5; i++) {134     //        printf("%d , %s /n", students[i].age, students[i].name);135     //    }136     137 /////////////////結構體的內存對齊方式  ,以占字節數最大的類型的字節的陪數分配138 //    typedef struct person{139 //        char name[12];140 //        char gender;141 //        int age;142 //    }Person;143 //    printf("%lu/n", sizeof(Person));144 ////、、、、、結構體嵌套(在一個結構體中, 結構體的成員又是另外一個結構體的變量)145     typedef struct birth{146         int year;  //出生年份147         int month; //出生月份148         int day;   //出生日149     }Birth;150     151     typedef struct teacher{152         char name[12];//姓名153         int age;//年齡154         Birth birthday;155     }Teacher;156     157     Teacher tea1 = {"Jack", 24, {1991, 5, 23}};158     printf("%s, %d, %d, %d, %d", tea1.name, tea1.age, tea1.birthday.year, tea1.birthday.month, tea1.birthday.day);159     160     161     162     return 0;

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 粉嫩粉嫩一区二区三区在线播放 | 午夜在线观看视频网站 | 国产精品久久久久久久久久东京 | 亚洲欧美国产高清 | 色综合久久久久久久久久久 | 成人午夜视频免费看 | 久久久久久久午夜 | 在线男人天堂 | 亚州精品国产 | 日韩视频在线观看免费 | 丰满年轻岳中文字幕一区二区 | 羞羞网站 | 日本黄色免费观看视频 | 精品亚洲二区 | 国产大片中文字幕在线观看 | 神马视频我不卡 | 国产久草视频在线 | 欧美人xx | 亚洲视频欧美 | 成人免费一区二区三区视频网站 | 伊人二本二区 | 免费观看一级 | 亚洲欧美aⅴ | 欧美成人免费小视频 | 国产毛片视频 | 成人不卡在线观看 | 色诱亚洲精品久久久久久 | 中文字幕在线观看二区 | 91久久国产综合久久91猫猫 | 中文字幕免费看 | 久久久精品视频免费看 | 在线免费视频a | 依人在线视频 | 欧美一级黄色录像片 | 失禁高潮抽搐喷水h | videos韩国 | 精品在线观看一区二区三区 | 91在线色视频 | 精品一区二区三区在线观看国产 | 成人男女啪啪免费观看网站四虎 | 免费午夜视频 |