CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  新手乐园

c++问题

楼主pow520www()2006-11-01 19:15:59 在 C/C++ / 新手乐园 提问

#include"stdio.h"  
  void   p(int   p[30]);  
  k(char   k[30]);  
  struct   st  
  {  
  char   name[30];  
  char   sex[30];  
  float   jishi;  
  float   bishi;  
  float   xiangmu;  
  float   chuqing;  
  float   zhonghe[4];  
  float   zhonghel;  
  };  
  void   main()  
  {  
  int   i,j,temp;  
  float   b,sum=0,sun1,max;  
  struct   st   stu[30];  
  for(i=0;i<30;i++)  
  {  
   
  printf("学生姓名:");  
  gets(stu[i].name);  
  fflush(stdin);  
  printf("姓别:");  
  gets(stu[i].sex);  
  printf("机试成绩:");  
  scanf("%f",&stu[i].jishi);  
  printf("笔试成绩:");  
  scanf("%f",&stu[i].bishi);  
  printf("项目成绩:");  
  scanf("%f",&stu[i].xiangmu);  
  printf("出勤成绩:");  
  scanf("%f",&stu[i].chuqing);  
          for(j=0;j<4;j++)  
  {  
      printf("第%d次内测成绩为:\n",j+1);  
      scanf("%f",&stu[i].zhonghe[j]);  
      sum=sum+stu[i].zhonghe[j];  
  }  
          printf("综合成绩:");  
  scanf("%f",&stu[i].zhonghel);  
  sun1=0.00;  
  sun1=sum*0.3+stu[i].jishi*0.1+stu[i].bishi*0.1+stu[i].xiangmu*0.2+stu[i].chuqing*0.1+stu[i].zhonghel*0.2;  
  printf("总成绩为:%1.2f\n",sun1);  
  if(sun1>max)  
   
  {  
   
                                max=sun1;  
   
                                temp=i;  
   
  }  
   
  }  
   
                              p   =   stu+temp;  
                              printf("\nThe   maximum   score:\n");  
                              printf("最佳成绩\n姓名:\n%s\n平均成绩:%4.1f\n",sun1);  
  }  
   
  改下错误  
  G:\用户文件\Cpp1.cpp(45)   :   warning   C4244:   '='   :   conversion   from   'double'   to   'float',   possible   loss   of   data  
  G:\用户文件\Cpp1.cpp(59)   :   error   C2659:   '='   :   overloaded   function   as   left   operand  
  还有  
    printf("最佳成绩\n姓名:\n%s\n平均成绩:%4.1f\n",sun1);  
  名字怎么填写啊  
  原题目是  
  题:定义一个ACCP学员的成绩结构:4次内测占30%,结业笔试占10%,结业机试占10%,项目设计占20%,出勤率占10%,综合素质占20%。    
   
  实现要求:    
  定义一个函数:   struct   score   input(   )    
  实现对一个学员成绩的输入    
  定义一个函数:void   display(struct   score     stud[])    
  实现对学员信息的输出,要求以格式化输出    
  定义一个函数:void   sort(struct   score   stud[])    
  实现对学员信息的排序    
  在主函数中,采用提示方式调用input()函数来输入学员成绩,输入完成后调用display()函数来输出所有学员成绩信息,调用sort()函数按最终成绩的降序排序学员成绩信息,排序后调用display()函数输出排序的后的成绩信息    
  用函数不会 问题点数:20、回复次数:8Top

1 楼lann64(昆仑大鹏@迦楼罗)回复于 2006-11-01 19:17:33 得分 0

怎么看都是个C程序,怎么叫C++问题?Top

2 楼yuanhan530(千年※ 蜗牛)回复于 2006-11-01 19:33:37 得分 0

???????????c不可以算是C++吗?  
  Top

3 楼laiwusheng(风清扬)回复于 2006-11-01 19:47:01 得分 0

p   =   stu+temp;//这能加吗?  
  还有你的max没有赋值  
  temp用的不恰当Top

4 楼lann64(昆仑大鹏@迦楼罗)回复于 2006-11-01 20:16:52 得分 0

???????????c不可以算是C++吗?  
  --------------  
  各有各的标准,各有各的标准委员会来制定标准,你说c算是C++吗?Top

5 楼wanfustudio(雁南飞:知识之败,慕虚名而不务潜修也)回复于 2006-11-01 20:17:00 得分 0

 
  p   =   stu+temp;//这个需要重载   +   号  
   
  ----  
   
  void   p(int   p[30]);//这个函数名怎么跟参数一个名字~Top

6 楼popchild(欧罗巴骚客贩)回复于 2006-11-02 13:59:35 得分 0

没看出有++的感觉Top

