《C++大学教程第五版》课后习题答案2_第1页
《C++大学教程第五版》课后习题答案2_第2页
《C++大学教程第五版》课后习题答案2_第3页
《C++大学教程第五版》课后习题答案2_第4页
《C++大学教程第五版》课后习题答案2_第5页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C++大学基础教程课后答案(DEITEL)版

3.11

GradeBook类定义:

#include<string>//programusesC++standardstringclass

usingstd::string;

classGradeBook

(

public:

//constructorinitializescoursenameandinstructorname

GradeBook(string,string);

voidsetCourseName(string);//functiontosetthecoursename

stringgetCourseName();//functiontoretrievethecoursename

voidsetlnstructorName(string);//functiontosetinstructorname

stringgetlnstructorNameO;//functiontoretrieveinstructorname

voiddisplayMessage();//displaywelcomemessageandinstructorname

private:

stringcourseName;//coursenameforthisGradeBook

stringinstructorName;//instructornameforthisGradeBook

};//endclassGradeBook

类成员函数:

^include<iostream>

usingstd::cout;

usingstd::endl;

#includeGradeBook,h”

//constructorinitializescourseNameandinstructorName

//withstringssuppliedasarguments

GradeBook::GradeBook(stringcourse,stringinstructor)

(

setCourseName(course);//initializescourseName

setlnstructorName(instructor);//initializesinstructorName

}//endGradeBookconstructor

//functiontosetthecoursename

voidGradeBook::setCourseName(stringname)

(

courseName=name;//storethecoursename

}//endfunctionsetCourseName

//functiontoretrievethecoursename

stringGradeBook::getCourseName()

(

returncourseName;

}//endfunctiongetCourseName

//functiontosettheinstructorname

voidGradeBook::setlnstructorName(stringname)

(

instructorName=name;//storetheinstructorname

}//endfunctionsetlnstructorName

//functiontoretrievetheinstructorname

stringGradeBook::getInstructorName()

(

returninstructorName;

}//endfunctiongetInstructorName

//displayawelcomemessageandtheinstructor,sname

voidGradeBook::displayMessage()

(

//displayawelcomemessagecontainingthecoursename

cout«”Welcometothegradebookfor\n"«getCourseName()<<〃!"

«endl;

//displaytheinstructor,sname

cout«”Thiscourseispresentedby:"«getlnstructorName()«endl;

}//endfunctiondisplayMessage

测试文件:

^include<iostream>

usingstd::cout;

usingstd::endl;

//includedefinitionofclassGradeBookfromGradeBook,h

^includeGradeBook,h”

//functionmainbeginsprogramexecution

intmainO

