assign23.zip

Assign2/dateType.cpp

Assign2/dateType.cpp

/*
*  Programming Assignment: 2
*  Course: COMSC-1351.A
*  Program Name: dateType.cpp
*  Author: Xusheng Wang
*  Date: 01/28/2015
*
*  Description: This file contains the function implementation details for the class dateType              
*/

#include   < iostream >
#include   "dateType.h"
using   namespace  std ;

void  dateType :: setDate ( int  mm ,   int  dd ,   int  yy )
{
     year  =  yy ;                   // set year 
      if   ( mm  >=   1   &&  mm  <=   12 )
        month  =  mm ;               // set month
      else
        month  =   1 ;  
      if   (( month == 1   ||  month == 3   ||  month == 5   ||  month == 7   ||  month == 8   ||  month == 10   ||  month == 12 )
           &&  dd  >=   1   &&  dd  <=   31 )
        day  =  dd ;                 // set day 
      else   if   (( month == 4   ||  month == 6   ||  month == 9   ||  month == 11 )   &&  dd  >=   1   &&  dd  <=   30 )
        day  =  dd ;  
      else   if   ( month == 2   &&  year % 4 == 0   &&  dd >= 1   &&  dd <= 29 )
        day  =  dd ;
      else   if   ( month == 2   &&  year % 4 != 0   &&  dd >= 1   &&  dd <= 28 )
        day  =  dd ;
      else
        day  =   1 ;
}

int  dateType :: getYear ()   const
{
     return  year ;
}

int  dateType :: getMonth ()   const
{
     return  month ;
}

int  dateType :: getDay ()   const
{
     return  day ;
}

void  dateType :: print ()   const          // print the date
{
    cout  <<   "Birth Date: " ;
     if   ( month  <   10 )  cout  <<   "0" ;
    cout  <<  month  <<   "/" ;
     if   ( day  <   10 )  cout  <<   "0" ;
    cout  <<  day  <<   "/"   <<  year  <<  endl ;
}

dateType :: dateType ( int  mm ,   int  dd ,   int  yy )   // a constructor 
{
    setDate ( mm ,  dd ,  yy );                  // set a date 
}

dateType :: dateType ( const  dateType &  aDate )   // copy constructor 
{
    setDate ( aDate . month ,  aDate . day ,  aDate . year );      // set a date 
}

Assign2/dateType.h

/* * Programming Assignment: 2 * Course: COMSC-1351.A * Program Name: dateType.h * Author: Xusheng Wang * Date: 01/28/2015 * * Description: This file contains the function prototype of the class dateType */ #ifndef H_dateType #define H_dateType class dateType { public: void setDate(int, int, int); // set the date int getYear() const; // get the year int getMonth() const; // get the month int getDay() const; // get the day void print() const; // print the date dateType(int mm=1, int dd=1, int yy=2000); // a constructor with parameters dateType(const dateType&); // copy constructor private: int month; // store the mounths int day; // store the days int year; // store the years }; #endif

Assign2/myMain.cpp

Assign2/myMain.cpp

/*
*  Programming Assignment: 2
*  Course: COMSC-1351.A
*  Program Name: myMain.cpp
*  Author: Xusheng Wang
*  Date: 01/28/2015
*
*  Description: This program tests the studentType class.
*/

#include   < iostream >
#include   < iomanip >
#include   "studentType.h"
using   namespace  std ;

int  main ()
{
    cout << fixed << showpoint << setprecision ( 2 );
    
    studentType s1 ;
    cout  <<   "The following is the information in the studentType object - s1:"   <<  endl ;
    s1 . print ();
    cout  <<  endl ;
    
    s1 . setSID ( 221836790 );
    s1 . setName ( const_cast < char   *> ( "Victoria" ),   const_cast < char   *> ( "Garcia" ));
    s1 . setBirthDate ( 7 ,   21 ,   1998 );
    s1 . setGrade ( 92.5 );
    s1 . setFullTime ( true );
    cout  <<   "The following is the information in the studentType object - s1:"   <<  endl ;
    s1 . print ();
    cout  <<  endl ;
    
    nameType aName ( const_cast < char   *> ( "Jack" ),   const_cast < char   *> ( "Lewis" ));
    dateType aDate ( 3 ,   18 ,   1997 );
    studentType s2 ( 221825166 ,  aName ,  aDate ,   88.0 ,   false );
    cout  <<   "The following is the information in the studentType object - s2:"   <<  endl ;
    s2 . print ();
    cout  <<  endl ;
    
     // change s2's name to "David Freeman", birth date to 02/29/1998, and full time to true
     // and call .print() method to print the information in s2 again.

    
    
    
    
    
    
    
    
    
     // create s3 and output s3 with cout and get methods. You cannot call the .print() method
     // to print the s3 object. Your output information and format should be the same as that
     // generated by the .print() method.
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
     //system("PAUSE");
     return   0 ;    
}

