» 首页 » 电脑_数码 » 编程 » 一段搞不定的c++代码

一段搞不定的c++代码

我写了一段代码,编译能通过但无法运行请专家指点一下,谢谢
#include<iostream>
#include<cstring>
using namespace std;
class student
{public:
student(int n,char name[],int sc)
{num=n;
strcpy(name,name);
score=sc;
}
char *getname()
{return name;}
int getnum()
{return num;}
int getscore()
{return score;
}
static void display()
{cout<<s<<' '<<na<<' '<<temp<<endl;
}
static void max(student&);
private:
int num;
char name[20];
int score;
static int temp;
static char na[20];
static int s;

};
int student::temp=-1;
char student::na[20]=" ";
int student::s=0;
void student::max(student&stud)
{if(temp==-1)temp=stud.getscore();
if(temp<stud.getscore())
{temp=stud.getscore();
strcpy(na,stud.getname());
s=stud.getnum();
}
}
void main()
{student stud[3]={student(1,"k",90),student(2,"m",95),student(3,"u",92)};
for(int i=0;i<3;i++)student::max(stud[i]);
student::display();
}


S(a+b)=3.5*1+2*1+2=7.5
结果为 7.5
7前面两个空格,最后换行

class student
{public:
student(int n,char name[],int sc)
{num=n;
strcpy(this->name,name);//这里修改**********
score=sc;
}
char *getname()
{return name;}
int getnum()
{return num;}
int getscore()
{return score;
}
static void display()
{cout<<s<<' '<<na<<' '<<temp<<endl;
}
static void max(student&);//
private:
int num;
char name[20];
int score;
static int temp;
static char na[20];
static int s;

};
int student::temp=-1;
char student::na[20]=" ";
int student::s=0;
void student::max(student&stud)
{if(temp==-1)temp=stud.getscore();
if(temp<stud.getscore())
{temp=stud.getscore();
strcpy(na,stud.getname());
s=stud.getnum();
}
}
void main()
{student stud[3]={student(1,"k",90),student(2,"m",95),student(3,"u",92)};
for(int i=0;i<3;i++)student::max(stud[i]);
student::display();
}

 相关问题
·一段搞不定的c++代码
·一个C语言程序选择题,我不懂什么意思?
·元音什么字母 辅音什么字母
·编程入门应该学什么
·SQL与oracle
·do i have to say sorry to u ?是什么意思
·如何用logo语言画火炬
·重力的定义与产生条件是?
·谁能解密这段字符?
·C++语言问题
·Dreamweaver 8连后台Access数据库
·若程序中有下面的说明和定义,则会发生的情况是编译出错.
·Delphi连接Access后为什么只显现出一条数据库的记录?
·两位数的十位上的数字比个位上的数字小1,十位上的数字扩...
·印度语是埃及的其中一种语言吗?

 《一段搞不定的c++代码》答案收集时间:2008-06-14 14:39:47



©2007 电脑技术问答录