正在学c++,试着写了个小型的图书馆管理系统,写了一部分就遇到个问题,大家帮帮忙!
只需看下红色部分就可以了,是关于一个赋值的问题:
#include<iostream.h>
#include<afx.h>
class BookCard //图书卡类
{public:
int m_bCount; //书的数量
CString m_bKind; //书的种类
CString m_bName; //书名
CString m_bNum; //书的编号
CString m_bAuthorName; //作者姓名
void BookCardRegister(CString Kind,CString Name,CString AuthorName,
CString Num,int Count); //新书入库
};
class Validity //借书证类
{public:
CString m_vName; //姓名
CString m_vSex; //性别
CString m_vNum; //学号
CString m_vDepartment; //所在学院
void ValidityRegister(CString Name,CString Sex,CString Num,CString Department);//借书证入库
};
class LendRecord:public BookCard,public Validity//借书记录类
{
CTime m_lLendTime; //借出时间
CTime m_lReturnTime; //归还时间
public:
void LendStatistics(CString BookName,CString BookNum,CString StudentName,CString sex,
CString StudentNum,CTime LendTime,CTime ReturnTime);//借书登记
int ReturnStatistics(CString BookName,CString BookNum,CString StudentName,CString sex,
CString StudentNum,CTime LendTime,CTime ReturnTime);//还书处理
};
void BookCard::BookCardRegister(CString Kind,CString Name,CString Num,CString AuthorName,
int Count)
{
m_bKind=Kind;
m_bName=Name;
m_bNum=Num;
m_bAuthorName=AuthorName;
m_bCount=0;
m_bCount=m_bCount+Count;
}
void Validity::ValidityRegister(CString Name,CString Sex,CString Num,CString Department)
{
m_vName=Name;
m_vSex=Sex;
m_vNum=Num;
m_vDepartment=Department;
}
void LendRecord::LendStatistics(CString BookName,CString BookNum,CString StudentName,CString Sex,
CString StudentNum,CTime LendTime,CTime ReturnTime)
{
m_bName=BookName;
m_bNum=BookNum;
m_vName=StudentName;
m_vSex=Sex;
m_vNum=StudentNum;
m_lLendTime=LendTime;
m_lReturnTime=ReturnTime;
}
int LendRecord::ReturnStatistics(CString BookName,CString BookNum,CString StudentName,CString Sex,
CString StudentNum,CTime LendTime,CTime ReturnTime)
{
int overdue=0;
CTimeSpan interval;
m_bName=BookName;
m_bNum=BookNum;
m_vName=StudentName;
m_vSex=Sex;
m_vNum=StudentNum;
m_lLendTime=LendTime;
m_lReturnTime=ReturnTime;
interval=ReturnTime-LendTime;
overdue=(interval>CTimeSpan(180,0,0,0)?1:0);
return overdue;
}
void main()
{
BookCard Book;
Validity Docu;
LendRecord Record;
CTime LendTime,ReturnTime;
LendTime=CTime(2005,9,1,0,0,0);
ReturnTime+=CTimeSpan(180,0,0,0);
Book.BookCardRegister("计算机","c语言程序设计","谭浩强","050201",150);
Docu.ValidityRegister("张三","男","026210101","计算机信息工程学院");
Record.LendStatistics("c语言程序设计","050201","张三","男","026210101",LendTime,ReturnTime);
Record.ReturnStatistics("c语言程序设计","050201","张三","男","026210101",LendTime,ReturnTime);
cout<<"馆内现有"<<Book.m_bCount<<"本"<<"<<"<<Book.m_bName<<">>"<<"教材!"<<endl;
cout<<LendTime.Format("%B%d,%Y")<<"借出一本"<<endl;
cout<<"借阅者:"<<endl;
cout<<"Department:\t";
cout<<Record.m_vDepartment<<endl;
cout<<"Name:\t";
cout<<Record.m_vName<<endl;
cout<<"Sex:\t";
cout<<Record.m_vSex<<endl;
cout<<"Num:\t";
cout<<Record.m_vNum<<endl;
}
跟踪调试过程中,函数ValidityRegister中的m_vDepartment=Department顺利执行,但m_vDepartment的输出结果确是空的!
m_vDepartment,_vName,m_vSex,m_vNum等都是公有继承Validity类的,惟独m_vDepartment输出的结果是空的...
大家大家指点指点,谢啦!
编程中遇到的问题