在主函数中,为什么我的for不能结束循环?还会出现死循环?
#include<iostream.h>#include<string.h>
//日期类
class Date
{
public:
int year,month,day;
Date(int y=2000,int m=1,int d=1) //构造函数,日期
{
year=y;
month=m;
day=d;
}
void showday( )
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
};
int Num=0;//全局变量
class Teacher//老师类
{
public:
int num;//编号
char name[10];//名字
char sex[2];//性别
Date birthday;//成员生日
Teacher(char name[],char [],int Num,int y,int m,int d);//构造函数,名字,
int getnum( );
void show( );
};
Teacher::Teacher(char n[], char s[],int Num,int y,int m,int d):birthday(y,m,d)//构造函数
{
Num++;
num=Num;
strcpy(name,n);
strcpy(sex,s);
}
void Teacher::show( )
{
cout<<"编号,名字,性别"<<endl;
cout<<num<<":"<<name<<" "<<sex<<endl;
cout<<"生日:"<<endl;
birthday.showday( );
}
int Teacher::getnum()//成员函数,编号
{
return num;
}
void main()
{
char name[10],sex[2];
char A[2]=A;
int year,month,day;
for(int i=0; ;i++)
{
cout<<"请输入姓名:"<<endl;
cin>>name;
if(name==A)
break;
cout<<"请输入性别:"<<endl;
cin>>sex;
cout<<"请输入生日:"<<endl;
cin>>year>>month>>day;
Teacher t1(name,sex,Num,year,month,day);//调用构造函数
t1.show( );
}
}
[此贴子已经被作者于2016-10-18 23:01编辑过]