2주 프로젝트 2 - 프로그램의 다중 파일 조직

5160 단어
질문 및 코드:
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff"></span><pre class="cpp" name="code">//          
//  :  
//  :9 11 
//    :                
//    : 
//    :      
#include <stdio.h>
#define MaxStud 50      //       50
#define MaxCour 300     //          50*6
struct stud1
{
    int no;         //  
    char name[10];  //  
    int bno;        //  
};
struct stud2
{
    int no;         //  
    int cno;        //    
    int deg;        //  
};
double studavg(struct stud2 s2[],int m,int i) ;  
double couravg(struct stud2 s2[],int m,int i) ;  
void allavg(struct stud1 s1[],int n,struct stud2 s2[],int m) ;  
cpp        main
#include"touwenjian.cpp"
int main()
{
    int n=7;        //      
    int m=21;       //       
    struct stud1 s1[MaxStud]=
    {
        {1,"  ",9901},
        {8,"  ",9902},
        {34,"  ",9901},
        {20,"  ",9902},
        {12,"  ",9901},
        {26,"  ",9902},
        {5,"  ",9901}
    };
    struct stud2 s2[MaxCour]=   //        1 6,            
    {
        {1,1,67},
        {1,2,98},
        {1,4,65},
        {8,1,98},
        {8,3,90},
        {8,6,67},
        {34,2,56},
        {34,4,65},
        {34,6,77},
        {20,1,68},
        {20,2,92},
        {20,3,64},
        {12,4,76},
        {12,5,75},
        {12,6,78},
        {26,1,67},
        {26,5,78},
        {26,6,62},
        {5,1,94},
        {5,2,92},
        {5,6,89}
    };
    allavg(s1,n,s2,m);
    return 0;
}
 
 
 
#include"touwenjian.h"
double studavg(struct stud2 s2[],int m,int i)   //    i       
{
    int j,n=0;              //n    i        
    double sum=0;           //   i     
    for (j=0; j<m; j++)
        if (s2[j].no==i)    //   i   
        {
            n++;
            sum+=s2[j].deg;
        }
    return(sum/n);
}
double couravg(struct stud2 s2[],int m,int i)   //    i       
{
    int j,n=0;              //n    i       
    double sum=0;           //   i     
    for (j=0; j<m; j++)
    {
        if (s2[j].cno==i)   //     i   
        {
            n++;
            sum+=s2[j].deg;
        }
    }
    return(sum/n);
}
void allavg(struct stud1 s1[],int n,struct stud2 s2[],int m)    //            
{
    int i,j;
    printf("     :
"); printf("
"); i=0; while (i<n) { j=s1[i].no; printf("%4d %10s %g
",s1[i].no,s1[i].name,studavg(s2,m,j)); i++; } printf(" :
"); for (i=1; i<=6; i++) printf(" %d:%g
",i,couravg(s2,m,i)); }
 
 
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff"><span style="font-family:Courier New;BACKGROUND-COLOR: #f0f0f0">    :</span></span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff"><img src="http://img.blog.csdn.net/20150911093227500?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">     :</span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">.h   :      ,       </span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">.cpp  :               </span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">.cpp  :  main()   ,      ,        </span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff"></span> 
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">    :</span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">         ,      ,              。</span>
<span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">             ,      ,      。</span>


좋은 웹페이지 즐겨찾기