蓝欧培训 c7


header.m#import "header.h" void printStudent(STUDENT boy){    printf("%-11s %d %d-%d-%d %c %.2f\n",boy.name,boy.age,boy.birthday.year,boy.birthday.month,boy.birthday.day, boy.sex,boy.score); } void printAllStudents(STUDENT stus[],int count){    for (int i = 0; i < count; i++) {        printStudent(stus[i]);    } } STUDENT findMaxScoreStudent(STUDENT stus[],int count){    STUDENT tem = {0};    for (int i = 0; i < count; i++) {        if (tem.score < stus[i].score ) {            tem = stus[i];                    }    }    return tem; } void sortByScoreWithBubble(STUDENT stus[],int count){    for (int i = 0; i < count - 1; i++) {        for (int j = 0; j < count - 1 - i; j++) {        if (stus[j].score > stus[j + 1].score) {            STUDENT tem = stus[j];            stus[j] = stus[j + 1];            stus[j + 1] = tem;            }        }    }    printAllStudents(stus,count); } void sortByScoreWithChoose(STUDENT stus[],int count){        for (int i = 0; i < count - 1; i++) {        int  min = i;        for (int j = i + 1; j < count; j++) {            if (stus[j].birthday.year < stus[min].birthday.year) {                min = j;            }        }        if (min != i ) {            STUDENT tem = stus[min];            stus[min] = stus[i];            stus[i] = tem;        }    }        printAllStudents(stus, 5); } header.h#import <Foundation/Foundation.h> typedef struct Date{    int year;    int month;    int day; }MYDath; typedef struct Students{    char name[20];    int age;    MYDath birthday;    char sex;    float score; }STUDENT; void printStudent(STUDENT boy); void printAllStudents(STUDENT stus[],int count); STUDENT findMaxScoreStudent(STUDENT stus[],int count); void sortByScoreWithBubble(STUDENT stus[],int count); void sortByScoreWithChoose(STUDENT stus[],int count); main.m#import <Foundation/Foundation.h> #import "header.h" //void test(){ //    for (int i = 0; i < 5; i++){ //    printf("从前有座山,山上有个老和尚,老和尚给小和尚讲:"); //    test(); //        if (i == 5) { //            break; //        } //    } //} //long fact(int n){ //    if (n == 1) { //        return n; //    } //    return n * fact(n - 1); // //} //struct student{ //    int number;//结构体类型的成员变量列表 //    char name[20]; //    int age; //    char sex; //    float score; //}; // //typedef struct Date{ //    int year; //    int month; //    int day; //}MYDath; // // ////结构体类型所占用的内存空降是最大数据类型的整数倍 ////因为结构体类型的变量在分配内存是有"内存对齐" // ////第二种,定义结构体同事tppedef //typedef struct Students{ //    char name[20]; //    int age; //    MYDath birthday; //    char sex; //    float score; //}STUDENT;//新类型名 // ////类型重定义,给现有的类型重新起别名 ////     原类型  新类型 //typedef int  Integer; //typedef struct Students Stu; int main(int argc, const char * argv[]) {    //    //函数的递归调用 ////    test(); //    //    //函数的递归调用(允许函数体里面再次调用函数本身) //    //使用递归一定要有出口; //    long s = fact(6); //    printf("s = %ld",s);        //结构体.构造类型 //    struct student{ //        int number; //        char name[20]; //        int age; //        char sex //        float score; //    };    //    struct student boy1 ={1,"zhangshan",19,‘M‘,89.05}; //    struct student girl2 = boy1; //    girl2.sex = ‘F‘; //    //    printf("%d, %s, %d, %c, %f\n",boy1.number,boy1.name,boy1.age,boy1.sex,boy1.score); //    printf("%d, %s, %d, %c, %f",girl2.number,girl2.name,girl2.age,girl2.sex,girl2.score); //    printf("\n%lu",sizeof(struct student));        //    STUDENT boy1 = {"zhangyishan", 19, {1992,5,6}, ‘M‘, 59.99}; //    struct Students girl1 = {"lisi", 20, {1996,4,6},‘w‘,89.98}; //    STUDENT girl2 = {"lose", 18, {1995,1,5},‘W‘,76.59}; //    struct Students girl3 = {0}; //    //    boy1.score = 69.89; //    girl1.score = 99.21; //    girl3.score = 89.99; //    strcpy(girl3.name, "annt"); //    girl2.birthday.year = 1969;    //    printf("%-11s, %d, %c, %.2f\n",boy1.name,boy1.age,boy1.sex,boy1.score); //    printf("%-11s, %d, %c, %.2f\n",girl1.name,girl1.age,girl1.sex,girl1.score); //    printf("%-11s, %d, %c, %.2f\n",girl2.name,girl2.age,girl2.sex,girl2.score);    //    struct Students stu = {0}; //    stu = boy1.score > girl1.score ? boy1 : girl1; //    stu = stu.score >girl2.score ? stu :girl2;    //数组不可以直接赋值,但是结构体类型的变量可以    //boy1 = girl2; //    stu = (boy1.score > girl1.score ? boy1.score : girl1.score) > girl2.score ? //   (boy1.score > girl1.score ? boy1 : girl1) : girl2; //    //    printf("%s %d %c %.2f",stu.name,stu.age,stu.sex,stu.score);    //    struct Students minAgeStu = {0}; //   //    minAgeStu = (boy1.age < girl2.age ? boy1.age : girl2.age) < girl1.age ? (boy1.age < girl2.age ? boy1 : girl2) : girl1; //    printf("%-11s %d %d-%d-%d %c %.2f",minAgeStu.name,minAgeStu.age,minAgeStu.birthday.year,minAgeStu.birthday.month,minAgeStu.birthday.day, minAgeStu.sex,minAgeStu.score);    //    printStudent(girl2); //    printStudent(boy1); //    printStudent(girl1);         STUDENT stus[5] = {        {"zhangyishan", 19, {1992,5,6}, ‘M‘, 59.99},        {"lisi", 20, {1996,4,6},‘w‘,89.98},        {"lose", 18, {1995,1,5},‘W‘,76.59},        {"shanyang", 19, {1993,8,5},‘M‘,96.55},        {"yanzi", 16, {1994,9,4},‘W‘,78.96},    }; // //    for (int i = 0; i < 5; i++) { //        printStudent(stus[i]); //    }      //    printAllStudents(stus,5);        //打印最大成绩的那个学生 //    STUDENT tem = findMaxScoreStudent(stus, 5); //    printStudent(tem); //    printStudent(findMaxScoreStudent(stus,5));    //    sortByScoreWithBubble(stus,5);        sortByScoreWithChoose(stus,5); //    printf("%s %d",stus[2].name,stus[2].age); //    printStudent(stus[3]);    //    printf("%lu",sizeof(struct Students));    return 0; }
时间: 2024-08-06 03:21:44

