面向对象的C++程序设计第六版课后习题答案第三章_第1页
面向对象的C++程序设计第六版课后习题答案第三章_第2页
面向对象的C++程序设计第六版课后习题答案第三章_第3页
面向对象的C++程序设计第六版课后习题答案第三章_第4页
面向对象的C++程序设计第六版课后习题答案第三章_第5页
已阅读5页,还剩70页未读 继续免费阅读

下载本文档

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

文档简介

Chapter3

MOREFLOWOFCONTROL

1.SolutionsforandRemarksonSelectedProgrammingProblems

Inordertopreserveflexibilityofthetext,theauthorhasnotdealtwithclassesinthischapteratall.Tohelp

thosewhoreallywanttodothingswithclasses,someoftheProgrammingProjectswillbecarriedoutusing

oneorseveralclasses.

1.RockScissorsPaper

Hereeachoftwoplayerstypesinoneofstrings"Rock","Scissors",or"Paper”.Afterthesecondplayerhas

typedinthestring,thewinnerofthisgameisdeterminedandannounced.

Rules:

RockbreaksScissors

ScissorscutsPaper

PapercoversRock

Ifbothplayersgivethesameanswer,thenthereisnowinner.

Anicetouchwouldbetokeepandreporttotalwinsforeachplayerasplayproceeds.

Tofindtheclasses,wenotefirstthatthereare2identicalplayers.Theseplayersrecordthecharacterentered,

andkeeptrackofthewins.Thereisaconstructorthatsetsthetotalwinsto0.Thereisaplay()member

functionthatpromptsforandgetsfromthekeyboardreturnsoneofthecharactersR,P,orS'forrock,

paperandscissors.Thereisanaccessormemberfunctionforchandanincrementormemberfunctionfor

accumulatedwinssothatastandalonefunctionintwin(ch,ch);candeterminewhowinsandincrementthe

accumulatedwinsvariable.

(Abettersolutionwouldmakethewinsfunctionafriendofclassplayersothatwinscanhaveaccess

totheeachplayer'sprivatedatatodeterminewhowinsandupdatetheaccumulatedwinswithouttheaccessor

functionch()andincrementwins()function.)

NotethatIhaveleftabitofdebuggingcodeintheprogram.

classplayer

(

publicfunctionmembers

constructors()

Copyright©2007PearsonEducation,Inc.PublishingasPearsonAddison-Wesley

play();//promptsforandgetsthisplayer'smove

charch();//accessor

intaccumulatedWins();//accessor

incrWins();//incrementswincount

privatedata

charactertypedin

accumulatedWins

);

intwins(playeruserl,playeruser2);

//playerl*scharacteriscomparedtoplayer2'scharacterusingaccessor

//functions.

//winsreturns

//0iftherenowinner

//1ifplayer1wins,

//2ifplayer2wins,

//callstheappropriateincrWins()toupdatethewins

Notethatoncetheclassisdefinedandtheauxiliaryfunctionwritten,thecode“almostwritesitself.”

//file:ch3Prbl.cc

//RockPaperScissorsgame

//class/objectsolution

#include<iostream>

#include<cctype>//forinttoupper(int);

usingnamespacestd;

classPlayer

(

public:

Player();

voidplay();//promptsforandgetsthisplayer'smove

charCh();//accessor

intAccumulatedWins();//accessor

voidIncrWins();//incrementswincount

private:

charch;//charactertypedin

inttotalwins;//totalofwins

);

Player::Player():totalWins(0)//intializersetsPlayer::totalWinsto0

(

//Thebodyisdeliberatelyempty.ThisisthepreferredC++idiom.

//Thisfunctioncouldbewrittenomittingtheinitializer,and

//puttingthislineinthebody:

//totalwins=0;

)

voidPlayer::play()

(

cout<<"PleaseentereitherR)ockzP)aperzorS)cissors."

<<endl;

cin>>ch;

ch=toupper(ch);//nocastneeded,chisdeclaredtobechar

)

charPlayer::Ch()

(

returnch;

)

intPlayer::AccumulatedWins()

(

returntotalwins;

)

voidPlayer::IncrWins()

(

totalWins++;

)

intwins(Playersuserl,Player&user2);

//playerl'scharacteriscomparedtoplayer2'scharacter

//usingaccessorfunctions.

//Thefunctionwinsreturns

//0iftherenowinner

