面向?qū)ο蟮腃程序設(shè)計(jì)第六版課后習(xí)題答案第三章_第1頁(yè)
面向?qū)ο蟮腃程序設(shè)計(jì)第六版課后習(xí)題答案第三章_第2頁(yè)
面向?qū)ο蟮腃程序設(shè)計(jì)第六版課后習(xí)題答案第三章_第3頁(yè)
面向?qū)ο蟮腃程序設(shè)計(jì)第六版課后習(xí)題答案第三章_第4頁(yè)
面向?qū)ο蟮腃程序設(shè)計(jì)第六版課后習(xí)題答案第三章_第5頁(yè)
已閱讀5頁(yè),還剩74頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Chapter3

MOREFLOWOFCONTROL

1.SolutionsforandRemarksonSelectedProgrammingProblems

Inordertopreserveflexibilityofthetext,theauthorhasnotdealtwithclassesinthischapteratall.Tohelp

thosewhoreallywanttodothingswithclasses,someoftheProgrammingProjectswillbecarriedoutusing

oneorseveralclasses.

1.RockScissorsPaper

Hereeachoftwoplayerstypesinoneofstrings"Rock1',"Scissors1',or"Paper*'.Afterthesecondplayerhas

typedinthestring,thewinnerofthisgameisdeterminedandannounced.

Rules:

RockbreaksScissors

ScissorscutsPaper

PapercoversRock

Ifbothplayersgivethesameanswer,thenthereisnowinner.

Anicetouchwouldbetokeepandreporttotalwinsforeachplayerasplayproceeds.

Tofindtheclasses,wenotefirstthatthereare2identicalplayers.Theseplayersrecordthecharacterentered,

andkeeptrackofthewins.Thereisaconstructorthatsetsthetotalwinsto0.Thereisaplay()member

functionthatpromptsforandgetsfromthekeyboardreturnsoneofthecharacters'R*,'P\orS'forrock,

paperandscissors.Thereisanaccessormemberfunctionforchandanincrementormemberfunctionfor

accumulatedwinssothatastandalonefunctionintwin(ch,ch);candeterminewhowinsandincrementthe

accumulatedwinsvariable.

(Abettersolutionwouldmakethewinsfunctionafriendofclassplayersothatwinscanhaveaccess

totheeachplayer'sprivatedatatodeterminewhowinsandupdatetheaccumulatedwinswithoutthe

accessorfunctionch()andincrementwins()function.)

NotethatIhaveleftabitofdebuggingcodeintheprogram.

classplayer

(

publicfunctionmembers

constructors()

1

Copyright?2007PearsonEducation,Inc.PublishingasPearsonAddison-Wesley

play();//promptsforandgetsthisplayer*smove

charch();//accessor

intaccumulatedWins();//accessor

incrWins();//incrementswincount

privatedata

charactertypedin

accumulatedWins

);

intwins(playeruserltplayeruser2);

//playerl1scharacteriscomparedtoplayer2'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.

//ThisfunctioncouldbewrittenomittingtheinitializerAand

//puttingthislineinthebody:

//totalWins=0;

)

voidPlayer::play()

(

cout<<"PleaseentereitherR)ock,P)aper,orS)cissors.u

<<endl;

cin>>ch;

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

)

charPlayer::Ch()

(

returnch;

)

intPlayer::AccumulatedWins()

(

returntotalWins;

)

voidPlayer::IncrWins()

(

totalWins++;

)

intwins(Player&userl,Player&user2);

//playerl1scharacteriscomparedtoplayer21scharacter

//usingaccessorfunctions.

//Thefunctionwinsreturns

//0iftherenowinner

//1ifplayer1wins,

//2ifplayer2wins,

//callstheappropriateIncrWins()toupdatethewins

intwins(PlayersuserlAPlayersuser2)//thismustchangeuserl

//anduser2

if((==userl.Ch()&&?Suser2.Ch())||

(1P*==userl.Ch()&&*R*==user2.Ch())II

('S'==userl.Ch()&&*P*==user2.Ch()))

//user1wins

userl.IncrWins();

return1;

)

