关于VC++6运行程序后出现“出现一个问题,导致程序停止正常工作。请关闭该程序”,望解决,谢谢!

以下是程序代码:#include<iostream.h>#include<string.h>classStudent{public:Student(char*pName,... 以下是程序代码:
#include<iostream.h>
#include<string.h>

class Student
{
public:
Student(char* pName,int xHours,float xgpa)
{

cout<<"constructing student "<<pName<<'\t'<<xHours<<'\t'<<xgpa<<endl;

name=new char[strlen(pName)+1];
if(name!=0)
{
strcpy(name,pName);
}

semesHours=xHours;
gpa=xgpa;
}

~Student()
{
cout<<"destructing "<<name<<'\t'<<semesHours<<'\t'<<gpa<<endl;
name[0]='\0';
delete name;
}

Student(){}

protected:

char * name;
int semesHours;
float gpa;
};

class Teacher
{
public:
Teacher()
{
cout<<"constructing teacher.\n";
}
~Teacher()
{
cout<<"destructing teacher.\n";
}

};

class TutorPair
{
public:
TutorPair()
{
cout<<"construting tutorpair.\n";
noMeetings=0;
}
~TutorPair()
{
cout<<"destructing tutorpair.\n";
}

protected:
Student student;
Teacher teacher;
int noMeetings;
};

void main()
{
Student ss("Jenny",22,3.5);
cout<<"\n";
TutorPair fg;
cout<<"back in main.\n";

}
展开
 我来答
匿名用户
2012-06-01
展开全部
问题在 Student 类:
第一、Student 类的析构函数定义写错。
第二、需要定义 Student 类的默认构造函数。

参考以下代码:
class Student
{
public:
Student( char * pName = "no name", int xHours = 0, float xgpa = 0.0 )
{

cout << "constructing student " << pName << '\t' << xHours << '\t' << xgpa << endl;
name = new char[strlen(pName)+1];
if ( name != 0 )
{
strcpy( name, pName );
}
semesHours = xHours;
gpa = xgpa;
}

~Student()
{
cout << "destructing " << name << '\t' << semesHours << '\t' << gpa << endl;
delete [] name;
}

protected:
char * name;
int semesHours;
float gpa;
};
zcy990718
2012-06-08 · TA获得超过1.2万个赞
知道大有可为答主
回答量:1.2万
采纳率:66%
帮助的人:1545万
展开全部
#include<iostream.h>
#include<string.h>

class Student
{
public:
Student(char* pName,int xHours,float xgpa)
{

cout<<"constructing student "<<pName<<'\t'<<xHours<<'\t'<<xgpa<<endl;

name=new char[strlen(pName)+1];
if(name!=0)
{
strcpy(name,pName);
}

semesHours=xHours;
gpa=xgpa;
}

~Student()
{
if(name)
{
cout<<"destructing "<<name<<'\t'<<semesHours<<'\t'<<gpa<<endl;
name[0]='\0';
delete name;
}
}

Student()
{
name = NULL;
semesHours = 0;
gpa = 0;
}
protected:
char * name;
int semesHours;
float gpa;
};

class Teacher
{
public:
Teacher()
{
cout<<"constructing teacher.\n";
}
~Teacher()
{
cout<<"destructing teacher.\n";
}

};

class TutorPair
{
public:
TutorPair()
{
cout<<"construting tutorpair.\n";
noMeetings=0;
}
~TutorPair()
{
cout<<"destructing tutorpair.\n";
}

protected:
Student student;
Teacher teacher;
int noMeetings;
};

void main()
{
Student ss("Jenny",22,3.5);
cout<<"\n";
TutorPair fg;
cout<<"back in main.\n";

}
//记得给分哦
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wk618520hrj
2012-06-02 · 超过32用户采纳过TA的回答
知道答主
回答量:208
采纳率:0%
帮助的人:107万
展开全部
无法生成可执行文件
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式