(

//createaGradeBookobject;passacoursenameandinstructorname

GradeBookgradeBook(

“CS1O1IntroductiontoC++Programming”,ProfessorSmith");

//displayinitialvalueofinstructorNameofGradeBookobject

cout«”gradeBookinstructornameis:“

«gradeBook.getlnstructorName()«”\n\n";

//modifytheinstructorNameusingsetfunction

gradeBook.setlnstructorName(''AssistantProfessorBates");

//displaynewvalueofinstructorName

cout«”newgradeBookinstructornameis:“

«gradeBook.getlnstructorName()«”\n\n";

//displaywelcomemessageandinstructor,sname

gradeBook.displayMessage();

return0;//indicatesuccessfultermination

}//endmain

3.12

类定义:

classAccount

(

public:

Account(int);//constructorinitializesbalance

voidcredit(int);//addanamounttotheaccountbalance

voiddebit(int);//subtractanamountfromtheaccountbalance

intgetBalance();//returntheaccountbalance

private:

intbalance;//datamemberthatstoresthebalance

};//endclassAccount

类成员函数:

#include<iostream>

usingstd::cout;

usingstd::endl;

#include"Account,h"//includedefinitionofclassAccount

//Accountconstructorinitializesdatamemberbalance

Account::Account(intinitialBalance)

(

balance=0;//assumethatthebalancebeginsat0

//ifinitialBalanceisgreaterthan0,setthisvalueasthe

//balanceoftheAccount;otherwise,balanceremains0

if(initialBalance>0)

balance=initialBalance;

//ifinitialBalanceisnegative,printerrormessage

if(initialBalance<0)

cout«”Error:Initialbalancecannotbenegative.\nz,«endl;

}//endAccountconstructor

//credit(add)anamounttotheaccountbalance

voidAccount::credit(intamount)

(

balance=balance+amount;//addamounttobalance

}//endfunctioncredit

//debit(subtract)anamountfromtheaccountbalance

voidAccount::debit(intamount)

(

if(amount>balance)//debitamountexceedsbalance

cout«”Debitamountexceededaccountbalance.\n"«endl;

if(amount<=balance)//debitamountdoesnotexceedbalance

balance=balance-amount;

}//endfunctiondebit

//returntheaccountbalance

intAccount::getBalance()

returnbalance;//givesthevalueofbalancetothecallingfunction

}//endfunctiongetBalance

测试函数:

^include<iostream>

usingstd::cout;

usingstd::cin;

usingstd::endl;

//includedefinitionofclassAccountfromAccount,h

^includeAccount,h”

//functionmainbeginsprogramexecution

intmainO

(

Accountaccount1(50);//createAccountobject

Accountaccount2(25);//createAccountobject

//displayinitialbalanceofeachobject

cout«”account1balance:$"«account1.getBalance()«endl;

cout«z,account2balance:$"«account2.getBalance()«endl;

intwithdrawalAmount;//storeswithdrawalamountreadfromuser

cout«”\nEnterwithdrawalamountforaccount1://prompt

cin»withdrawalAmount;//obtainuserinput

cout«z,\nattemptingtosubtract"«withdrawalAmount

«“fromaccount1balance\n\n”;

account1.debit(withdrawalAmount);//trytosubtractfromaccount1

//displaybalances

cout«^account1balance:$〃«accountl.getBalance()«endl;

cout«”account?balance:$〃«account2.getBalance()«endl;

cout«”\nEnterwithdrawalamountforaccount2://prompt

cin»withdrawalAmount;//obtainuserinput

cout«zz\nattemptingtosubtract"«withdrawalAmount

«“fromaccount2balance\n\n”;

account2.debit(withdrawalAmount);//trytosubtractfromaccount2

//displaybalances

cout«”accountlbalance:$“«accountl.getBalance()«endl;

cout«”account2balance:$“«account2.getBalance()«endl;

return0;//indicatesuccessfultermination

}//endmain

3.13

类定义:

^include<string>//programusesC++standardstringclass

usingstd::string;

//Invoiceclassdefinition

classInvoice

(

public:

//constructorinitializesthefourdatamembers

Invoice(string,string,int,int);

//setandgetfunctionsforthefourdatamembers

voidsetPartNumber(string);//partnumber

stringgetPartNumber();

voidsetPartDescription(string);//partdescription

stringgetPartDescriptionO;

voidsetQuantity(int);//quantity

intgetQuantity();

voidsetPricePerItem(int);//priceperitem

intgetPricePerltemO;

//calculatesinvoiceamountbymultiplyingquantityxpriceperitem

intgetlnvoiceAmount();

private:

stringpartNumber;//thenumberofthepartbeingsold

stringpartDescription;//descriptionofthepartbeingsold

intquantity;//howmanyoftheitemsarebeingsold

intpricePerltem;//priceperitem

};//endclassInvoice

类成员函数:

Winclude<iostream>

usingstd::cout;

usingstd::endl;

//includedefinitionofclassInvoicefromInvoice,h

#include"Invoice,h”

//Invoiceconstructorinitializestheclass,sfourdatamembers

Invoice::Invoice(stringnumber,stringdescription,intcount,

intprice)

(

setPartNumber(number);//storepartNumber

setPartDescription(description);//storepartDescription

setQuantity(count);//validateandstorequantity

setPricePerItem(price);//validateandstorepricePerltem

}//endInvoiceconstructor

//setpartnumber

voidInvoice::setPartNumber(stringnumber)

(

partNumber=number;//novalidationneeded

}//endfunctionsetPartNumber

//getpartnumber

stringInvoice::getPartNumber()

(

returnpartNumber;

}//endfunctiongetPartNumber

//setpartdescription

voidInvoice::setPartDescription(stringdescription)

(

partDescription=description;//novalidationneeded

}//endfunctionsetPartDescription

//getpartdescription

stringInvoice::getPartDescription()

{

returnpartDescription;

}//endfunctiongetPartDescription

//setquantity;ifnotpositive,setto0

voidInvoice::setQuantity(intcount)

(

if(count>0)//ifquantityispositive

quantity=count;//setquantitytocount

if(count<=0)//ifquantityisnotpositive

(

quantity=0;//setquantityto0

cout«”\nquantitycannotbenegative,quantitysetto0.\n”;

}//endif

}//endfunctionsetQuantity

//getquantity

intInvoice::getQuantity()

{

returnquantity;

}//endfunctiongetQuantity

//setpriceperitem;ifnotpositive,setto0

voidInvoice::setPricePerItem(intprice)

(

if(price>0)//ifpriceispositive

pricePerltem=price;//setpricePerltemtoprice

if(price<=0)//ifpriceisnotpositive

(

pricePerltem=0;//setpricePerltemto0

cout«/z\npricePerItemcannotbenegative.”

«^pricePerltemsetto0.\n”;

}//endif

}//endfunctionsetPricePerltem

//getpriceperitem

intInvoice::getPricePerItem()

(

returnpricePerltem;

}//endfunctiongetPricePerltem

//calulatesinvoiceamountbymultiplyingquantityxpriceperitem

intInvoice::getInvoiceAmount()

(

returngetQuantity()*getPricePerltem();

}//endfunctiongetlnvoiceAmount

测试函数:

#include<iostream>

usingstd::cout;

usingstd::cin;

usingstd::endl;

//includedefinitionofclassInvoicefromInvoice,h

^include"Invoice,h”

//functionmainbeginsprogramexecution

intmain()

(

//createanInvoiceobject

Invoiceinvoice(“12345","Hammer”,100,5);

//displaytheinvoicedatamembersandcalculatetheamount

cout«”Partnumber:“«invoice.getPartNumber()«endl;

cout«”Partdescription:“«invoice.getPartDescription()«endl;

cout«”Quantity:“«invoice.getQuantity()«endl;

cout«”Priceperitem:$“«invoice.getPricePerltem()«endl;

cout«”Invoiceamount:$〃«invoice.getlnvoiceAmount()«endl;

//modifytheinvoicedatamembers

invoice.setPartNumber("123456");

invoice.setPartDescription("Saw");

invoice.setQuantity(-5);//negativequantity,soquantitysetto0

invoice.setPricePerltem(10);

cout«”\nlnvoicedatamembersmodified.\n\nz,;

//displaythemodifiedinvoicedatamembersandcalculatenewamount

cout«”Partnumber:"«invoice.getPartNumber()«endl;

cout«”Partdescription:“«invoice.getPartDescription()«endl;

cout«”Quantity:"«invoice.getQuantity()«endl;

cout«”Priceperitem:$“«invoice.getPricePerltem()«endl;

cout«”Invoiceamount:$“«invoice.getlnvoiceAmount()«endl;

return0;//indicatesuccessfultermination

}//endmain

3.14

类定义:

^include<string>//programusesC++standardstringclass

usingstd::string;

//Employeeclassdefinition

classEmployee

(

public:

Employee(string,string,int);//constructorsetsdatamembers

voidsetFirstName(string);//setfirstname

stringgetFirstNameO;//returnfirstname

voidsetLastName(string);//setlastname

stringgetLastName();//returnlastname

voidsetMonthlySalary(int);//setweeklysalary

intgetMonthlySalary();//returnweeklysalary

private:

stringfirstName;//Employee1sfirstname

stringlastName;//Employee,slastname

intmonthlySalary;//Employee,ssalarypermonth

};//endclassEmployee

类成员函数:

#include<iostream>

usingstd::cout;

^include“Employee,h"//Employeeclassdefinition

//Employeeconstructorinitializesthethreedatamembers

Employee::Employee(stringfirst,stringlast,intsalary)

(

setFirstName(first);//storefirstname

setLastName(last);//storelastname

setMonthlySalary(salary);//validateandstoremonthlysalary

}//endEmployeeconstructor

//setfirstname

voidEmployee::setFirstName(stringname)

(

firstName=name;//novalidationneeded

}//endfunctionsetFirstName

//returnfirstname

stringEmployee::getFirstNameO

(

returnfirstName;

}//endfunctiongetFirstName

//setlastname

voidEmployee::setLastName(stringname)

lastName=name;//novalidationneeded

}//endfunctionsetLastName

