C6_函数多文件管理练习

//

//  MyFunction.h

//  homeworkC6

//

//  Created by dllo on 15/7/8.

//  Copyright (c) 2015 Clare. All rights reserved.

//


#import <Foundation/Foundation.h>


///****************************************************************

//1.创建一个Size结构体,包含widthheight两个变量。并写以下函数:函数1,判断两个size是否等宽。函数2,判断两个size是否在等高。函数3,判断两个size是否相等


struct size{

    float width;

    float height;

};

typedef struct size size;


BOOL equalWidth(size p1, size p2);

BOOL equalHeight(size p1, size p2);

BOOL equal(size p1,size p2);


///******************************************************************

//2.定义一个结构体,有两个成员变量,一个是姓名,一个是速度,然后计算两人相距100公里,第一个人的速度4公里/h 第二个人的速度6公里/h.函数1, 两人相向而行,相遇的时候第一个人走了多远.函数2, 第一个人先走40公里,第二个人走多远能追上第一个人


struct distance{

    char name[20];

    int speed;

};

typedef struct distance distance;


int target(distance p1, distance p2);

int pursue(distance p1, distance p2);



/////********************************************************************

////3.某班有 5 个学生,三门课。分别编写 3 个函数实现以下要求:(1 求各门课的平均分;(2 找出有两门以上不及格的学生,并输出其学号和不及格课程的成绩;(3 找出三门课平均成绩在 85-90 分的学生,并输出其学号和姓名

//

//struct className{

//    char cName[20];

//};

//typedef struct className className;

//

//struct score{

//    float course[20];

//    className className;

//};

//typedef struct score score;

////

////struct className{

////    char cName[20];

////    score stuScore;

////};

////typedef struct className className;

//

//struct student{

//    char name[20];

//    int stuNum;

//   // className cName;

//    score stuScore;

//};

//typedef struct student student;

//

//float averageScore(className name[],score score[]);

//

//int unpass(student num, score score);

//

//student averagescore(student num,student name);


struct student{

    char stuNam[20];

    int stuID;

    int English;

    int Math;

    int Chinese;

};

typedef struct student student;


void averageScore(student stu[]);

void unpass(student stu[]);

void aversum(student stu[]);





//

//  MyFunction.m

//  homeworkC6

//

//  Created by dllo on 15/7/8.

//  Copyright (c) 2015 Clare. All rights reserved.

//


#import "MyFunction.h"


BOOL equalWidth(size p1, size p2){

    if (p1.width == p2.width) {

        return YES;

    } else {

        return NO;

    }

}


BOOL equalHeight(size p1, size p2){

    if (p1.height == p2.height) {

        return YES;

    } else {

        return NO;

    }

}

BOOL equal(size p1,size p2){

    if (p1.width == p2.width && p1.height == p2.height) {

        return YES;

    } else {

        return NO;

    }

}


///********************************************************************


int target(distance p1, distance p2){

    int distance = p1.speed * (100 / (p1.speed + p2.speed));

    return distance;

}


int pursue(distance p1, distance p2){

    int distance = (100 + 40) / (p2.speed - p1.speed) * p2.speed;

    return distance;

}



/////*******************************************************************

//

//float averageScore(className name[],score score[]){

//    for (int i = 0; i < 5; i++) {

//        int aver = 0;

//        aver = classname[i].score[i]

//    }

//    

//}

//

////int unpass(student num, score score);{

////    

////}

////

////student averagescore(student num,student name);{

////    

////}



void averageScore(student stu[]){

    int chinese = 0;

    int english = 0;

    int math = 0;

    for (int i = 0; i < 5; i++) {

        chinese += stu[i].Chinese;

        english += stu[i].English;

        math += stu[i].Math;

    }

    printf("chinese %d\n english %d\n math %d\n",chinese/5,english/5,math/5);

}


void unpass(student stu[]){

//    int chinese = 0;

//    int english = 0;

//    int math = 0;

    int sum = 0;

    for (int i = 0; i < 5; i++) {

        if ((stu[i].Math <= 60 && stu[i] .English <= 60)||(stu[i].English <= 60&&stu[i].Chinese<=60)||(stu[i].Chinese <=60&&stu[i].Math<=60)) {

            sum++;

            printf("%s %d\n",stu[i].stuNam, stu[i].stuID);

        }

    }

    

}


void aversum(student stu[]){

    int aversum1 =0;

    for (int i = 0; i < 5; i++) {

       aversum1 = ( stu[i].Chinese + stu[i].English + stu[i].Math)/3;

        if (aversum1 >= 85 && aversum1 <=90) {

            printf("%s %d \n",stu[i].stuNam, stu[i].stuID);

        }

    }

}

























//

//  main.m

//  homeworkC6

//

//  Created by dllo on 15/7/8.

//  Copyright (c) 2015 Clare. All rights reserved.

//


#import <Foundation/Foundation.h>

#import "MyFunction.h"

int main(int argc, const char * argv[]) {

//

//    size p1 = {4, 5};

//    size p2 = {8, 5};

//    if (equalWidth(p1, p2)) {

//        printf("宽相等\n");

//    } else {

//        printf("宽不相等\n");

//    }

//    

//    if (equalHeight(p1, p2)) {

//        printf("高相等\n");

//    } else {

//        printf("高不相等\n");

//    }

//    if (equal(p1, p2)) {

//        printf("p1p2相等\n");

//    } else {

//        printf("p1p2不相等\n");

//    }

// 

///**************************************************************

    distance p1 = { "zhangsan",4};

    distance p2 = { "wangwu", 6};

    int sum = target(p1, p2);

    int sum1 = pursue(p1, p2);

    printf("相遇时走了%d公里\n",sum);

    printf("第二个人走了%d公里\n",sum1);

    

    

    

/////************************************************************

////    className  class1 =  {"Math"};

////    className  class2 =  {"English" };

////    className  class3 =  {"Computer"};

//    className  class =  {"Math", "English" ,"Computer"};

//    score stu1 = { 98, 82, 65, class};

//    score stu2 = { 75, 84, 88,class};

//    score stu3 = { 78, 83, 66,class};

//    score stu4 = { 92, 32, 42,class};

//    score stu5 = { 58, 43, 69,class};

//    

//    student stu11 = { "zhangsan", 111, stu1};

//    student stu21 = { "lisi", 222, stu2};

//    student stu31 = { "wangwu", 333, stu3};

//    student stu41 = { "yangliu", 95, stu4};

//    student stu51 = { "aoteman", 60, stu5};

//

//    

//    

    

    student stu1 = { "zhangsan", 111, 98, 82, 65};

    student stu2 = { "lisi", 222, 75, 84, 88};

    student stu3 = { "wangwu", 333, 78, 83, 66};

    student stu4 = { "yangliu", 444, 92, 32, 42};

    student stu5 = { "aoteman", 555, 58, 43, 69};

    student stu[5] = {stu1,stu2,stu3,stu4,stu5};

    averageScore(stu);

    unpass(stu);

    aversum(stu);

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值