7 楼Dan1980()回复于 2006-11-02 14:03:05 得分 0

同意1楼,这是c程序,不是c++程序。Top

8 楼wukexin()回复于 2006-11-02 22:22:38 得分 0

/*  
  用C++写得  
  */  
  #include   <iostream>  
  #include   <string>  
  #include   <vector>  
  #include   <algorithm>  
  #include   <functional>  
   
  const   int   NUMBER=4;  
  //  
  class   Cscore  
  {  
  public:  
  Cscore();  
  ~Cscore();  
  void   input();  
  void   print()   const;  
  std::string   name()   const   ;  
  float   count()   const;//总成绩    
  protected:  
  friend   class   Crule_sort;  
  private:  
  std::string   m_name;  
  std::string   m_sex;  
  float   m_jishi;  
  float   m_bishi;  
  float   m_xiangmu;  
  float   m_chuqing;  
  float   m_zhonghe[NUMBER];  
  float   m_zhonghel;  
  };  
  Cscore::Cscore(){   input();   }  
  Cscore::~Cscore(){}  
  void   Cscore::input()   {  
  using   namespace   std;  
  {  
  cout<<"学生姓名:";  
  cin>>m_name;  
  cout<<"姓别:";  
  cin>>m_sex;  
  cout<<"机试成绩:";  
  cin>>m_jishi;  
  cout<<"笔试成绩:";  
  cin>>m_bishi;  
  cout<<"项目成绩:";  
  cin>>m_xiangmu;  
  cout<<"出勤成绩:";  
  cin>>m_chuqing;  
  for(int   i=0;i<NUMBER   ;i++   )  
  {  
  cout<<"第"<<i+1<<"次内测成绩为:";  
  cin>>m_zhonghe[i];  
  }  
  cout<<"综合成绩:";  
  cin>>m_zhonghel;  
  };  
  };  
  void   Cscore::print()   const{  
  using   namespace   std;  
  cout<<"学生姓名:"<<m_name  
  <<"\t姓别:"<<m_sex  
  <<"\t机试成绩:"<<m_jishi  
  <<"\t笔试成绩:"<<m_bishi  
  <<"\t项目成绩:"<<m_xiangmu  
  <<"\t出勤成绩:"<<m_chuqing;  
  for(int   i=0;i<NUMBER   ;i++   )  
  {  
  cout<<"\t第"<<i+1<<"次内测成绩为:"<<m_zhonghe[i];  
  }  
  cout<<"综合成绩:"<<m_zhonghel<<"\n";  
  };  
  //  
  std::string   Cscore::name()   const   {  
  return   m_name;  
  }  
  //  
  float   Cscore::count()   const{  
  float   sum=0,result=0;  
  for(int   i=0;i<NUMBER   ;i++   )  
  {  
  sum+=m_zhonghe[i];  
  }  
  result=sum*0.3+m_jishi*0.1+m_bishi*0.1+m_xiangmu*0.2+m_chuqing*0.1+m_zhonghel*0.2;  
  return   result;  
  }  
  //  
  class   Crule_sort   :   std::binary_function   <   Cscore,Cscore,bool>  
  {  
  public:  
  bool   operator()   (const   Cscore&   arg1,const   Cscore&   arg2){  
  return   rule(arg1)<rule(arg2);  
  }  
  private:  
  float   rule(Cscore&   x){  
  return   x.count();//排序规则可以自定义    
  }  
  };  
  //  
  void   display(const   std::vector<Cscore>&   v){  
  using   namespace   std;  
  vector<Cscore>::const_iterator   itr=v.begin();  
  for(   ;   itr!=v.end();   itr++){  
  itr->print();  
  }  
  }  
  //  
  int   main()  
  {  
  using   namespace   std;  
  const   int   MAX=3;  
  vector<Cscore>   v(MAX);  
  for(unsigned   int   i=0;i<v.size();i++){  
  cout<<"学号"<<i<<"\n";  
  Cscore   student;  
  v[i]=student;  
  }  
  display(v);  
  sort(   v.begin(),v.end(),Crule_sort()   );  
  display(v);  
  vector<Cscore>::const_iterator   itr=max_element(v.begin(),v.end(),Crule_sort()   );  
  float   sum=0;//学生成绩汇总  
  for(unsigned   int   i=0;i<v.size();i++)  
  {  
  sum+=v[i].count();  
  }  
  cout<<"最佳成绩:"<<itr->count()  
  <<"姓名:"<<itr->name()  
  <<"平均成绩:"<<sum/MAX  
  <<"\n";  
  return   0;  
  }Top

相关问题

关键词

得分解答快速导航

  • 帖主:pow520www

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo