注册 登录
编程论坛 C++教室

请大家帮我修改下这个程序

kartik 发布于 2010-04-11 18:29, 462 次点击
#include<iomanip.h>
#include<iostream.h>
struct std
{
    long num;
    char name[20];
    int sex;
    float score[5];
};
void main()
{   int i,j;
    std st[5];
   
    for(i=0;i<5;i++)
    {cout<<"input the num:";
     cin>>st[i].num;
     cout<<"\ninput the name:";
     cin>>st[i].name;
     cout<<"\ninput the sex:";
     cin>>st[i].sex;
     for(j=0;j<5;j++)
     {cout<<"Please input the all score:";
      cin>>st[i].score[j];
     }
    }
    for(i=0;i<5;i++)
    {
     for(j=0;j<5;j++)
     {
      if(st[i].score[j]>=70)
      {
          if((st[i].score[j]>=85)&&(j>=3))
          {   cout<<"有"<<i<<"同学达到优秀:\n";
              
          }
      }
     }
    }
    for(i=0;i<5;i++)
    {
      for(j=0;j<5;j++)
      { if(st[i].score[j]<60)
         {
          cout<<"有"<<i<<"同学需要补考:\n";
         }
      }
    }
}



请大家帮我修改下这个程序,能够输出优秀和补考的人数。
7 回复
#2
kartik2010-04-15 00:31
~~~~(>_<)~~~~ ,没人理我
#3
atemouse2010-04-15 09:21
你要实现的目的是什么?怎么sex用int定义?能说清楚点吗?是不是想说一个人有5门课的成绩,只要有一门下了60就要补考?
#4
apull2010-04-15 10:31
没调试,直接写了,大概就这样。
程序代码:

#include<iomanip.h>
#include<iostream.h>
struct std
{
    long num;
    char name[20];
    int sex;
    float score[5];
};

void main()
{   int i,j;
    std st[5];
    int y=0,b=0;    //y优秀人数,b补考人数
   
    for(i=0;i<5;i++)
    {cout<<"input the num:";
     cin>>st[i].num;
     cout<<"\ninput the name:";
     cin>>st[i].name;
     cout<<"\ninput the sex:";        //这里必须输入一个整数
     cin>>st[i].sex;
     cout<<"Please input the all score:";
     for(j=0;j<5;j++)
     {
      cin>>st[i].score[j];
     }
    }
   cout << endl;    //换行
    for(i=0;i<5;i++)
    {
    int yy=0;    //统计>=85的人数
    int bb=0;
     for(j=0;j<5;j++)
     {
          if(st[i].score[j]>=85)
          {  
              ++yy;
          }
         if(st[i].score[j]<60)
         {
    ++bb;
         
         }
     }
    if(yy>=3) ++y;
    if(bb>0)++b;
    }
     cout<<""<<y<<"同学达到优秀:\n";
     cout<<""<<b<<"同学需要补考:\n";
}

#5
flyinthesky12010-04-15 10:32
怎么用那么多循环?
#6
南国利剑2010-04-15 16:04
不在家里,没有开发环境,没办法调试。晚上回去再看看。
#7
最近不在2010-04-16 11:46
我想lz的意思是,每门都需要70分以上并且有3门达到85以上!!
而且补考的同学,有的会挂几门,不要重复计算!
#8
kartik2010-04-16 12:00
恩恩,题目是这样的?大家帮看看,没有时间做了

已知全班有75位同学,期末考试该班共考了五门功课,每门课程均以百分制整数计分;同学的学号从1号起连续编号。编出程序,输入全班同学的成绩、统计出全班同学中成绩达到优秀的人数以及需要补考的人数。
优秀的要求是:成绩大于等于85分的功课不少于三门、且其他课程成绩均不低于70分;
补考的要求是:只要有一门课的成绩低于60分,即属于“补考”。
进一步思考问题1:若把全班同学人数改为“已知全班同学人数不超过100人”,上述程序应如何修改?
进一步思考问题2:若问题要求不仅是统计出补考和优秀的人数,而加上要求“分别输出优秀及补考的同学的相关成绩资料”(包括学号及各门课成绩),程序又应如何改进?
1