【正文】
+ , imaginaryPart + )。 include Complex::Complex( double real, double imaginary ){ setComplexNumber( real, imaginary )。}。 // set plex number private: double realPart。 // function subtract void printComplex()。 // function add Complex subtract( const Complex amp。 // default constructor Complex add( const Complex amp。 // output the modified date (1/1/2005) return 0。 cout \nNew date: endl。 // invalid month ( 1 )。 ()。 cout Year: () endl。 // create a Date object for May 6, 1981 // display the values of the three Date data members cout Month: () endl。using std::endl。 year endl。 day 39。} // end function getYear// print Date in the format mm/dd/yyyyvoid Date::displayDate() { cout month 39。} // end function getDay// set yearvoid Date::setYear( int y ){ year = y。} // end function getMonth// set dayvoid Date::setDay( int d ){ day = d。 if ( month 12 ) month = 1。} // end Date constructor // set monthvoid Date::setMonth( int m ){ month = m。 setDay( d )。include // include definition of class Date from // Date constructor that initializes the three data members。 // end class Date類成員函數(shù):include iostreamusing std::cout。 // the day of the date int year。 // displays date in mm/dd/yyyy formatprivate: int month。 // set year int getYear()。 // set day int getDay()。 // set month int getMonth()。 // indicate successful termination} // end main類定義:class Date {public: Date( int, int, int )。 cout () () : $ monthlySalary2 * 12 endl。 cout () () : $ monthlySalary1 * 12 endl。 // retrieve and display employee139。s yearly salary again cout \nEmployees39。 ( monthlySalary2 * )。 cout () () : $ monthlySalary2 * 12 endl。 // retrieve and display employee239。s monthly salary multiplied by 12 int monthlySalary1 = ()。 yearly salaries: endl。 // display each Employee39。include // include definition of class Employee// function main begins program executionint main(){ // create two Employee objects Employee employee1( Lisa, Roberts, 4500 )。} // end function getMonthlySalary測(cè)試函數(shù):include iostreamusing std::cout。 // set monthlySalary to salary if ( salary = 0 ) // if salary is not positive monthlySalary = 0。} // end function getLastName// set monthly salary。} // end function getFirstName// set last namevoid Employee::setLastName( string name ){ lastName = name。 // validate and store monthly salary} // end Employee constructor// set first namevoid Employee::setFirstName( string name ){ firstName = name。 // store first name setLastName( last )。 // end class Employee類成員函數(shù):include iostreamusing std::cout。 // Employee39。 // Employee39。 // Employee39。 // set weekly salary int getMonthlySalary()。 // set last name string getLastName()。 // set first name string getFirstName()。// Employee class definitionclass Employee {public: Employee( string, string, int )。 return 0。 cout Price per item: $ () endl。 cout Part description: () endl。 cout \nInvoice data members modified.\n\n。 ( 5 )。 // modify the invoice data members ( 123456 )。 cout Price per item: $ () endl。 cout Part description: () endl。// include definition of class Invoice from include // function main begins program executionint main(){ // create an Invoice object Invoice invoice( 12345, Hammer, 100, 5 )。using std::cin。} // end function getPricePerItem// calulates invoice amount by multiplying quantity x price per itemint Invoice::getInvoiceAmount(){ return getQuantity() * getPricePerItem()。 // set pricePerItem to 0 cout \npricePerItem cannot be negative. pricePerItem set to 0.\n。 if not positive, set to 0void Invoice::setPricePerItem( int price ){ if ( price 0 ) // if price is positive pricePerItem = price。 } // end if} // end function setQuantity// get quantityint Invoice::getQuantity(){ return quantity。 // set quantity to count if ( count = 0 ) // if quantity is not positive { quantity = 0。} // end function getPartDescription// set quantity。} // end function getPartNumber// set part descriptionvoid Invoice::setPartDescription( string description ){ partDescription = description。 // validate and store pricePerItem} // end Invoice constructor// set part numbervoid Invoice::setPartNumber( string number ){ partNumber = number。 // store partDescription setQuantity( count )。s four data membersInvoice::Invoice( string number, string description, int count, int price ){ setPartNumber( number )。using std::endl。 // price per item}。 // description of the part being sold int quantity。 private: string partNumber。 // price per item int getPricePerItem()。 // quantity int getQuantity()。 // part description string getPartDescription()。 // part number string getPartNumber()。// Invoice class definitionclass Invoice{public: // constructor initializes the four data members Invoice( string, string, int, int )。 return 0。 // try to subtract from account2 // display balances cout account1 balance: $ () endl。 // obtain user input cout \nattempting to subtract withdrawalAmount from account2 balance\n\n。 cout \nEnter withdrawal amount for account2: 。 // try to subtract from account1 // display balances cout account1 balance: $ () endl。 // obtain user input cout \nattempting to subtract withdrawalAmount from account1 balance\n\n。 // stores withdrawal amount read from user cout \nEnter withdrawal amount for account1: 。 c