home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD1.iso / workshop / c / files / student.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-03  |  2.0 KB  |  98 lines

  1. #include "student.h"
  2. #include "studutes.h"
  3. #include <iomanip>
  4. #include <string>
  5. #include <cstdlib>
  6.  
  7. CStudent::CStudent()
  8. : m_studNo(0)
  9. {
  10. }
  11.  
  12.  
  13. CStudent::CStudent(unsigned   sNo,
  14.              const std::string &fNam,
  15.              const std::string &oNam,
  16.              const std::string &addr,
  17.              const std::string &DOB)
  18. : m_studNo(sNo)
  19. , m_familyName(fNam)
  20. , m_otherNames(oNam) 
  21. , m_address(addr) 
  22. , m_DOB(DOB)
  23. {
  24. }
  25.  
  26. unsigned CStudent::StudentNo() const
  27. {
  28.    return m_studNo;
  29. }
  30.  
  31. const std::string &CStudent::FamilyName() const 
  32. {
  33.    return m_familyName;
  34. }
  35.  
  36. const std::string &CStudent::OtherName() const
  37. {
  38.    return m_otherNames;
  39. }
  40.  
  41. const std::string &CStudent::Address() const
  42. {
  43.    return m_address;
  44. }
  45.  
  46. const std::string &CStudent::DOB() const
  47. {
  48.    return m_DOB;
  49. }
  50.  
  51. bool CStudent::Read(std::ifstream &is)
  52. {
  53.    SStudent s;
  54.  
  55.    is.read(reinterpret_cast<char *>(&s), 
  56.            sizeof(SStudent));
  57.    m_studNo     = s.m_studNo;
  58.    m_familyName = s.m_familyName;
  59.    m_otherNames = s.m_otherNames;
  60.    m_address    = s.m_address;
  61.    m_DOB        = s.m_DOB;
  62.  
  63.    return is.good();
  64. }
  65.  
  66. bool CStudent::Write(std::ofstream &os)
  67. {
  68.    SStudent s;
  69.  
  70.     s.m_studNo = m_studNo;
  71.    StudUtes::SafeCopy(s.m_familyName, 
  72.                       m_familyName.c_str(), 
  73.                       LENSTR);
  74.    StudUtes::SafeCopy(s.m_otherNames, 
  75.                       m_otherNames.c_str(), 
  76.                       LENSTR);
  77.    StudUtes::SafeCopy(s.m_address,    
  78.                       m_address.c_str(), 
  79.                       LENSTR);
  80.    StudUtes::SafeCopy(s.m_DOB,        
  81.                       m_DOB.c_str(), 
  82.                       LENDOB);
  83.  
  84.    //os << std::ios_base::binary;
  85.    os.write(reinterpret_cast<char *>(&s), 
  86.             sizeof(SStudent));
  87.    return os.good();
  88. }
  89.  
  90. bool CStudent::Print(std::ostream &os)
  91. {
  92.    os << m_studNo     << std::endl
  93.       << m_familyName << std::endl
  94.       << m_otherNames << std::endl
  95.       << m_address    << std::endl
  96.       << m_DOB        << std::endl;
  97.    return os.good();
  98. }