【正文】
structor name for this GradeBook}。class GradeBook{public: // constructor initializes course name and instructor name GradeBook( string, string )。 // function to retrieve instructor name void displayMessage()。 // initialiZes instructorName} // end GradeBook constructor// function to set the course namevoid GradeBook::setCourseName( string name ){ courseName = name。} // end function displayMessage測(cè)試文件:include iostreamusing std::cout。s name ()。 // end class Account類成員函數(shù):include iostreamusing std::cout。 if ( amount = balance ) // debit amount does not exceed balance balance = balance amount。 cout account2 balance: $ () endl。 cout \nEnter withdrawal amount for account2: 。// Invoice class definitionclass Invoice{public: // constructor initializes the four data members Invoice( string, string, int, int )。 // price per item int getPricePerItem()。using std::endl。} // end function getPartNumber// set part descriptionvoid Invoice::setPartDescription( string description ){ partDescription = description。 if not positive, set to 0void Invoice::setPricePerItem( int price ){ if ( price 0 ) // if price is positive pricePerItem = price。// include definition of class Invoice from include // function main begins program executionint main(){ // create an Invoice object Invoice invoice( 12345, Hammer, 100, 5 )。 ( 5 )。 return 0。 // set weekly salary int getMonthlySalary()。 // end class Employee類成員函數(shù):include iostreamusing std::cout。} // end function getLastName// set monthly salary。 // display each Employee39。 cout () () : $ monthlySalary2 * 12 endl。 cout () () : $ monthlySalary1 * 12 endl。 // set day int getDay()。 // end class Date類成員函數(shù):include iostreamusing std::cout。 if ( month 12 ) month = 1。 day 39。 cout Year: () endl。 // output the modified date (1/1/2005) return 0。 // set plex number private: double realPart。right ){ return Complex( realPart , imaginaryPart )。 using std::endl。 // output object c cout 39。 c = ( b )。 )。 // integer numerator int denominator。a ){ Rational t。 // creates Rational object = * numerator。 = * denominator。 // store the fraction in reduced form return t。 } // end function printRationalAsDoublevoid Rational::reduction(){ int largest。 if (gcd != 0) { numerator /= gcd。 // prints rational object d x = ( d )。 ()。 // prints rational object x cout 39。 ()。 ()。 // prints rational object x cout 39。 // default constructor // set functions void setTime( int, int, int )。 // increment one second void printUniversal()。using std::setw。amp。 // validate second} // end function setSecond// return hour valueint Time::getHour(){ return hour。 ) setw( 2 ) getHour() : setw( 2 ) getMinute() : setw( 2 ) getSecond()。 // instantiate object t of class Time ( 23, 59, 57 )。} // end main類定義:ifndef DATE_Hdefine DATE_Hclass Date {public: Date( int = 1, int = 1, int = 1900 )。 // get day int getYear()。 // end class Dateendif類成員函數(shù):include iostream using std::cout。amp。 // sets month } // end function setMonthvoid Date::setYear( int y ) { year = y = 1900 ? y : 1900。 year 39。 // is a leap year else return false。 Date d( 12, 24, 2004 )。} // end main類定義:ifndef DATEANDTIME_Hdefine DATEANDTIME_Hclass DateAndTime {public: DateAndTime( int = 1, int = 1, int = 1900,int = 0, int = 0, int = 0 )。 // set hour void setMin。 // set month, day, year void setMonth( int )。s value for ( int loop = 1。 return month == 2 amp。 // outputs date} // end function printvoid Date::nextDay(){ setDay( day + 1 )。} // end function getDayint Date::getMonth() { return month。 else day = ( d = monthDays() amp。 // sets date } // end Date constructorvoid Date::setDate( int mo, int dy, int yr ){ setMonth( mo )。 // next dayprivate: int month。 // print function void setDate( int, int, int )。s values for ( int ticks = 1。039。} // end function getMinute// return second valueint Time::getSecond(){ return second。 // validate hour} // end function setHour// set minute valuevoid Time::setMinute( int m ){ minute = ( m = 0 amp。// ensures that Time objects start in a consistent state Time::Time( int hr, int min, int sec ) { setTime( hr, min, sec )。 // output time in standardtime formatprivate: int hour。 // set hour (after validation) void setMinute( int )。 ()。 ()。 // multiplies object c and d cout = 。 ()。 ()。 sets the value to x cout = 。 } // end if } // end function reduction測(cè)試函數(shù):include iostream using std::cout。 int gcd = 0。\n39。 // store the fraction in reduced form return t。 = * denominator。 += * numerator。 // utility function}。 )。 // output object c cout endl。 ( 10, 1 )。 // create three Complex objects ()。(39。}。 // default constructor Complex add( const Complex amp。 ()。 year endl。} // end function getMonth// set dayvoid Date::setDay( int d ){ day = d。include // include definition of class Date from // Date constructor that initializes the three data members。 // set year int getYear()。 cout () () : $ monthlySalary2 * 12 endl。 ( monthlySalary2 * )。 yearly salaries: endl。 // set monthlySalary to salary if ( salary = 0 ) // if salary is not positive monthlySalary = 0。 // store first name setLastName( last )。 // Employee