//returnlastname

stringEmployee::getLastName()

(

returnlastName;

}//endfunctiongetLastName

//setmonthlysalary;ifnotpositive,setto0.0

voidEmployee::setMonthlySalary(intsalary)

(

if(salary>0)//ifsalaryispositive

monthlySalary=salary;//setmonthlySalarytosalary

if(salary<=0)//ifsalaryisnotpositive

monthlySalary=0;//setmonthlySalaryto0.0

}//endfunctionsetMonthlySalary

//returnmonthlysalary

intEmployee::getMonthlySalary()

(

returnmonthlySalary;

}//endfunctiongetMonthlySalary

测试函数:

#include<iostream>

usingstd::cout;

usingstd::endl;

#include“Employee,h"//includedefinitionofclassEmployee

//functionmainbeginsprogramexecution

intmain()

(

//createtwoEmployeeobjects

Employeeemployeel("Lisa","Roberts”,4500);

Employeeemployee2("Mark","Stein”,4000);

//displayeachEmployee,syearlysalary

cout«”Employees'yearlysalaries:"«endl;

//retrieveanddisplayemployeeTsmonthlysalarymultipliedby12

intmonthlySalaryl=employeel.getMonthlySalary();

cout«employeel.getFirstName()«〃〃«employeel.getLastName()

«“:$"«monthlySalaryl*12«endl;

//retrieveanddisplayemployee2,smonthlysalarymultipliedby12

intmonthlySalary2=employee2.getMonthlySalary();

cout«employee2.getFirstName()«”“«employee2.getLastName()

«“:$"«monthlySalary2*12«endl;

//giveeachEmployeea10%raise

employeel.setMonthlySalary(monthlySalaryl*1.1);

employee2.setMonthlySalary(monthlySalary2*1.1);

//displayeachEmployee,syearlysalaryagain

cout«^\nEmployees,yearlysalariesafter10%raise:"«endl;

//retrieveanddisplayemployeeTsmonthlysalarymultipliedby12

monthlySalaryl二employeel.getMonthlySalary();

cout«employeel.getFirstName()«"“«employeel.getLastName()

«“:$"«monthlySalaryl*12«endl;

monthlySalary2=employee2.getMonthlySalary();

cout«employee2.getFirstName()«"〃«employee2.getLastName()

«“:$"«monthlySalary2*12«endl;

return0;//indicatesuccessfultermination

}//endmain

3.15

类定义:

classDate

(

public:

Date(int,int,int);//constructorinitializesdatamembers

voidsetMonth(int);//setmonth

intgetMonth();//returnmonth

voidsetDay(int);//setday

intgetDay();//returnday

voidsetYear(int);//setyear

intgetYear();//returnyear

voiddisplayDateO;//displaysdateinmm/dd/yyyyformat

private:

intmonth;//themonthofthedate

intday;//thedayofthedate

intyear;//theyearofthedate

);//endclassDate

类成员函数:

#include<iostream>

usingstd::cout;

usingstd::endl;

^include"Date・h"//includedefinitionofclassDatefromDate,h

//Dateconstructorthatinitializesthethreedatamembers;

//assumevaluesprovidedarecorrect(reallyshouldvalidate)

Date::Date(intm,intd,inty)

(

setMonth(m);

setDay(d);

setYear(y);

}//endDateconstructor

//setmonth

voidDate::setMonth(intm)

(

month=m;

if(month<1)

month=1;

if(month>12)

month=1;

}//endfunctionsetMonth

//returnmonth

intDate::getMonth()

(

returnmonth;

}//endfunctiongetMonth

//setday

voidDate::setDay(intd)

(

day=d;

}//endfunctionsetDay

//returnday

intDate::getDay()

(

returnday;

}//endfunctiongetDay

//setyear

voidDate::setYear(inty)

(

year=y;

}//endfunctionsetYear

//returnyear

intDate::getYear()

(

returnyear;

}//endfunctiongetYear

//printDateintheformatmm/dd/yyyy

voidDate::displayDate()

(

cout«month«'/'«day«'/'«year«endl;

}//endfunctiondisplayDate

测试函数:

^include<iostream>

usingstd::cout;

usingstd::endl;

^include"Date・h"//includedefinitionofclassDatefromDate,h

//functionmainbeginsprogramexecution

intmainO

Datedate(5,6,1981);//createaDateobjectforMay6,1981

//displaythevaluesofthethreeDatedatamembers

cout«”Month:"«date.getMonth()<<endl;

cout«"Day:"«date.getDay()«endl;

cout«"Year:"«date.getYear()«endl;

cout«^XnOriginaldate:"«endl;

date.displayDateO;//outputtheDateas5/6/1981

//modifytheDate

date.setMonth(13);//invalidmonth

date.setDay(1);

date.setYear(2005);

cout«”\nNewdate:"«endl;

date.displayDateO;//outputthemodifieddate(1/1/2005)

return0;//indicatesuccessfultermination

}//endmain

9.05

类定义:

ttifndefC0MPLEX_H

ttdefineC0MPLEX_H

classComplex

(

public:

Complex(double=0.0,double=0.0);//defaultconstructor

Complexadd(constComplex&);//functionadd

Complexsubtract(constComplex&);//functionsubtract

voidprintComplex();//printcomplexnumberformat

voidsetComplexNumber(double,double);//setcomplexnumber

private:

doublerealPart;

doubleimaginaryPart;

};//endclassComplex

ftendif

类成员函数:

#include<iostream>

usingstd::cout;

#include"Complex,h”

Complex::Complex(doublereal,doubleimaginary)

(

setComplexNumber(real,imaginary);

}//endComplexconstructor

ComplexComplex::add(constComplexferight)

returnComplex(

realPart+right.realPart,imaginaryPart+right.imaginaryPart);

}//endfunctionadd