//1ifplayer1wins,

//2ifplayer2wins,

//callstheappropriateIncrWins()toupdatethewins

intwins(Player&userl,Player&user2)//thismustchangeuserl

//anduser2

if((1R,==userl.Ch()&&•s'==user2.Ch())||

('P'==userl.Ch()&&'R'==user2.Ch())||

('S'==userl.Ch()&&'P1==user2.Ch()))

(

//user1wins

userl.IncrWins();

return1;

)

elseif(('R1==user2.Ch()&&'S'==userl.Ch())

||('P'==user2.Ch()&&'R*==userl.Ch())

||('S'==user2.Ch()&&'P1==userl.Ch()))

(

//user2wins

user2.IncrWins();

return2;

)

else

//nowinner

return0;

)

intmain()

(

Playerplayerl;

Playerplayer2;

charans='Y';

while(*Y'==ans)

(

playerl.play();

player2.play();

switch(wins(playerl,player2))

(

case0:

cout<<"Nowinner."<<endl

<<•'Totalstothismove:•'<<endl

<<"Player1:"<<playerl.AccumulatedWins()

<<endl

<<"Player2:n<<player2.AccumulatedWins()

<<endl

<<"Playagain?Y/ycontinuesotherquits";

cin>>ans;

cout<<"Thanks"<<endl;

break;

case1:

cout<<"Player1wins."<<endl

<<"Totalstothismove:"<<endl

<<"Player1:"<<playerl.AccumulatedWins()

<<endl

<<"Player2:"<<player2.AccumulatedWins()

<<endl

<<"PlayAgain?Y/ycontinues,otherquits.

cin>>ans;

cout<<"Thanks"<<endl;

break;

case2:

cout<<"Player2wins."<<endl

<<•'Totalstothismove:"<<endl

"Player1:<<playerl.AccumulatedWins()

<<endl

"Player2:<<player2.AccumulatedWins()

<<endl

<<"PlayAgain?Y/ycontinues,otherquits.n;

cin>>ans;

cout<<"Thanksn<<endl;

break;

)

ans=toupper(ans);

)

return0;

)

Atypicalrunfortheclass/objectsolutionfollows:

PleaseentereitherR)ock,P)aper,orS)cissors.

R

PleaseentereitherR)ock,P)aperzorS)cissors.

S

insideIncrWins()

1

Player1wins.

Totalstothismove:

Player1:1

Player2:0

PlayAgain?Y/ycontinueszotherquits.y

Thanks

PleaseentereitherR)ock,P)aper,orS)cissors.

S

PleaseentereitherR)ockzP)aperzorS)cissors.

P

insideIncrWins()

2

Player1wins.

Totalstothismove:

Player1:2

Player2:0

PlayAgain?Y/ycontinueszotherquits.y

Thanks

PleaseentereitherR)ock,P)aperzorS)cissors.

P

PleaseentereitherR)ockzP)aperzorS)cissors.

S

insideIncrWins()

1

Player2wins.

Totalstothismove:

Player1:2

Player2:1

PlayAgain?Y/ycontinueszotherquits.y

Thanks

PleaseentereitherR)ockzP)aperzorS)cissors.

P

PleaseentereitherR)ockzP)aperzorS)cissors.

P

Nowinner.

Totalstothismove:

Player1:2

Player2:1

Playagain?Y/ycontinuesotherquitsq

Thanks

1.RockScissorsPaper-Conventionalsolution:

HereeachoftwoplayerstypesinoneofstringsuRockn,"Scissors",orHPaper".Afterthesecondplayerhas

typedinthestring,thewinnerofthisgameisdeterminedandannounced.

Rules:

RockbreaksScissors

ScissorscutsPaper

PapercoversRock

Ifbothplayersgivethesameanswer,thenthereisnowinner.

Anicetouchwouldbetokeepandreporttotalwinsforeachplayerasplayproceeds.

Thisisaconventionalsolutiontotheproblem.

//filech3nlcon.cc

//conventionalsolutiontotheRockScissorsPapergame

#include<iostream>//streamio

#include<cctype>//forinttoupper(int)

usingnamespacestd;

intwins(charchi,charch2)