蓝欧培训 c7的相关文章

蓝欧培训--lessonc12[枚举,位运算符,预编译指令,const]

////  main.m//  lessonc12////  Created by 张阳帅 on 15-1-6.//  Copyright (c) 2015年 张阳帅. All rights reserved.// #import <Foundation/Foundation.h> #define kDeBug //当一个变量只有固定几个取值的时候,可以定义一个枚举类型//枚举类型声明了一组常数,将人能看懂的标示符和计算机能看懂的数字建立对应关系//如果枚举类型不指定常数,默认从0开始, 依次

蓝欧--lesson8

#import <Foundation/Foundation.h>//       宏名 替换的内容[千万别加分号]#define VALUE 10 //命名规范,纯大写或者是k开头的驼峰命名法#define AS 52.02 #define SUM(A, B) A + B #define SQUARE(A) ((A) + (A))//安全 #define MAXXX(A, B) (((A) > (B)) ? (A) : (B)) #define MAX_NUMBER(A, B, C)

蓝欧h5课程笔记

1.获取css外部样式表的属性值 getCss(obj,'属性名称');如:getCss(oSpan[0],'height'); getComputedStyle(obj).属性名称;如:getComputedStyle(oDiv[0]).width; 2响应式布局 <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0

蓝欧证件照

蓝欧--lessonc12[函数指针]

#import <Foundation/Foundation.h> //int(*)(int ,int) 原类型//PFUN 新类型typedef int(*PFUN)(int ,int); typedef struct student{    char name[20];    char sex;    int age;    float score;}STUDENT; BOOL sortByAge(STUDENT stu, STUDENT stu1);BOOL sortByAge(STUD

蓝欧--lesson2

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) {                //变量定义三要素    //类型修饰符 变量名 =初始值            //变量命名规范:    //1.变量名必须以字母,数字,下划线组成,数字不能打头    //2.变量名不能够占用系统关键字    //3.见名知意    //4.驼峰命名法        //    int a = 5;//   

蓝欧--lessonc11[动态内存分配]

#import <Foundation/Foundation.h>#import "header.h" typedef struct student{    char name[20];    char sex;    int  age;    float score;    }STUDENT; int maxValue(int a, int b);int square(int n); char * getString(); int maxValue(int a, int

蓝欧--lesson5&lt;有难度&gt;

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { //输出数组中4个数的最大数//    int i = 0, max = 0,a[4] = {0};//    printf("请输入四个数:");//    for (i = 0; i<4; i++) {//        scanf("%d", &a[i]);//    }//    m

蓝欧--lesson3

#import <Foundation/Foundation.h>////int main(int argc, const char * argv[]) { //    //    //溢出//    char a = 128;//    //    printf("%d", a);//        //无符号类型,值存正数    //%u 打印无符号整型数    //%lu 打印无符号长整型数    //%ld 打印有符号长整型数//    unsigned char