ComplexComplex::subtract(constComplex&right)

(

returnComplex(

realPart-right.realPart,imaginaryPart-right.imaginaryPart);

}//endfunctionsubtract

voidComplex::printComplex()

(

cout«'('«realPart«”,"«imaginaryPart«;

}//endfunctionprintComplex

voidComplex::setComplexNumber(doublerp,doubleip)

(

realPart=rp;

imaginaryPart=ip;

}//endfunctionsetComplexNumber

测试函数:

^include<iostream>

usingstd::cout;

usingstd::endl;

#include"Complex,h”

intmain()

(

Complexa(1,7),b(9,2),c;//createthreeComplexobjects

a.printComplex();//outputobjecta

cout«"+";

b.printComplex();//outputobjectb

cout«=;

c=a.add(b);//invokeaddfunctionandassigntoobjectc

c.printComplex();//outputobjectc

cout«'\n,;

a.setComplexNumber(10,1);//resetrealPartand

b.setComplexNumber(11,5);//andimaginaryPart

a.printComplex();//outputobjecta

cout

b.printComplex();//outputobjectb

cout

c=a.subtract(b);//invokeaddfunctionandassigntoobjectc

c.printComplex();//outputobjectc

cout«endl;

return0;

}//endmain

9.06

类定义:

ttifndefRATIONAL」!