Assign2/nameType.cpp

Assign2/nameType.cpp

/*
*  Programming Assignment: 2
*  Course: COMSC-1351.A
*  Program Name: nameType.cpp
*  Author: Xusheng Wang
*  Date: 01/28/2015
*
*  Description: This file contains the function implementation details for the class nameType              
*/

#include   < iostream >
#include   < cstring >
#include   "nameType.h"
using   namespace  std ;

void  nameType :: setName ( char  first [],   char  last [])
{
    strcpy ( firstName ,  first );     // set the first name
    strcpy ( lastName ,  last );       // set the last name
}

void  nameType :: getName ( char  first [],   char  last [])   const
{
    strcpy ( first ,  firstName );     // get the first name
    strcpy ( last ,  lastName );       // get the last name
}
void  nameType :: print ()   const      // print the name
{
    cout  <<   "Name: "   <<  firstName  <<   " "   <<  lastName  <<  endl ;
}

nameType :: nameType ()              // default constructor
{
    firstName [ 0 ]   =   '\0' ;          // set the first name to null string
    lastName [ 0 ]   =   '\0' ;           // set the last name to null string
}

nameType :: nameType ( char  first [],   char  last [])   // parameter constructor 
{
    setName ( first ,  last );         // set the name
}

nameType :: nameType ( const  nameType &  aName )     // copy constructor 
{
    strcpy ( firstName ,  aName . firstName );       // set the first name
    strcpy ( lastName ,  aName . lastName );         // set the last name     
}

Assign2/nameType.h

/* * Programming Assignment: 2 * Course: COMSC-1351.A * Program Name: nameType.h * Author: Xusheng Wang * Date: 01/28/2015 * * Description: This file contains the function prototype of the class nameType */ #ifndef H_nameType #define H_nameType class nameType { public: void setName(char [], char []); // set the full name void getName(char [], char []) const; // get the full name void print() const; // print the name nameType(); // default constructor nameType(char [], char []); // a constructor with parameters nameType(const nameType&); // copy constructor private: char firstName[30]; // store the first name char lastName[30]; // store the last name }; #endif

Assign2/personType.cpp

Assign2/personType.cpp

/*
*  Programming Assignment: 2
*  Course: COMSC-1351.A
*  Program Name: personType.cpp
*  Author: Xusheng Wang
*  Date: 01/28/2015
*
*  Description: This file contains the function implementation details for the class personType              
*/

#include   < iostream >
#include   "personType.h"
using   namespace  std ;

// Add your implement code for personType below


Assign2/personType.h

/* * Programming Assignment: 2 * Course: COMSC-1351.A * Program Name: personType.h * Author: Xusheng Wang * Date: 01/28/2015 * * Description: This file contains the function prototype of the class personType */ #ifndef H_personType #define H_personType #include "nameType.h" #include "dateType.h" class personType { public: void setSID(long); // set the SSN long getSID() const; // get the SSN void setName(char [], char []); // set the name void setName(nameType&); // set the name nameType getName() const; // get the name void setBirthDate(int, int, int); // set the birthDate void setBirthDate(dateType&); // set the birthDate dateType getBirthDate() const; // get the birthDate void print() const; // print the person personType(); // default constructor personType(long, nameType&, dateType&); // a constructor with parameters personType(long, char [], char [], int, int, int); // a constructor with parameters personType(const personType&); // copy constructor protected: long SID; // store person's SSN nameType name; // store person's full name dateType birthDate; // store person's birthDate }; #endif

Assign2/studentType.cpp

Assign2/studentType.cpp

/*
*  Programming Assignment: 2
*  Course: COMSC-1351.A
*  Program Name: studentType.cpp
*  Author: Xusheng Wang
*  Date: 01/28/2015
*
*  Description: This file contains the function implementation details for the class studentType              
*/

#include   < iostream >
#include   < string >
#include   < cstring >
#include   "studentType.h"
using   namespace  std ;

// Add your implement code for studentType below


Assign2/studentType.h

/* * Programming Assignment: 2 * Course: COMSC-1351.A * Program Name: studentType.h * Author: Xusheng Wang * Date: 01/28/2015 * * Description: This file contains the function prototype of the class studentType */ #ifndef H_studentType #define H_studentType #include "nameType.h" #include "dateType.h" #include "personType.h" class studentType : public personType { public: void setGrade(double); // set the salary double getGrade() const; // get the salary void setFullTime(bool); // set the full-time flag to true or false bool getFullTime() const; // get the full-time flag void print() const; // print the faculty studentType(); // default constructor studentType(long, nameType&, dateType&, double, bool); // a constructor with all parameters studentType(long, char [], char [], int, int, int, double, bool); // a constructor with all parameters studentType(const studentType&); // copy constructor private: double grade; // store faculty's salary bool fullTime; // true: full time, false: part time }; #endif