C++谁帮我调试下这个程序 不知道错在哪里??

来源:百度知道 编辑:UC知道 时间:2024/06/14 06:18:24
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
class Tstudent
{
private:
int sno;
char sname[10];
float score;
public:
Tstudent(int no,char *name,float sco);
void stushow();
}
Tstudent::Tstudent(int no,char *name,float sco)
{
sno=no;
strcpy(sname,name);
score=sco;
}
void Tstudent::stushow()
{
cout<<setw(8)<<sno<<setw(10)<<sname<<setw(6)<<score<<endl;
}

void main()
{
Tstudent t1(10011,"JIE",100),t2(10012,"KOBE",98);
cout<<setw(8)<<"no"<<setw(10)<<"name"<<setw(6)<<"score"<<endl;
t1.stushow();
t2.stushow();
}

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

class Tstudent
{
public:
Tstudent();
Tstudent(int no,char *name,double sco) : sno(no), score(sco)
{
strcpy(sname,name);
}
void stushow();
private:
int sno;
char sname[10];
double score;

};

void Tstudent::stushow()
{
cout<<setw(8)<<sno<<setw(10)<<sname<<setw(6)<<score<<endl;
}

void main()
{
Tstudent t1(10011,"JIE",100);
Tstudent t2(10012,"KOBE",98);
cout<<setw(8)<<"no"<<setw(10)<<"name"<<setw(6)<<"score"<<endl;
t1.stushow();
t2.stushow();
}

注意几个问题:
尽量不要使用带.h的头文件,因为可植性不高,不是C++STL标准库里面的;
尽量使用double,不要使用float;

setw是什么东东。。。