zoukankan      html  css  js  c++  java
  • 第三次作业

    一、学习内容总结

    2 课上疑点:讨论查阅分析 struct sk{int a; char str)}p; p->str++ 中的++ 加向________?
    答:加向str。

    二.pta

    题目1查找书籍中最高价及最低价

    1.设计思路

    • 定义结构体book,并且对成员分量名字name价格price进行定义。
    • 输入n表示有n本书,利用循环输入书名和价格。
    • 定义最大值与最小值。
    • 在循环体中将每本书的价格与最大价格max.price和最小价格min.price比较,如果价格大于max.price就将p.price传给max.price,如果价格小于min就将p.price传给min.price。
    • 输出结果。
      2.流程图

      3.代码
    
    #include <stdio.h>  
    #include <stdlib.h>  
    #include <string.h>  
    #include <math.h>  
      
    int main()  
    {  
        struct bookandprice  
        {  
            char name[300];  
            double price;   
        }now,max,min;  
      
        max.price=0;  
        min.price=999999999999999999;  
        int n,i;  
        scanf("%d",&n);  
        for(i=1;i<=n;i++)  
        {  
            getchar();  
            gets(now.name);  
            scanf("%lf",&now.price);  
            if(now.price>max.price)  
            {  
                strcpy(max.name,now.name);  
                max.price=now.price;  
            }  
            if(now.price<min.price)  
            {  
                strcpy(min.name,now.name);  
                min.price=now.price;  
            }  
        }  
        printf("%.2lf, %s
    %.2lf, %s",max.price,max.name,min.price,min.name);  
      
        return 0;  
    }  
    
    

    题目2 计算平均成绩

    1.设计思路

    • 填写基本结构,基础函数。
    • 对平均数赋初值,并输入人的个数以及对应的学号,姓名,成绩,并把每一个学生的成绩累加。
    • 利用循环结构相加。
    • 输出结果
      2.流程图

      3.代码
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    struct student{
    	char num[20];
    	char name[20];
    	int score;
    		
    }s[1000],*p;
    int main(){
    	int N;
    	int i=0,count;
    	scanf("%d",&N);
    	for(i=0;i<N;i++){
    	scanf("%s %s %d",&s[i].num,s[i].name,&s[i].score);
    	}
    	int sum;
    	for(i=0;i<N;i++){
    		sum=sum+s[i].score;
    	}
    	float ave;
    	ave=sum/N;
    	printf("%.2f
    ",ave);
    	for(i=0;i<N;i++){
    		if(s[i].score<ave)
    		printf("%s %s
    ",s[i].name,s[i].num);
    	}
    system("pause");
    }
    

    要求三、学习总结和进度(20分)

    1、指针与结构作业中题目所使用的知识点
    1、指针与结构作业中题目所使用的知识点。
    1.结构体的正确使用和输出定义的变量。
    2.使用指针可以代替类似&s[i]的输入,在用到p->时,有明确的分层指向时,不必要写出两个界限,就如结构二中的题目一样。

    git

  • 相关阅读:
    Photoshop 基础七 位图 矢量图 栅格化
    Photoshop 基础六 图层
    Warfare And Logistics UVALive
    Walk Through the Forest UVA
    Airport Express UVA
    Guess UVALive
    Play on Words UVA
    The Necklace UVA
    Food Delivery ZOJ
    Brackets Sequence POJ
  • 原文地址:https://www.cnblogs.com/100200a/p/8917219.html
Copyright © 2011-2022 走看看