WriteaC++programthatpromptsforanumberofrowsfromtheuserandthenprintsanhourglassofthatnumberofrows.
Yourhourglassmustabuttheleftmargin.Youmayuseonlythesinglecharacters''(space),'*'(asteriskorstar),andendlor'n'(newline)foryourhourglass.Youmaynotuseanyiomanipformattingcommandslikesetw()forthisprogram.
Yourhourglassmusthavebetween3and23rows,inclusive.Youmustforceareasonableinputfromtheuserfornumberofrows(donotlettheusergetpastthenumberofrowspromptunlesstheyenterareasonablevalue).Thenumberofrowsmustbeodd,soiftheuserentersanevennumber,addonetothenumberofrows.
YouMUSTusethealgorithmwediscussinclass.Particularly,youmustcalculatethenumberofspacesandstarsinthecurrentrowinoneplace,notspreadoutamongotherpartsofthecode.Donotjustfigureoutthenumberofspacesandstarsonthefirstrowbeforeprintingtherows,thenadjustthemupordownasyouprintrows.Workouthowtocalculatethesevaluesforeachrowgivenjustthecurrentrownumberandthetotalnumberofrows.Iwillgivehintsabouthowtodothisinclass.
Forexample,iftheuserenterseither6or7forthenumberofrows,printthefollowing:(50points):
邮箱:联系方式: