Computer sciecne question in c++. From June 25-July 1, 1862, the Civil War and the attention of two nations focused on the area near Richmond, Virginia. A series of battles took place in which a Confederate army under General Robert E. Lee drove back General George B. McClellan's Union forces and thwarted the Northern attempt to capture the Confederate capital of Richmond, Va. McClellan was forced to retreat from a position 4 miles (6 km) east of the Confederate capital to a new base of operations at Harrison's Landing on the James River. The purpose of this assignment is to create a (very) simple simulation which re-enacts the Battle of Seven Days using coin flips. That said, this is still complicated enough that we should do some high-level planning. Such a road map, known as pseudocode, for this program appears below, as well as an indication of what background you need to finish each individual task. Because we will be constructing this program out-of-order as we build up individual concepts, this outline will help you determine where the individual piece that you’re writing at a given time fits into the big picture. In fact, you may want to insert the lines of pseudocode as comments into your code to help document what you’re doing as you go along. PSEUDOCODE OUTLINE • Declare variables Chapter 2 • Print beginning instructions Chapter 1 • Loop through the 9 battles Chapter 3 • Print the battle’s name Chapter 2 • Prompt user for guess Chapter 2 • Echo guess Chapter 2 • …following correction Chapter 3 • Get and print coin flip Chapter 3 • …as either heads or tails Chapter 3 • Determine and print battle winner and increment proper score Chapter 3 • Print running score Chapter 2 • Print final score and winner Chapter 3 • Print final historical data Chapter 1 PART 1 (after Chapter 1) • Create the project for this project on your IDE. Here you will store all files related to any programming assignments for this class. I strongly advise you to further organize your work by creating additional versions, one for each part of this assignment. • Below appears the standard header. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 /* ACADEMIC INTEGRITY PLEDGE - I have not used source code obtained from another student nor any other unauthorized source, either modified or unmodified. - All source code and documentation used in my program is either my original work or was derived by me from the source code published in the textbook for this course or presented in class. - I have not discussed coding details about this project with anyone other than my instructor. I understand that I may discuss the concepts of this program with other students and that another student may help me debug my program so long as neither of us writes anything during the discussion or modifies any computer file during the discussion. - I have violated neither the spirit nor letter of these restrictions. Signed:______________________________ Date:_____________ COPYRIGHT (C) 2016 (your name). All Rights Reserved. (Description of program) author (your name) version 1.01 (date) */ (Line numbers are purely for reference and are not to be typed in by you.) Type it in and save to your folder under main.cpp. Update the name of the public class and the header information accordingly. • Following the header, write a main method that displays the game’s beginning and ending screens. To begin the program print out 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 LET THE FLIP OF THE COIN REWRITE HISTORY /----------------------\\ | RETURN TO SEVEN DAYS | \\----------------------/ It is July 1, 1862, the final day of the Battle of Seven Days... In this re-enactment of the second day of battle, you are George B. McClellan in charge of the Unionists We will flip a coin to determine the outcome of the small battles for territories within the Seven Days area You have to predict whether the coin will come up heads or tails... Your code will be a sequence of cout statements. The double ‘\’ is not a typo; this is what’s required to trick the computer into printing out a single backslash, for reasons that we will explain later. For now just instruct the computer to display this text exactly as it appears. Next, in the same file, just as before, write code to print the end title: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 In the actual Battle at Seven Days, the Northern troops turned back Lee's final assaults at Malvern Hill (July 1).... The Confederates lost about 16,000 men... The Unionists lost about 20,000 men … McClellan's failure to capture Richmond, and the subsequent withdrawal of the Union's Army from the Yorktown Peninsula, signified the end of the Peninsular Campaign. • For this and all other programming assignments note the following: • This is not a group project. If you are having difficulty, consult with the professor, the teaching assistant, or the lab instructor only. • Follow the applicable elements of the documentation style and guidelines given in the text with regard to spacing, indentation, identifier names, comments, etc. PART 2 (after Chapter 2) • Make a copy of your code from Part 1 and place it under a separate name. Since you are going to be making changes to your code, it is better to keep your previously working copy as-is and edit only this new copy. To do this, in Code::Blocks, select "File" ⇒ "Save File as" ⇒ enter a program name such as "Version1-1.cpp". You also want to make a copy start again with your new version. You will need to remove Version1-1 from the project (because each project can only have one file with main()), by right-clicking on "Version1-1.cpp" ⇒ "remove file from project". You can alter this procedure as you like, but this is the basic idea. • Before displaying the opening title declare integer variables for your score, the computer’s score and the coin. Initialize all of these variables to zero. Also declare a string variable for the user’s guess. • Following the opening instructions, prompt the user for input (heads or tails) and echo back the choice. For example 1 2 3 4 5 6 7 8 Now General McClellan Do you predict the coin will come out heads (H) or tails (T)? Choose H or T: H You have chosen H Stand by to fight, General McClellan... (Here the user input is shown in boldface type.) • Finally, before printing the end title, print a summary of the action to this point as follows: 1 2 3 4 5 6 So far: McClellan 0 victories, Lee 0 Remember that, instead of just printing zeros, you are printing the values of the score variables declared earlier. • Simulate a coin flip by generating a random integer less than 2 (i.e., either 0 or 1). Store it in your coin variable (declared earlier) and display the result. For example, if the computer kicks out a zero as the random number, you should see 1 2 3 4 5 The result of the coin flip was 0 Remember the import statements for these libraries, positioned after the Academic Integrity Pledge and before the code for the program. • Save this revised program as you did for Part 1. PART 3 (after Chapter 3) • As before make a copy of your code from Part 2 in a new file and make changes only to this new copy. • Revise your program from Part 2 by doing the following: • Account for a user messing up. If the user enters something other than “H” or “T” for their guess, set the guess to “H”. Remember both now and in what follows to use a case-insensitive test on the user’s input. • Echo back the user’s choice by saying “heads” or “tails” instead of “H” and “T”. In other words, if the user enters an ‘H’, instead of printing “You have chosen H”, print “You have chosen heads”. • Translate the coin flip from numbers to words. In other words, if the computer generated a random zero, print “The result of the coin flip was heads” instead of “The result of the coin flip was 0”. Similarly match a random one with “tails”. • Remember from now on: a value of zero for the coin variable means “heads”, a one means “tails”. With this in mind determine the battle’s winner. • If the user guess and the random result are the same print the following 1 2 3 Well done, General McClellan... You have defeated Lee and add one to your (the human’s) score. • Otherwise print 1 2 3 I am sorry, General McClellan... but the battle goes to Lee and add one to the computer’s score. • Immediately before printing the end titles, print a summary declaring a victor. In other words, after all battles have been fought, if the human’s score is greater than the computer’s, print the following 1 2 3 4 5 The results show that George G Meade won the majority of the battles and is thus declared the victor on July 2 1863. If the computer’s score is larger, print “Robert E Lee” instead of “George G Meade” in this statement. • Enclose everything from the user guess for the coin flip to the printing of the running score inside a for loop running from 1 to 9. Remember to adjust all indentations accordingly. • Inside the loop, immediately before getting the user guess, print the name of the individual battle based on the value of the loop index variable. If the index variable is… the battle name is… 1 Little Round Top 2 Cemetry Ridge 3 Devils Den 4 The Wheatfield 5 The Peach Orchard 6 Culps Hill 7 Zieglers Grove 8 Seminary Ridge 9 Gettysburg Your print statement should display the word “Battle ”, the battle number, a “ – ”, and then the battle’s name. • Check and make sure this all works right. The beginning and ending instructions, as well as the declaration of a final winner, should print only once. The game itself, with the guess at the coin flip, the actual coin flip, the declaration of an individual battle winner and the display of the running score should happen 9 times in all.

Public Answer

L6HNFD The First Answerer