ttdefineRATIONALE

classRational

(

public:

Rational(int=0,int=1);//defaultconstructor

Rationaladdition(constRational&);〃functionaddition

Rationalsubtraction(constRational&);//functionsubtraction

Rationalmultiplication(constRational&);//functionmulti.

Rationaldivision(constRational&);//functiondivision

voidprintRational();//printrationalformat

voidprintRationalAsDoubleO;//printrationalasdoubleformat

private:

intnumerator;//integernumerator

intdenominator;//integerdenominator

voidreduction();//utilityfunction

};//endclassRational

Wendif

类成员函数:

#include<iostream>

usingstd::cout;

^include“Rational,h"//includedefinitionofclassRational

Rational::Rational(intn,intd)

(

numerator=n;//setsnumerator

denominator=d;//setsdenominator

reduction();//storethefractioninreducedform

}//endRationalconstructor

RationalRational::addition(constRational&a)

{

Rationalt;//createsRationalobject

t.numerator=a.numerator*denominator;

t.numerator+=a.denominator*numerator;

t.denominator=a.denominator*denominator;

t.reduction();//storethefractioninreducedform

returnt;

}//endfunctionaddition

RationalRational::subtraction(constRational&s)

(

Rationalt;//createsRationalobject

t.numerator=s.denominator*numerator;

t.numerator一二denominator*s.numerator;

t.denominator=s.denominator*denominator;

t.reduction();//storethefractioninreducedform

returnt;

}//endfunctionsubtraction

RationalRational::multiplication(constRational&m)

(

Rationalt;//createsRationalobject

t.numerator=m.numerator*numerator;

t.denominator=m.denominator*denominator;

t.reduction();//storethefractioninreducedform

returnt;

}//endfunctionmultiplication

