【正文】
// set year void nextDay()。 // invokes function print ()。} // end function monthDays測試函數(shù):include iostream using std::cout。 // increments year by 1 } // end if statement } // end function nextDaybool Date::leapYear(){ if ( year % 400 == 0 || ( year % 4 == 0 amp。39。} // end function setDayvoid Date::setMonth( int m ) { month = m = 12 amp。 // invokes function setYear} // end function setDatevoid Date::setDay( int d ){ if ( month == 2 amp。 // 1900+ bool leapYear()。 // set day void setYear( int )。 // invokes function printStandard cout endl。 using std::endl。 // increment minute by 1 if ( getMinute() == 0 ) setHour( getHour() + 1 )。 // validate minute} // end function setMinute// set second valuevoid Time::setSecond( int s ){ second = ( s = 0 amp。 // set private field hour setMinute( m )。 // 0 59}。 // return hour int getMinute()。 // prints rational object x as double cout endl。 // prints rational object d x = ( d )。\n39。 // prints rational object x as double cout \n\n。 // prints rational object d x = ( d )。\n39。 // creates three rational objects ()。 loop++ ) if ( numerator % loop == 0 amp。/39。 // creates Rational object = * numerator。} // end function subtractionRational Rational::multiplication( const Rational amp。 // store the fraction in reduced form return t。 // sets numerator denominator = d。 // function division void printRational ()。 // default constructor Rational addition( const Rational amp。 // output object a cout 。 // output object b cout = 。} // end function printComplexvoid Complex::setComplexNumber( double rp, double ip ) { realPart = rp。 } // end Complex constructorComplex Complex::add( const Complex amp。 )。 ( 2005 )。include // include definition of class Date from // function main begins program executionint main(){ Date date( 5, 6, 1981 )。} // end function setYear// return yearint Date::getYear(){ return year。 setYear( y )。 // the month of the date int day。 // constructor initializes data members void setMonth( int )。 yearly salaries after 10% raise: endl。 cout () () : $ monthlySalary1 * 12 endl。using std::endl。 // no validation needed} // end function setFirstName// return first namestring Employee::getFirstName(){ return firstName。s last name int monthlySalary。 // return first name void setLastName( string )。 cout Quantity: () endl。 cout Invoice amount: $ () endl。} // end function getInvoiceAmount測試函數(shù):include iostreamusing std::cout。 // set quantity to 0 cout \nquantity cannot be negative. quantity set to 0.\n。 // validate and store quantity setPricePerItem( price )。 // how many of the items are being sold int pricePerItem。 void setQuantity( int )。 cout account2 balance: $ () endl。 ( withdrawalAmount )。// include definition of class Account from include // function main begins program executionint main(){ Account account1( 50 )。 // if initialBalance is negative, print error message if ( initialBalance 0 ) cout Error: Initial balance cannot be negative.\n endl。 // subtract an amount from the account balance int getBalance()。 // modify the instructorName using set function ( Assistant Professor Bates )。s namevoid GradeBook::displayMessage(){ // display a wele message containing the course name cout Wele to the grade book for\n getCourseName() ! endl。using std::endl。 // function to set the course name string getCourseName()。 // function to retrieve the course name void setInstructorName( string )。include // constructor initializes courseName and instructorName // with strings supplied as argumentsGradeBook::GradeBook( string course, string instructor ){ setCourseName( course )。 // display the instructor39。 // display new value of instructorName cout new gradeBook instructor name is: () \n\n。 // return the account balanceprivate: int balance。} // end Account constructor// credit (add) an amount to the account balancevoid Account::credit( int amount ){ balance = balance + amount。 // create Account object Account account2( 25 )。 // try to subtract from account1 // display balances cout account1 balance: $ () endl。 return 0。 // quantity int getQuantity()。 // price per item}。 // validate and store pricePerItem} // end Invoice constructor// set part numbervoid Invoice::setPartNumber( string number ){ partNumber = number。 } // end if} // end function setQuantity// get quantityint Invoice::getQuantity(){ return quantity。using std::cin。 // modify the invoice data members ( 123456 )。 cout Price per item: $ () endl。 // set last name string getLastName()。 // Employee39。} // end function getFirstName// set last namevoid Employee::setLastName( string name ){ lastName = name。include // include definition of class Employee// function main begins program executionint main(){ // create two Employee objects Employee employee1( Lisa, Roberts, 4500 )。 // retrieve and display employee239。 // retrieve and display employee139。 // set month int getMonth()。 // the day of the date int year。} // end Date constructor // set monthvoid Date::setMonth( int m ){ month = m。} // end function getYear// print Date in the format mm/dd/yyyyvoid Date::displayDate() { cout month 39。 // create a Date object for May 6, 1981 // display the values of the three Date data members cout Month: () endl。 cout \nNew date: endl。 // function subtract void printComplex()。right