elseif(('R*==user2.Ch()&&'S'==userl.Ch())

I|(*P1==user2.Ch()&&'R1==userl.Ch())

II('S1==user2.Ch()&&'P1==userl.Ch()))

(

//user2wins

user2.IncrWins();

return2;

}

else

//nowinner

return0;

)

intmain()

(

Playerplayerl;

Playerplayer2;

charans='Y1;

while(1YT==ans)

playerl.play();

player2.play();

switch(wins(playerl,player2))

case0:

cout<<"Nowinner.*'<<endl

<<*'Totalstothismove:"<<endl

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

<<endl

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

<<endl

<<“Playagain?Y/ycontinuesotherquits'1;

cin>>ans;

cout<<*'Thanks"<<endl;

break;

case1:

cout<<"Player1wins.**<<endl

<<"Totalstothismove:"<<endl

<<“Player1:n?playerl.AccumulatedWins()

<<endl

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

<<endl

<<nPlayAgain?Y/ycontinues,otherquits.

cin>>ans;

cout<<"Thanks*'<<endl;

break.;

case2:

cout<<"Player2wins.**<<endl

<<“Totalstothismove:"<<endl

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

<<endl

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

<<endl

<<“PlayAgain?Y/ycontinues,otherquits;

cin>>ans;

cout<<"Thanks”<<endl;

break;

)

ans=toupper(ans);

)

return0;

Atypicalrunfortheclass/objectsolutionfollows:

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

R

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

S

insideIncrWins()

1

Player1wins.

Totalstothismove:

Player1:1

Player2:0

PlayAgain?Y/ycontinuesfotherquits.y

Thanks

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

S

PleaseentereitherR)ock,P)aperzorS)cissors.

P

insideIncrWins()

2

Player1wins.

Totalstothismove:

Player1:2

Player2:0

PlayAgain?Y/ycontinues,otherquits.y

Thanks

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

P

PleaseentereitherR)ock,P)aperforS)cissors.

S

insideIncrWins()

1

Player2wins.

Totalstothismove:

Player1:2

Player2:1

PlayAgain?Y/ycontinues,otherquits.y

Thanks

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

P

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

P

Nowinner.

Totalstothismove:

Player1:2

Player2:1

Playagain?Y/ycontinuesotherquitsq

Thanks

1.RockScissorsPaper-Conventionalsolution:

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

typedinthestring,thewinnerofthisgameisdeterminedandannounced.

Rules:

RockbreaksScissors

ScissorscutsPaper

PapercoversRock

Ifbothplayersgivethesameanswer,thenthereisnowinner.

Anicetouchwouldbetokeepandreporttotalwinsforeachplayerasplayproceeds.

Thisisaconventionalsolutiontotheproblem.

//filech3nlcon.cc

//conventionalsolutiontotheRockScissorsPapergame

#include<iostream>//streamio

#include<cctype>//forinttoupper(int)

usingnamespacestd;

intwins(charchlzcharch2)