RationalRational::division(constRational&v)

(

Rationalt;//createsRationalobject

t.numerator=v.denominator*numerator;

t.denominator=denominator*v.numerator;

t.reduction();//storethefractioninreducedform

returnt;

}//endfunctiondivision

voidRational::printRational()

(

if(denominator==0)//validatesdenominator

cout«”"DIVIDEBYZEROERROR!!!"«"\n;

elseif(numerator==0)//validatesnumerator

cout«0;

else

cout«numerator«'/'«denominator;

}//endfunctionprintRational

voidRational::printRationalAsDouble()

(

cout«static_cast<double>(numerator)/denominator;

}//endfunctionprintRationalAsDouble

voidRational::reduction()

(

intlargest;

largest=numerator>denominator?numerator:denominator;

intgcd=0;//greatestcommondivisor

for(intloop=2;loop<=largest;loop++)

if(numerator%loop==0&&denominator%loop==0)

gcd=loop;

if(gcd!=0)

numerator/=gcd;

denominator/=gcd;

}//endif

}//endfunctionreduction

测试函数:

#include<iostream>

usingstd::cout;

usingstd::endl;

^include"Rational,h"//includedefinitionofclassRational

intmainO

Rationalc(2,6),d(7,8),x;//createsthreerationalobjects

c.printRational();//printsrationalobjectc

cout<<"+";

d.printRational();//printsrationalobjectd

x=c.addition(d);//addsobjectcandd;setsthevaluetox

cout«"=

x.printRational();//printsrationalobjectx

cout«'\n;

x.printRational();//printsrationalobjectx

cout«

x.printRationalAsDoubleO;//printsrationalobjectxasdouble

cout«"\n\n";

c.printRational();//printsrationalobjectc

cout<<"一";

d.printRational();//printsrationalobjectd

x=c.subtraction(d);//subtractsobjectcandd

cout

x.printRational();//printsrationalobjectx

cout«'\n;

x.printRational();//printsrationalobjectx

cout<<"=";

x.printRationalAsDoubleO;//printsrationalobjectxasdouble

cout«"\n\n";

c.printRational();//printsrationalobjectc

cout<<"x

d.printRational();//printsrationalobjectd

x=c.multiplication(d);//multipliesobjectcandd

cout<<“二";

x.printRational();//printsrationalobjectx

cout«'\n,;

x.printRational();//printsrationalobjectx

cout<<"=";

x.printRationalAsDoubleO;//printsrationalobjectxasdouble

cout«"\n\n";

c.printRational();//printsrationalobjectc

cout<<"/";

d.printRational();//printsrationalobjectd

x=c.division(d);//dividesobjectcandd

cout

x.printRational();//printsrationalobjectx

cout«'\n,;

x.printRational();//printsrationalobjectx

cout

x.printRationalAsDoubleO;//printsrationalobjectxasdouble

cout«endl;

return0;

}//endmain

9.07

类定义:

ttifndefTIME_H

ttdefineTIME_H

classTime

(

public:

public:

Time(int=0,int=0,int=0);//defaultconstructor

//setfunctions

voidsetTime(int,int,int);//sethour,minute,second

voidsetHour(int);//sethour(aftervalidation)

voidsetMinute(int);//setminute(aftervalidation)

voidsetSecond(int);//setsecond(aftervalidation)

//getfunctions

intgetHour();//returnhour

intgetMinuteO;//returnminute

intgetSecondO;//returnsecond

voidtick();//incrementonesecond

voidprintUniversal();//outputtimeinuniversal-timeformat

voidprintstandard();//outputtimeinstandard-timeformat

private:

inthour;//0-23(24-hourclockformat)

intminute;//0-59

intsecond;//0-59

};//endclassTime

ttendif

类成员函数:

tfinclude<iostream>

usingstd::cout;

^include<iomanip>

usingstd::setfill;

usingstd::setw;

^include”Time・h"//includedefinitionofclassTimefromTime,h

//Timeconstructorinitializeseachdatamembertozero;

//ensuresthatTimeobjectsstartinaconsistentstate

Time::Time(inthr,intmin,intsec)

(

setTime(hr,min,sec);//validateandsettime

}//endTimeconstructor

//setnewTimevalueusinguniversaltime;ensurethat

//thedataremainscons

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论