讲解:C HW6_BlackJack_S2017C/C++

ntroductionstd::string num_to_string(std::size_t n){// Create a string stream to hold nstd::ostringstream o;// Push the number into the stream and return the string valueo ‘9’) // only valid if digit from 0-9 inclusivethrow std::runtime_error(“Invalid input to char_to_num”);// value is char value minus 0 char valuereturn static_cast(c - ‘0’);}提交时只要提交game.cpp运行结果见截图,具体过程均有注释RequirementPIC 10A Section 1 - Homework #6 (due Wednesday, May 17, by 8 am)You should upload the file to CCLE. Submit this before the due date/time!Your work will otherwise not be considered for grading. Do not submit a zip-ped up folder or any other type of file besides the .cpp file requested of you.Be sure you upload files with the precise names that you used in your editorenvironment otherwise there may be linker and other errors when your home-works are compiled on a different machine. Also be sure your code compilesand runs on Visual Studio 2015.BLACKJACK – KIND OFThis homework is aimed at getting you to use random numbers, vectors, and to readand write functions!This is a one-player game that resembles BlackJack. There are 3 identical roundswhere a player attempts for the value of all cards in their hand to be within a fixed range.Each card of a standard deck of 52 cards has a value associated with it.• The cards numbered 2-10 are worth that many points; for example a 4 of any suithas a value of 4.• All Jacks (J), Queens (Q), and Kings (K) have value 11.• An Ace (A) is has value 12 if it is Spades and otherwise it has value 1.In each round, a number from 17 to 22 inclusive is randomly chosen as a lower boundfor the value of the user’s hand. The player aims for the total value of all cards in theirhand to reach or exceed the given target value, while at the same time ensuring the totalvalue of their hand does not exceed 22!At the start of every round, there is a full deck of 52 cards, represented by astd::vector (see the Card.h and Card.cpp files). Cards are dealt by a cardbeing randomly selected from the deck and removed from it.During a round, the target lower bound should be displayed and the user dealt a cardif they have chosen so (except for the first card that will always be dealt). The total valueof cards in the user’s hand should be displayed along with the cards in their hand. Then,1• if the value of their hand is within the desired range, they earn 1 point and are toldso.• if the value of their hand exceeds 22, they earn -1 points and are told so.• if the value of their hand is less than the target value, the player may choose whetheror not to be dealt another card by choosing ‘y’ for “yes” or ‘n’ for “no”.If they choose to be dealt no more cards, they do not earn or lose any points, theyare told they earned 0 points, and the next round, if there is one, commences. A roundshould end if the user is within range, without them having to choose not to be dealtmore cards!When the game is over, the score should be displayed.The specifics:Download the Card.h and Card.cpp files and include them in your workspace. Donot modify these files in any way. You must use the Card class in this assignent; someof the other functions included may also be of use to you.Write a Game.cpp file to submit on CCLE that implements the game describedabove. The desired input and a sample outputs are provided.In writing this Game.cpp program, you must define and use the following functionsin nontrivial ways in your code:• cardValue, which can be passed a Card as input and returns the card’s value asan int;• dealCard, which accepts an std::vector representing the deck of undealtcards, chooses a card at random and removes it from the deck, and returns thatselected Card;• showHand, which accepts an std::vector representing the player’s handand an int for the total value of cards in their hand, and which displays their handvalue and cards in hand to the console;• exceeds, which accepts two arguments, an int representing the max possible handvalue allowed and an int representing the user’s hand value, returning true only ifthe user’s hand value has exceeded the maximum possible hand value allowed; and2• inRange, which accepts three arguments, an int representing the target lowerbound for a hand value; an int representing the maximum possible hand valueallowed; and an int representing the user’s hand value, returning true only if theuser’s hand value is within the target range.You should declare the functions above int main() and define the functionsbelow int main().The desired format is below:Cards 2-10 are worth their numeric value.J, Q, K have a value of 11.An A has a value of 12 as a spade and 1 for other suits.Over 3 rounds, you will try to reach or exceed a target value, without going over 22!If you go over, you get -1 points; if you are within range, you get +1 points; otherwiseyou get 0 points.FOR EACH OF 3 ROUNDS [UNTIL THE USER WINS OR LOSES OR CHOOSES TO ACCEPT NO MORE CARDS[Target lower bound: [VALUE CHOSEN]Hand value is: [CORRECTLY COMPUTED HAND VALUE]Hand is: [LIST OF CARDS]Deal more? y/n: [USER ENTERS ‘y’ or ‘n’]]]转自:http://ass.3daixie.com/2019042536767033.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,496评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,407评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,632评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,180评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,198评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,165评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,052评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,910评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,324评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,542评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,711评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,424评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,017评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,668评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,823评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,722评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,611评论 2 353

推荐阅读更多精彩内容