【正文】
// default constructor void setDate( int, int, int )。 // is not a leap year} // end function leapYearint Date::monthDays(){ const int days[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }。 // sets year} // end function setYearint Date::getDay() { return day。 include // include definition of class DateDate::Date( int m, int d, int y ) { setDate( m, d, y )。 // default constructor void print()。} // end function printUniversal// print Time in standardtime format (HH:MM:SS AM or PM)void Time::printStandard(){ cout (( getHour() == 0 || getHour() == 12 ) ? 12 : getHour() % 12 ) : setfill( 39。 h 24 ) ? h : 0。 // output time in universaltime format void printStandard()。\n39。 // prints rational object d x = ( d )。 // prints rational object x as double cout \n\n。 denominator /= gcd。} // end function divisionvoid Rational::printRational (){ if ( denominator == 0 ) // validates denominator cout \nDIVIDE BY ZERO ERROR!!! 39。 = denominator * 。 // integer denominator void reduction()。 // invoke add function and assign to object c ()。 include int main(){ Complex a( 1, 7 ), b( 9, 2 ), c。 double imaginaryPart。 cout \nOriginal date: endl。} // end function setMonth// return monthint Date::getMonth(){ return month。 // return day void setYear( int )。 // give each Employee a 10% raise ( monthlySalary1 * )。 if not positive, set to void Employee::setMonthlySalary( int salary ){ if ( salary 0 ) // if salary is positive monthlySalary = salary。 // return weekly salaryprivate: string firstName。 //negative quantity,so quantity set to 0 ( 10 )。 // set pricePerItem to price if ( price = 0 ) // if price is not positive { pricePerItem = 0。// include definition of class Invoice from include // Invoice constructor initializes the class39。 // set and get functions for the four data members void setPartNumber( string )。 int withdrawalAmount。using std::endl。 using std::endl。 // display wele message and instructor nameprivate: string courseName。 // course name for this GradeBook string instructorName。// include definition of class GradeBook from include // function main begins program executionint main(){ // create a GradeBook object。include // include definition of class Account// Account constructor initializes data member balanceAccount::Account( int initialBalance ){ balance = 0。 // stores withdrawal amount read from user cout \nEnter withdrawal amount for account1: 。 // part number string getPartNumber()。s four data membersInvoice::Invoice( string number, string description, int count, int price ){ setPartNumber( number )。 // set pricePerItem to 0 cout \npricePerItem cannot be negative. pricePerItem set to 0.\n。 cout \nInvoice data members modified.\n\n。 // Employee39。 // set monthlySalary to salary if ( salary = 0 ) // if salary is not positive monthlySalary = 0。 ( monthlySalary2 * )。 // set year int getYear()。} // end function getMonth// set dayvoid Date::setDay( int d ){ day = d。 ()。}。 // create three Complex objects ()。 // output object c cout endl。 // utility function}。 = * denominator。\n39。 } // end if } // end function reduction測(cè)試函數(shù):include iostream using std::cout。 ()。 // multiplies object c and d cout = 。 ()。 // output time in standardtime formatprivate: int hour。 // validate hour} // end function setHour// set minute valuevoid Time::setMinute( int m ){ minute = ( m = 0 amp。039。 // print function void setDate( int, int, int )。 // sets date } // end Date constructorvoid Date::setDate( int mo, int dy, int yr ){ setMonth( mo )。} // end function getDayint Date::getMonth() { return month。 return month == 2 amp。 // set month, day, year void setMonth( int )。} // end main類定義:ifndef DATEANDTIME_Hdefine DATEANDTIME_Hclass DateAndTime {public: DateAndTime( int = 1, int = 1, int = 1900,int = 0, int = 0, int = 0 )。 // is a leap year else return false。 // sets month } // end function setMonthvoid Date::setYear( int y ) { year = y = 1900 ? y : 1900。 // end class Dateendif類成員函數(shù):include iostream using std::cout。} // end main類定義:ifndef DATE_Hdefine DATE_Hclass Date {public: Date( int = 1, int = 1, int = 1900 )。 ) setw( 2 ) getHour() : setw( 2 ) getMinute() : setw( 2 ) getSecond()。amp。 // increment one second void printUniversal()。 // prints rational object x cout 39。 ()。 ()。 if (gcd != 0) { numerator /= gcd。 // store the fraction in reduced form return t。 // creates Rational object = * numerator。 // integer numerator int denominator。 c = ( b )。 using std::endl。 // set plex number private: double realPart。 cout Year: () endl。 if ( month 12 ) month = 1。 // set day int getDay()。 cout () () : $ monthlySalary2 * 12 endl。} // end function getLastName// set monthly salary。 // set weekly salary int getMonthlySalary()。 ( 5 )。 if not positive, set to 0void Invoice::setPricePerItem( int price ){ if ( price 0 ) // if price is positive pricePerItem = price。using std::endl。// Invoice class definitionclass Invoice{public: // constructor initializes the four data members Invoice( string, string, int, int )。 cout account2 balance: $ () endl。 // end class Account類成員函數(shù):include iostreamusing std::cout。} // end function displayMessage測(cè)試文件:include iostreamusing std::cout。 // function to retrieve instructo