C++输出了乱码,求解?
#include <iostream>#include <string.h>
using namespace std;
class Teacher;
class Student{
public:
friend class Teacher;
Student(char *,int);
~Student(){}
private:
char * m_pName;
int m_iScore;
};
Student::Student(char *name,int score)
{
m_pName=new char[strlen(name)+1];
strcpy(m_pName,name);
m_iScore=score;
}
class Teacher{
public:
Teacher(int MAXSIZE)
{
m_pStu=new Student*[MAXSIZE];
}
~Teacher()
{
delete []m_pStu ;
m_pStu=NULL;
}
void Insert(int);
void Sort(int);
void InfoPrint(int);
private:
Student **m_pStu;
};
void Teacher::Insert(int MAXSIZE)
{
char *name;
float score;
for(int i=0;i<MAXSIZE;i++)
{
cout<<"please input the information of the new student";
name=new char[10];
cin>>name;
cin>>score;
Student *newStu=new Student(name,score);
m_pStu=&newStu;
m_pStu=m_pStu+1;
}
}
void Teacher::Sort(int MAXSIZE)
{
Student **temp1,**temp2,**temp;
for(int i=0 ; i<MAXSIZE-1 ;i++)
for(int j=0; j<MAXSIZE-1-i; j++)
{
if( m_pStu[i]->m_iScore > m_pStu[i+1]->m_iScore )
{
temp1=&m_pStu[i];
temp2=&m_pStu[i+1];
temp=temp1;
temp1=temp2;
temp2=temp;
}
}
}
void Teacher::InfoPrint(int MAXSIZE)
{
for(int i=0;i<MAXSIZE;i++)
{
cout<<i<<" Name:"<<(m_pStu[i]->m_pName)<<endl;
cout<<i<<" Score:"+(*(m_pStu+i))->m_iScore<<endl;
cout<<endl;
}
}
int main()
{
int MAXSIZE;
cout << "Please input the student's number" << endl;
cin>>MAXSIZE;
Teacher teacher(MAXSIZE);
teacher.Insert(MAXSIZE);
teacher.Sort(MAXSIZE);
teacher.InfoPrint(MAXSIZE);
return 0;
}
[local]1[/local]