【正文】
mount測(cè)試函數(shù):include iostreamusing std::cout。 // display the invoice data members and calculate the amount cout Part number: () endl。 cout Invoice amount: $ () endl。 //negative quantity,so quantity set to 0 ( 10 )。 cout Quantity: () endl。 // indicate successful termination} // end main類定義:include string // program uses C++ standard string classusing std::string。 // return first name void setLastName( string )。 // return weekly salaryprivate: string firstName。s last name int monthlySalary。include // Employee class definition// Employee constructor initializes the three data membersEmployee::Employee( string first, string last, int salary ){ setFirstName( first )。 // no validation needed} // end function setFirstName// return first namestring Employee::getFirstName(){ return firstName。 if not positive, set to void Employee::setMonthlySalary( int salary ){ if ( salary 0 ) // if salary is positive monthlySalary = salary。using std::endl。s yearly salary cout Employees39。 cout () () : $ monthlySalary1 * 12 endl。 // give each Employee a 10% raise ( monthlySalary1 * )。 yearly salaries after 10% raise: endl。 monthlySalary2 = ()。 // constructor initializes data members void setMonth( int )。 // return day void setYear( int )。 // the month of the date int day。using std::endl。 setYear( y )。} // end function setMonth// return monthint Date::getMonth(){ return month。} // end function setYear// return yearint Date::getYear(){ return year。/39。include // include definition of class Date from // function main begins program executionint main(){ Date date( 5, 6, 1981 )。 cout \nOriginal date: endl。 ( 2005 )。 // indicate successful termination} // end main類定義:ifndef COMPLEX_Hdefine COMPLEX_Hclass Complex {public: Complex( double = , double = )。 )。 double imaginaryPart。 } // end Complex constructorComplex Complex::add( const Complex amp。} // end function subtractvoid Complex::printComplex(){ cout 39。} // end function printComplexvoid Complex::setComplexNumber( double rp, double ip ) { realPart = rp。 include int main(){ Complex a( 1, 7 ), b( 9, 2 ), c。 // output object b cout = 。\n39。 // output object a cout 。 // invoke add function and assign to object c ()。 // default constructor Rational addition( const Rational amp。 // function subtraction Rational multiplication( const Rational amp。 // function division void printRational ()。 // integer denominator void reduction()。 // sets numerator denominator = d。 // creates Rational object = * denominator。 // store the fraction in reduced form return t。 = denominator * 。} // end function subtractionRational Rational::multiplication( const Rational amp。 ()。 // creates Rational object = * numerator。} // end function divisionvoid Rational::printRational (){ if ( denominator == 0 ) // validates denominator cout \nDIVIDE BY ZERO ERROR!!! 39。/39。 largest = numerator denominator ? numerator : denominator。 loop++ ) if ( numerator % loop == 0 amp。 denominator /= gcd。 // creates three rational objects ()。 // adds object c and d。\n39。 // prints rational object x as double cout \n\n。 // prints rational object d x = ( d )。\n39。 // prints rational object x as double cout \n\n。 // prints rational object d x = ( d )。\n39。 // prints rational object x as double cout \n\n。 // prints rational object d x = ( d )。\n39。 // prints rational object x as double cout endl。 // set hour, minute, second void setHour( int )。 // return hour int getMinute()。 // output time in universaltime format void printStandard()。 // 0 59}。include // include definition of class Time from // Time constructor initializes each data member to zero。 // set private field hour setMinute( m )。 h 24 ) ? h : 0。 // validate minute} // end function setMinute// set second valuevoid Time::setSecond( int s ){ second = ( s = 0 amp。} // end function getHour// return minute valueint Time::getMinute(){ return minute。 // increment minute by 1 if ( getMinute() == 0 ) setHour( getHour() + 1 )。} // 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。 using std::endl。 // set time // output Time object t39。 // invokes function printStandard cout endl。 // default constructor void print()。 // set day void setYear( int )。 // get year void nextDay()。 // 1900+ bool leapYear()。 include // include definition of class DateDate::Date( int m, int d, int y ) { setDate( m, d, y )。 // invokes function setYear} // end function setDatevoid Date::setDay( int d ){ if ( month == 2 amp。 d = 1 ) ? d : 1。} // end function setDayvoid Date::setMonth( int m ) { month = m = 12 amp。 // sets year} // end function setYearint Date::getDay() { return day。39。\n39。 // increments year by 1 } // end if statement } // end function nextDaybool Date::leapYear(){ if ( year % 400 == 0 || ( year % 4 == 0 amp。 // 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 }。} // end function monthDays測(cè)試函數(shù):include iostream using std::cout。 // instantiate object d of class Date // output Date object d39。 // invokes function print ()。 // default constructor void setDate( int, int, int )。 // set year void nextDay