【正文】
39。// Employee class definitionclass Employee {public: Employee( string, string, int )。 cout \nInvoice data members modified.\n\n。 cout Part description: () endl。 // set pricePerItem to 0 cout \npricePerItem cannot be negative. pricePerItem set to 0.\n。} // end function getPartDescription// set quantity。s four data membersInvoice::Invoice( string number, string description, int count, int price ){ setPartNumber( number )。 private: string partNumber。 // part number string getPartNumber()。 // obtain user input cout \nattempting to subtract withdrawalAmount from account2 balance\n\n。 // stores withdrawal amount read from user cout \nEnter withdrawal amount for account1: 。 // gives the value of balance to the calling function} // end function getBalance測(cè)試函數(shù):include iostreamusing std::cout。include // include definition of class Account// Account constructor initializes data member balanceAccount::Account( int initialBalance ){ balance = 0。 // indicate successful termination} // end main類定義:class Account{public: Account( int )。// include definition of class GradeBook from include // function main begins program executionint main(){ // create a GradeBook object。} // end function getCourseName// function to set the instructor namevoid GradeBook::setInstructorName( string name ){ instructorName = name。 // course name for this GradeBook string instructorName。C++ 大學(xué)基礎(chǔ)教程 課后答案(DEITEL)版GradeBook類定義:include string // program uses C++ standard string classusing std::string。 // display wele message and instructor nameprivate: string courseName。 // store the course name} // end function setCourseName// function to retrieve the course namestring GradeBook::getCourseName(){ return courseName。 using std::endl。 return 0。using std::endl。} // end function debit// return the account balanceint Account::getBalance(){ return balance。 int withdrawalAmount。 // prompt cin withdrawalAmount。 // set and get functions for the four data members void setPartNumber( string )。 // calculates invoice amount by multiplying quantity x price per item int getInvoiceAmount()。// include definition of class Invoice from include // Invoice constructor initializes the class39。 // no validation needed} // end function setPartDescription// get part descriptionstring Invoice::getPartDescription(){ return partDescription。 // set pricePerItem to price if ( price = 0 ) // if price is not positive { pricePerItem = 0。 // display the invoice data members and calculate the amount cout Part number: () endl。 //negative quantity,so quantity set to 0 ( 10 )。 // indicate successful termination} // end main類定義:include string // program uses C++ standard string classusing std::string。 // return weekly salaryprivate: string firstName。include // Employee class definition// Employee constructor initializes the three data membersEmployee::Employee( string first, string last, int salary ){ setFirstName( first )。 if not positive, set to void Employee::setMonthlySalary( int salary ){ if ( salary 0 ) // if salary is positive monthlySalary = salary。s yearly salary cout Employees39。 // give each Employee a 10% raise ( monthlySalary1 * )。 monthlySalary2 = ()。 // return day void setYear( int )。using std::endl。} // end function setMonth// return monthint Date::getMonth(){ return month。/39。 cout \nOriginal date: endl。 // indicate successful termination} // end main類定義:ifndef COMPLEX_Hdefine COMPLEX_Hclass Complex {public: Complex( double = , double = )。 double imaginaryPart。} // end function subtractvoid Complex::printComplex(){ cout 39。 include int main(){ Complex a( 1, 7 ), b( 9, 2 ), c。\n39。 // invoke add function and assign to object c ()。 // function subtraction Rational multiplication( const Rational amp。 // integer denominator void reduction()。 // creates Rational object = * denominator。 = denominator * 。 ()。} // end function divisionvoid Rational::printRational (){ if ( denominator == 0 ) // validates denominator cout \nDIVIDE BY ZERO ERROR!!! 39。 largest = numerator denominator ? numerator : denominator。 denominator /= gcd。 // adds object c and d。 // prints rational object x as double cout \n\n。\n39。 // prints rational object d x = ( d )。 // prints rational object x as double cout \n\n。\n39。 // set hour, minute, second void setHour( int )。 // output time in universaltime format void printStandard()。include // include definition of class Time from // Time constructor initializes each data member to zero。 h 24 ) ? h : 0。} // end function getHour// return minute valueint Time::getMinute(){ return minute。} // 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。 // set time // output Time object t39。 // default constructor void print()。 // get year void nextDay()。 include // include definition of class DateDate::Date( int m, int d, int y ) { setDate( m, d, y )。 d = 1 ) ? d : 1。 // sets year} // end function setYearint Date::getDay() { return day。\n39。 // 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 }。 // instantiate object d of class Date // output Date object d39。 // default constructor void setDate( int, int, int