if((chi&&'Sch2)||

(Pchi&&*Rch2)||

(Schi&&'Pch2))

return1;//player1wins

elseif((1R1==ch2&&'S'chi)||

(1P1==ch2&&'R1==chi)||

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

return2;//player2wins

else

return0;//nowinner

)

charplay()

(

charch;

n

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

cin>>ch;

returntoupper(ch);//nocastneeded,charisreturntype

)

intmain()

intwins_l=0;

intwins_2=0;

charchi;

charch2;

charans=*Y1;

while('Y'==ans)

chi=play();

ch2=play();

switch(wins(chlfch2))

case0:

cout<<nNowinner.”<<endl

<<“Totalstothismove:<<endl

<<"Player1:<<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:<<wins_l<<endl

<<“Player2:<<wins_2<<endl

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

cin>>ans;

cout<<"Thanks<<endl;

break;

case2:

wins_2++;

cout<<nPlayer2wins.”<<endl

<<"Totalstothismove:“<<endl

<<"Player1:<<wins_l<<endl

<<nPlayer2:<<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,

computesinterestrtotaldue,minimumpay

interestDue()reportsinterest

totalDue()reportstotalamountdue

minPayDue()reportsminimumpaymentdue

privatedata

balance

totaldue

interestdue

minimumpayment

Class-objectImplementation:

//file:ch3prb2.cc

//Interest

//class-objectsolution

//Purpose:Computeinterestdue,totalamountdue,andminimumpayment

//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)AinterestDue(0)zminPay(0)

(

//Bodydeliberatelyleftempty.

//ThisisaC++idiom.SeethisIRMChapter10.

//ThisiscoveredinAppendix7ofthetext

)

CreditAccount::CreditAccount(doublebalance)

(

if(balance<=1000)

interestDue=balance*INTEREST_RATEl;

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<<nInterestdue:"<<erestDue()<<endl

<<"Totaldue:“<<account.totalDue()<<endl

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

cout<<nY/yrepeats.anyotherquitsn<<endl;

cin>>ans;

)

while(fy1==ans||1Y1==ans);

)

Atypicalrunfortheclass/objectsolutionfollows:

Entertheaccountbalance,please:9.00

Interestdue:0.14

Totaldue:9.13

MinimumPayment:9.13

Y/yrepeats.anyotherquits

y

Entertheaccountbalance,please:9.85

Interestdue:0.15

Totaldue:10.00

MinimumPayment:10.00

Y/yrepeats.anyotherquits

y

Entertheaccountbalance^please:985.22

Interestdue:14.78

Totaldue:1000.00

MinimumPayment:100.00

Y/yrepeats.anyotherquits

y

Entertheaccountbalance,please:1000

Interestdue:15.00

Totaldue:1015.00

MinimumPayment:101.50

Y/yrepeats.anyotherquits

y

Entertheaccountbalance,please: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<$10,

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<$10,

//minimumpaymentistotaldue

//else

//minimumpaymentis10%oftotaldue

//

//Outputs:Interestdue,totalamountdue,minimumpayment

#include<iostream>

usingnamespacestd;

constdoubleINTEREST_RATE1=0.015;

constdoubleINTEREST_RATE2=0.01;

constdoubleMINPAY_FRACTION=0.10;

doubleinterestDue(doublebalance)

if(balance<=1000)

returnbalance*INTEREST_RATEl;

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<<nInterestdue:“<<interestDue<<endl

<<nTotaldue:"<<totalDue<<endl

<<nMinimumPayment:"<<minPay<<endl;

cout<<nY/yrepeats.anyotherquits*'<<endl;

cin>>ans;

}

while(*y1==ans||fY1==ans);

)

Atypicalrunfortheconventionalsolutiondoesnotdiffersignificantlyfromthe'class'basedsolution.

3.AstrologyClass/Objectsolution.

Notes:

Ihavenotdoneaconventionalsolution.Allthebitsandpiecesnecessarytodoaconventionalsolutionare

presenthere.Ialsohavenotdonetheenhancementssuggested.Ihave,however,includedcommentsthat

suggesthowtocarryouttheseenhancements.

Ihaveusedslightlymodifiednewjineanddisplayjinecodefromthetext.Encouragestudentsnotto

reinventthewheel,thatis,tousebitsandpiecescodefromthebookandothersourcesaslongascopyrights

arenotviolated.

Iusedalibrarybookonastrologyformyreference.Anewspaperworksaswell.

Planning:

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

Process:tablelookupofsignsandhoroscopes,withrepeatatuser'soption

Output:SignoftheZodiacandhoroscopeforthatbirthday.

Hint:useranewspaperhoroscopefornames,datesanda

horoscopeforeachsign.

Enhancement:Ifbirthdayiswithin2daysoftheadjacent

sign,announcethatthebirthdateisona"cusp"andoutput

thehoroscopefortheadjacentsignalso.

Commentsandsuggestions.Programwillhavealongmultiway

branch.Storethehoroscopesinafile.

Askyourinstructorforanyspecialinstructions,suchasfilenameor

locationifthisisaclassassignment.

Planningforthesolution:

Whataretheobjectandclasses?

TheAstrologicalChartwouldbetheclassifweweredoingafullchart.WeareonlyselectingtheSun

Sign,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==1rreportthecurrenthoroscope

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(istream&sourceFile);

//readandignoreinStreamthroughthenext#

//Enhancement:

//intisCusp(};

Planningdone,nowtothecoding.Thecontentsof“horoscope.dal“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..28,or29or30or31,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:ifwegethere,iscusp==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!=;

)

//displaysallfromfilethroughthenext#

voidAstro::displayHoroscope(istreamSsourceFile)

(

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<<"nosuchmonthas11<<birthday.month

<<*'Aborting”<<endl;

exit(1);

break;

)

)

intmain()

(

monthbirthday;

cout<<"Anynon-digitinthemonthfieldwillterminatetheprogram.*'

<<endl;

cout<<"Enterbirthdayinnumericform:monthday,as125:11

<<endl;

cin>>birthday.month>>birthday.day;

do

(

cout<<birthday.month<<""<<birthday.day;

Astrouser(b

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論