66------70

66.#include <stdio.h>
long get_file_size(char *file_name){
    FILE *fp = NULL;
    if((fp = fopen(file_name,"r")) == NULL){
        printf("获取文件失败");
        return -1;
    }
    //从文件末尾偏移,偏移0位
    fseek(fp,0,SEEK_END);
    long file_size = ftell(fp);//ftell()存储当前文件描述符的读取的偏移位置,这里就是文件末尾
    fclose(fp);
    return file_size;
}
int main(int argc, char *args[]){
    printf("%ld",get_file_size("./filename.txt"));
}

67.

#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
int i;
typedef struct              //定义学生结构体
{
    string str;
    double courseA;
    double courseB;
    double courseC;
    double courseD;
    double avg;
}Student;

double sum[4]={0};          //用来保存四门课程的总分的数组
double course_avg[4]={0};   //用来保存四门课程的平均分的数组
Student stu_rank[5];        //用来保存学生排名的数组
queue<string> fail_stu;     //用来保存不及格学生学号的队列
queue<string> fine_stu;     //用来保存良好学生学号的队列

int cmp(Student a,Student b)//用来降序表示的bool函数
{
    return a.avg>b.avg;
}
void AvgCourse(Student*a)   //求各门课程的平均分
{
    for(i=0;i<5;i++)
    {
        sum[0]+=a[i].courseA;
        sum[1]+=a[i].courseB;
        sum[2]+=a[i].courseC;
        sum[3]+=a[i].courseD;
    }
    for(int i=0;i<4;i++)
    {
        course_avg[i]=sum[i]/5;
    }
}
void AvgStudent(Student*a)  //求每个学生的平均分
{
    for(i=0;i<5;i++)
    {
        a[i].avg=(a[i].courseA+a[i].courseB+a[i].courseC+a[i].courseD)/4;
    }
}
void Rank(Student*a)        //按照每个学生的平均分降序排序
{
    AvgStudent(a);
    sort(a,a+5,cmp);
    memcpy(stu_rank,a,sizeof(stu_rank));
}
void Fail(Student*a)
{
    for(i=0;i<5;i++)
    {
        int count = 0;
        if(a[i].courseA < 60)
            count++;
        if(a[i].courseB < 60)
            count++;
        if(a[i].courseC < 60)
            count++;
        if(a[i].courseD < 60)
            count++;
        if(count>=2)
            fail_stu.push(a[i].str);      
    }
}
void Fine(Student*a)
{
    for(i=0;i<5;i++)
    {
        if(85.0 <= a[i].avg && a[i].avg<= 90.0)
            fine_stu.push(a[i].str);      
    }
}

void main()
{
    Student a[5];
    cout<<"请依次输入学生的学号和四门课程的成绩"<<endl;
    for(i=0 ; i<5 ; i++)
    {
        cin>>a[i].str;
        cin>>a[i].courseA;
        cin>>a[i].courseB;
        cin>>a[i].courseC;
        cin>>a[i].courseD;
    }
    cout<<endl;

    AvgCourse(a);
    cout<<"各门课程的平均分为:"<<endl;
    for(int i=0; i<4 ;i++)
    {
        if(i==0)
            cout<<"courseA的平均分为:"<<course_avg[i]<<endl;
        if(i==1)
            cout<<"courseB的平均分为:"<<course_avg[i]<<endl;
        if(i==2)
            cout<<"courseC的平均分为:"<<course_avg[i]<<endl;
        if(i==3)
            cout<<"courseD的平均分为:"<<course_avg[i]<<endl;
    }
    cout<<endl;

    Rank(a);
    cout<<"学生按照平均分降序的排名为:"<<endl;
    for(i=0; i<5 ;i++)
    {
        cout<<"第"<<i+1<<"名的学号为:"<<stu_rank[i].str<<",平均分为:"<<stu_rank[i].avg<<endl;
    }
    cout<<endl;

    Fail(a);
    cout<<"有两门及以上课程不及格的学生的学号为:"<<endl;
    if(!fail_stu.empty())
    {
        while(!fail_stu.empty())
        {
            cout<<fail_stu.front()<<endl;
            fail_stu.pop();
        }
    }
    else
        cout<<"没有两门及以上课程不及格的学生"<<endl<<endl;

    Fine(a);
    cout<<"四门课的平均成绩在85~90分的学生的学号为:"<<endl;
    if(!fine_stu.empty())
    {
        while(!fine_stu.empty())
        {
            cout<<fine_stu.front()<<endl;
            fine_stu.pop();
        }
    }
    else 
        cout<<"没有学生四门课的平均成绩在85~90分"<<endl;
}
68.//2019-11-6
#include <stdio.h>
//设计一个递归函数,求x的n次幂:
//主函数通过键盘输入x和n的值,并输出x^n的值(假设x为实数,n为正整数)
double fun(double x,int n){
    if(n==1)
        return x;
    return x*fun(x,n-1);
}
int main()
{
    double x;
    int n;
    double result=0;
    scanf("%lf %d",&x,&n);
    result=fun(x,n);
    printf("%.2lf\n",result);
    return 0;
}
 
 
 69.#include <stdio.h> 
#define N 16 
typedef struct 
{     char num[10]; 
    int s; 
} STREC; 
/*************fun函数***************/
int fun( STREC *a,STREC *b,int l, int h ) 
{     
    int i,j=0;
        for(i=0;i<N;i++)
                if(a[i].s<=h&&a[i].s>=l)
                    b[j++]=a[i];
        return j;

/*************fun函数***************/
void main() 
{     STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},{"GA001",96}, {"GA007",72},{"GA008",64},{"GA006",87},{"GA015",85},{"GA013",94},{"GA012",64}, {"GA014",91},{"GA011",90}, {"GA017",64},{"GA018",64},{"GA016",72}}; 
    STREC h[N],tt;
    int i,j,n,low,heigh,t; 
    printf("Enter 2 integer number low & heigh : "); 
    scanf("%d%d", &low,&heigh); 
    if ( heigh< low ){ t=heigh;heigh=low;low=t; } 
    n=fun( s,h,low,heigh ); 
    printf("The student's data between %d--%d :\n",low,heigh); 
    for(i=0;i<n; i++) 
        printf("%s %4d\n",h[i].num,h[i].s); 
    printf("\n"); 
}

70.不会做

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值