数据结构训练1(关于学生的姓名,学号,成绩分数的管理)

#include 
using namespace std;




struct stu
{
int No;  //学号
char name[8];  
char sex[4];
int co1;
int co2;
int co3;
int co4;
};


double allavg(stu s[],int n)  //第n个学生的总平均分
{
int  sum = 0, m = 0;


if (s[n].co1 != -1)
{
m++;
sum += s[n].co1;
}


if (s[n].co2 != -1)
{
m++;
sum += s[n].co2;
}


if (s[n].co3!= -1)
{
m++;
sum += s[n].co3;
}


if (s[n].co4 != -1)
{
m++;
sum += s[n].co4;
}


return (sum/m);
}




double sinavg(stu s[], int i, int n) //第n门课的平均分
{
int m = 0, sum = 0;
switch (i)
{
case 1:
for (int j = 0; j < n; j++)
{
if (s[j].co1 != -1)
{
m++;
sum += s[j].co1;
}
}
break;
case 2:
for (int j = 0; j < n; j++)
{
if (s[j].co2 != -1)
{
m++;
sum += s[j].co2;
}
}
break;
case 3:
for (int j = 0; j < n; j++)
{
if (s[j].co3 != -1)
{
m++;
sum += s[j].co3;
}
}
break;
case 4:
for (int j = 0; j < n; j++)
{
if (s[j].co4 != -1)
{
m++;
sum += s[j].co4;
}
}
break;


default:
break;
}


return (sum / m);
}






void bothavg(stu s[] ,int n )
{
cout << "学生平均分:" << endl;
cout << "学号"<<'\0'<<"姓名"<<'\0'<<"性别" << endl;
for (int i = 0; i < n; i++)
{
cout << s[i].No << '\0' << s[i].name << '\0';
cout<


你可能感兴趣的:(数据结构)