if(('R'==chi&&'S'==ch2

(1P'==chi&&'R'==ch2)11

(S==chi&&'P'==ch2

return1;//player1wins

elseif(('R'==ch2&&S==chi)11

('P'==ch2&&'R'==chi)11

(S==ch2&&'P«==chi))

return2;//player2wins

else

return0;//nowinner

)

charplay()

(

charch;

cout<<"PleaseentereitherR)ock,P)aperzorS)cissors."<<endl;

cin>>ch;

returntoupper(ch);//nocastneeded,charisreturntype

)

intmain()

(

intwins_l=0;

intwins_2=0;

charchi;

charch2;

charans='Y';

while('Y1==ans)

(

chi=play();

ch2=play();

switch(wins(chi,ch2))

(

case0:

cout<<"Nowinner."<<endl

<<•'Totalstothismove:"<<endl

<<"Player1:H<<wins_l<<endl

<<*'Player2:"<<wins_2<<endl

<<"Playagain?Y/ycontinuesotherquits"

cin>>ans;

cout<<"Thanks”<<endl;

break;

case1:

wins_l++;

cout<<"Player1wins."<<endl

<<"Totalstothismove:•'<<endl

<<"Player1:u<<wins_l<<endl

<<"Player2:n«wins_2<<endl

<<"PlayAgain?Y/ycontinues,otherquits.

cin>>ans;

cout<<"Thanks"<<endl;

break;

case2:

wins_2++;

cout<<"Player2wins."<<endl

<<"Totalstothismove:"<<endl

<<"Player1:*'<<wins_l<<endl

<<"Player2:"<<wins_2<<endl

<<"PlayAgain?Y/ycontinues,otherquits."

cin>>ans;

cout<<"Thanks"<<endl;

break;

)

ans=toupper(ans);

)

return0;

)

Atypicalrunfollowsfortheconventionalsolutionisessentiallythesameasforthe'class'basedsolution.

2.CreditAccountproblem.-class/objectsolution

Computeinterestdue,totalamountdue,andminimumpaymentforarevolvingcreditaccount.

Inputs:accountbalance

Process:Computesinterest

interestaccordingto:

1.5%on1st$1000

1.0%onallover$1000

addsthistoaccountbalancegettotaldue.

Computesminimumpaymentaccordingto:

ifamountdue<$10,

minimumpaymentistotaldue

else

minimumpaymentis10%oftotaldue

outputs:Interestdue,totalamountdue,minimumpayment

Theclassistheaccount.

thepublicinterfacehasfunctions:

constructors

defaultconstructor

constructorwithparameterbalance,

computesinterest,totalduezminimumpay

interestDue()reportsinterest

totalDue()reportstotalamountdue

minPayDue()reportsminimumpaymentdue

privatedata

balance

totaldue

interestdue

minimumpayment

Class-objectImplementation:

//file:ch3prb2.cc

//Interest

//class-objectsolution

//Purpose:Computeinterestdueztotalamountduezandminimumpayment

//forarevolvingcreditaccount.

//

//Inputs:accountbalance

//

//Process:Computesinterest

//interestaccordingto:

//1.5%on1st$1000ofbalance

//1.0%onallover$1000ofbalance

//addsthistoaccountbalancegettotaldue.

//Computesminimumpaymentaccordingto:

//ifamountdue<$10,

//minimumpaymentistotaldue

//else

//minimumpaymentis10%oftotaldue

//

//outputs:Interestdue,totalamountdue,minimumpayment

#include<iostream>

usingnamespacestd;

constdoubleINTEREST_RATE1=0.015;

constdoubleINTEREST_RATE2=0.01;

constdoubleMINPAY_FRACTION=0.10;

classCreditAccount

(

public:

CreditAccount();//setseverythingto0

CreditAccount(doublebalance);//computeseverythingneeded

doubleinterestDue();

doubletotalDue();

doubleminPayDue();

private:

doublebalance;

doubleinterestDue;

doubletotalDue;

doubleminPay;

);

doubleCreditAccount::interestDue()

(

returninterestDue;

)

doubleCreditAccount::totalDue()

(

returntotalDue;

)

doubleCreditAccount::minPayDue()

(

returnminPay;

)

CreditAccount::CreditAccount()

:balance(0)ztotalDue(0)zinterestDue(0)zminPay(0)

(

//Bodydeliberatelyleftempty.

//ThisisaC++idiom.SeethisIRMChapter10.

//ThisiscoveredinAppendix7ofthetext

)

CreditAccount::CreditAccount(doublebalance)

if(balance<=1000)

interestDue=balance*INTEREST_RATE1;

elseif(balance>1000)

interestDue=1000*INTEREST_RATE1+(balance-1000)*INTEREST_RATE2;

totalDue=balance+interestDue;

if(totalDue<=10)

minPay=totalDue;

else

minPay=totalDue*MINPAY_FRACTION;

)

intmain()

(

cout.setf(ios::showpoint);

cout.setf(ios::fixed);

cout.precision(2);

charans;

doublebalance;

do

(

cout<<"Entertheaccountbalance,please:";

cin>>balance;

CreditAccountaccount(balance);

cout<<"Interestdue:"<<erestDue()<<endl

<<•'Totaldue:"<<account.totalDue()<<endl

<<"MinimumPayment:"<<account.minPayDue()<<endl;

cout<<"Y/yrepeats.anyotherquits"<<endl;

cin>>ans;

)

while(1y,==ans||1Y'==ans);

)

Atypicalrunfortheclass/objectsolutionfollows:

Entertheaccountbalance,please:9.00

Interestdue:0.14

Totaldue:9.13

MinimumPayment:9.13

Y/yrepeats.anyotherquits

y

Entertheaccountbalancezplease:9.85

Interestdue:0.15

Totaldue:10.00

MinimumPayment:10.00

Y/yrepeats.anyotherquits

y

Entertheaccountbalancezplease:985.22

Interestdue:14.78

Totaldue:1000.00

MinimumPayment:100.00

Y/yrepeats.anyotherquits

y

Entertheaccountbalancezplease:1000

Interestdue:15.00

Totaldue:1015.00

MinimumPayment:101.50

Y/yrepeats.anyotherquits

y

Entertheaccountbalancezplease:2000

Interestdue:25.00

Totaldue:2025.00

MinimumPayment:202.50

Y/yrepeats.anyotherquits

q

2.CreditAccountproblem-Conventionalsolution

Computeinterestdue,totalamountdue,andminimumpaymentforarevolvingcreditaccount.

Inputs:accountbalance

Process:Computesinterest

interestaccordingto:

1.5%on1st$1000

1.0%onallover$1000

addsthistoaccountbalancegettotaldue.

Computesminimumpaymentaccordingto:

ifamountdue<$10z

minimumpaymentistotaldue

else

minimumpaymentis10%oftotaldue

outputs:Interestdue,totalamountdue,minimumpayment

data

balance

totaldue

interestdue

minimumpayment

//file:ch3n2con.cc

//conventionalsolution

//

//Purpose:Computeinterestdue,totalamountdue,andminimumpayment

//forarevolvingcreditaccount.

//

//Inputs:accountbalance

//

//Process:Computesinterest

//interestaccordingto:

//1.5%on1st$1000ofbalance

//1.0%onallover$1000ofbalance

//addsthistoaccountbalancegettotaldue.

//Computesminimumpaymentaccordingto:

//ifamountdue<$10z

//minimumpaymentistotaldue

//else

//minimumpaymentis10%oftotaldue

//

//Outputs:Interestdueztotalamountdue,minimumpayment

#include<iostream>

usingnamespacestd;

constdoubleINTEREST_RATE1=0.015;

constdoubleINTEREST_RATE2=0.01;

constdoubleMINPAY_FRACTION=0.10;

doubleinterestDue(doublebalance)

if(balance<=1000)

returnbalance*INTEREST_RATE1;

return1000*INTEREST_RATE1+(balance-1000)*INTEREST_RATE2;

)

doubleminPay(doubletotalDue)

(

if(totalDue<=10)

returntotalDue;

returntotalDue*MINPAY_FRACTION;

)

intmain()

(

doublebalance;

doubleinterestDue;

doubletotalDue;

doubleminPay;

cout.setf(ios::showpoint);

cout.setf(ios::fixed);

cout.precision(2);

charans;

do

(

cout<<•'Entertheaccountbalance,please:";

cin>>balance;

interestDue=interestDue(balance);

totalDue=balance+interestDue;

minPay=minPay(totalDue);

cout<<"Interestdue:"<<interestDue<<endl

<<"Totaldue:H<<totalDue<<endl

<<"MinimumPayment:"<<minPay<<endl;

cout<<"Y/yrepeats.anyotherquits"<<endl;

cin>>ans;

)

while('y'==ans||'Yans);

)

Atypicalrunfortheconventionalsolutiondoesnotdiffersignificantlyfromthe'class'basedsolution.

3.AstrologyClass/Objectsolution.

Notes:

Ihavenotdoneaconventionalsolution.Allthebitsandpiecesnecessarytodoaconventionalsolutionare

presenthere.Ialsohavenotdonetheenhancementssuggested.Ihave,however,includedcommentsthat

suggesthowtocarryouttheseenhancements.

Ihaveusedslightlymodifiednew_lineanddisplay_linecodefromthetext.Encouragestudentsnotto

reinventthewheel,thatis,tousebitsandpiecescodefromthebookandothersourcesaslongascopyrights

arenotviolated.

Iusedalibrarybookonastrologyformyreference.Anewspaperworksaswell.

Planning:

Input:user'sbirthday.Month1-12,day1-31

Process:tablelookupofsignsandhoroscopes,withrepeatatuser'soption

Output:SignoftheZodiacandhoroscopeforthatbirthday.

Hint:useranewspaperhoroscopefbrnames,datesanda

horoscopeforeachsign.

Enhancement:Ifbirthdayiswithin2daysoftheadjacent

sign,announcethatthebirthdateisona"cusp"andoutput

thehoroscopefortheadjacentsignalso.

Commentsandsuggestions.Programwillhavealongmultiway

branch.Storethehoroscopesinafile.

Askyourinstructorforanyspecialinstructions,suchasfilenameor

locationifthisisaclassassignment.

Planningforthesolution:

Whataretheobjectandclasses?

TheAstrologicalChartwouldbetheclassifweweredoingafullchart.WeareonlyselectingtheSunSign,

butwestillletAstrobetheclass.

ZodiacSignnamesanddates:

AriesMarch21-April19

TarusApril20-May20

GeminiMay21-June21

CancerJune22-July22

LeoJuly23-August22

VirgoAugust23-September22

LibraSeptember23-October22

ScorpioOctober23-November21

SagittariusNovember22-December21

CapricornDecember21-January19

AquariusJanuary19-February18

PicesFebruary19-March20

Horoscopefilestructure.

Theinitial<cr>isnecessarygiventhiscodetopreventoutputfromrunningonfromthefirsthoroscope.(We

didnotmakeuseofthesignnumber.)

<cr>

signnumber

horoscope

#

signnumber

horoscope

#

andsoon.

Pseudocodefortheclassandwhatmemberfunctionsdo...

classAstro

(

public:

constructors

Astro();

Astro(Datebirthday);

looksupandsetsthesignnumber,

Enhancement:

setsiscuspto-1ifbirthdayiswithin2days

beforetheadjacentsign,to-1ifwithin2days

afteradjacentsignand0ifneither.

memberfunctions

voidhoroscope();

Enhancement:

ifiscusp==-1,reporthoroscopebeforethe

currentoneandthecurrentone.

elseifiscusp==1,reportthecurrenthoroscope

andtheonefollowing.

else//iscusp==0,dothedefaultaction:

Unenhancedaction:

Dumpthehoroscopesfromfileuptothecurrentone.

Displaycurrenthoroscope.

How?#issentinelforendofahoroscope.Dumphoroscopes

through(signNumber-1)#symbols,usingutility-

functions.Displaythroughnext#usingutility

functions.

private:

Daybirthday;

intsignNumber;

voidnewHoroscope(istream&inStream);

//displayinStreamtonext#anddiscardthe#

voiddisplayHoroscope(istreamasourceFile);

//readandignoreinStreamthroughthenext#

//Enhancement:

//intisCusp();

Planningdone,nowtothecoding.Thecontentsof“horoscope.dat“arelistedwiththe'typicalrun'attheend

ofthefollowingcode.

//Program:file:ch3prb3.cc

//Requiresfile"horoscope.datnhavingstructure

//linesoftext

//#

//linesoftext

//#

//

//linesoftext

//#

#include<fstream>//forstreamio

#include<stdlib>//forexit()

usingnamespacestd;

//anenumcouldhavecertainlybeenusedhere

constintaries=1;

constinttaurus=2;

constintgemini=3;

constintcancer=4;

constintleo=5;

constintvirgo=6;

constintlibra=7;

constintscorpio=8;

constintSagittarius=9;

constintcapricorn=10

constintaquarius=11

constintpisces=12

//constmakescertainnoerrorthatchangestheseconstantsismade.

structmonth//nocheckingisdone...Lettheuserbewarned!

(

intday;//1..28zor29or30or31,dependingonmonth.

intmonth;//1..12

);

classAstro

(

public:

Astro();

Astro(monthbirthday);

//looksupandsetsthesignnumber

//Enhancement:setsiscuspto-1ifbirthdayiswithin2days

//beforetheadjacentsign,to-1ifwithin2days

//afteradjacentsignand0ifneither.

voidhoroscope();

//Enhancement:ifiscusp==-1,

//dump(signNumber-2)horoscopes

//elseifiscusp==1

//dump(signNumber-1)horoscopes

//displaynexttwohoroscopes.

//return;

//unenhancedaction:ifwegethereziscusp==0sowe

//dump(signNumber-1)horoscopes,

//displaynexthoroscope.

private:

monthbirthday;

intsignNumber;

voidnewHoroscope(istream&inStream);

voiddisplayHoroscope(istream&sourceFile);

//Enhancement:

//intisCusp;

);

//dumpsallfromfilethroughthenext#

voidAstro::newHoroscope(istream&inStream)

(

charsymbol;

do

(

inStream.get(symbol);

}while(symbol!=1#*);

//displaysallfromfilethroughthenext#

voidAstro::displayHoroscope(istream&sourceFile)

charnext;

sourceFile.get(next);

while(1#'!=next)

(

cout<<next;

sourceFile.get(next);

)

)

voidAstro::horoscope()

(

ifstreaminfile;

infile.open("horoscope.dat");

intc;

//cusp==0case:dumpsignNumber-1horoscopes.

for(inti=1;i<signNumber;i++)

newHoroscope(infile);

displayHoroscope(infile);

cout<<endl;

//Enhancement,changefrom//cusp==0case:

//sothat

//if(cusp==-1)

//dumpthru(signNumber-2)horoscopes

//elseif(cusp==1)

//dumpthru(signNumber-1)hororscopes

//fromthisposition,

//displaytwohoroscopes

//return

//thisisthecusp=0case,asabove.

)

Astro::Astro()//Iprefertousetheclassinitializerlist

{//notation.Thisfollowsthetext

signNumber=0;

//isCusp=0;//foroneoftheenhancementsIdidnotdo

)

Astro::Astro(monthbirthday)

//intsignNumber(monthbirthday)〃totestthisturkey

//looksupandsetsthesignnumber,

(

switch(birthday.month)

(

case1:

if(birthday.day<=19)signNumber=capricorn;

elsesignNumber=aquarius;

//enhancementcodewilllooklikethisinallthecases:

//if(17<=birthday.day&&birthday.day<19)cusp=-1;

//elseif(19<birthday.day&&birthday.day<=21)cusp=-1;

//elsecusp=0;

//

break;

case2:

if(birthday.day<=18)signNumber=aquarius;

elsesignNumber=pisces;

break;

case3:

if(birthday.day<=20)signNumber=pisces;

elsesignNumber=aries;

break;

case4:

if(birthday.day<=19)signNumber=aries;

elsesignNumber=taurus;

break;

case5:

if(birthday.day<=20)signNumber=taurus;

elsesignNumber=gemini;

break;

case6:

if(birthday.day<=21)signNumber=gemini;

elsesignNumber=cancer;

break;

case7:

if(birthday.day<=22)signNumber=cancer;

elsesignNumber=leo;

break;

case8:

if(birthday.day<=22)signNumber=leo;

elsesignNumber=virgo;

break;

case9:

if(birthday.day<=22)signNumber=virgo;

elsesignNumber=libra;

break;

case10:

if(birthday.day<=22)signNumber=libra;

elsesignNumber=scorpio;

break;

case11:

if(birthday.day<=21)signNumber=scorpio;

elsesignNumber=Sagittarius;

break;

case12:

if(birthday.day<=21)signNumber=Sagittarius;

elsesignNumber=capricorn;

break;

default:cout<<"nosuchmonthas"<<birthday.month

<<"Aborting"<<endl;

exit(1);

break;

)

)

intmain()

(

monthbirthday;

cout<<"Anynon-digitinthemonthfieldwillterminatetheprogram.

<<endl;

cout<<"Enterbirthdayinnumericform:monthday,as125:•'

<<endl;

cin>>birthday.month>>birt

温馨提示

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

评论

0/150

提交评论