1. Let's make the game more playable! Currently, the player wins every other round and each game consists of a single turn. We want to change this! Create a new global variable named computerHealth and initialize it to 100. Inside the loop that represents a single game being played, place another loop. This loop will represent a single round of a game. In each iteration of the inner loop: • The computer will attack the player for a value between 0 and 50. • The player will choose an action (heal, block, special, or regular) • Make the calculated adjustments to computerHealth and playerHealth · If the player health goes below 0, count it as a player loss and break out of the inner loop. • If the computer health goes below 0, count it as a player win and break out of the inner loop. · Otherwise, the inner loop will iterate again (i.e. the computer will attack and the player will pick another action). • You can remove the previous logic of determining a winner based on if it's an even or odd round. 2. Update the block function to "return" two values. It should have one value parameter (computerDamage from before) and two reference parameters (named blockAmount and hitAmount). The function should calculate how much of the attack the user blocks. To do this, select a random number between O and computerDamage and assign it to blockAmount. After determining how much of computerDamage is blocked, assign the rest to hitAmount. In main, print the value of each (we will have access to both since the arguments will be passed by reference). 3. Update your program so that when the user decides to quit, it saves the number of wins and losses to a file. When the program starts, load the data (if it exists). When the program ends, overwrite the previous data with the updated data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ Question:

Hello based on the attached code picture, please update that code so it can follow the instructions given in the other picture. Thank you. 

1. **Let's make the game more playable!** Currently, the player wins every other round and each game consists of a single turn. We want to change this! Create a new global variable named `computerHealth` and initialize it to 100. Inside the loop that represents a single game being played, place another loop. This loop will represent a single round of a game. In each iteration of the inner loop:
   - The computer will attack the player for a value between 0 and 50.
   - The player will choose an action (heal, block, special, or regular).
   - Make the calculated adjustments to `computerHealth` and `playerHealth`:
     - If the player health goes below 0, count it as a player loss and break out of the inner loop.
     - If the computer health goes below 0, count it as a player win and break out of the inner loop.
     - Otherwise, the inner loop will iterate again (i.e., the computer will attack and the player will pick another action).
   - You can remove the previous logic of determining a winner based on if it's an even or odd round.

2. **Update the block function to "return" two values.** It should have one value parameter (`computerDamage` from before) and two reference parameters (named `blockAmount` and `hitAmount`). The function should calculate how much of the attack the user blocks. To do this, select a random number between 0 and `computerDamage` and assign it to `blockAmount`. After determining how much of `computerDamage` is blocked, assign the rest to `hitAmount`. In main, print the value of each (we will have access to both since the arguments will be passed by reference).

3. **Update your program so that when the user decides to quit, it saves the number of wins and losses to a file.** When the program starts, load the data (if it exists). When the program ends, *overwrite* the previous data with the updated data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.
Transcribed Image Text:1. **Let's make the game more playable!** Currently, the player wins every other round and each game consists of a single turn. We want to change this! Create a new global variable named `computerHealth` and initialize it to 100. Inside the loop that represents a single game being played, place another loop. This loop will represent a single round of a game. In each iteration of the inner loop: - The computer will attack the player for a value between 0 and 50. - The player will choose an action (heal, block, special, or regular). - Make the calculated adjustments to `computerHealth` and `playerHealth`: - If the player health goes below 0, count it as a player loss and break out of the inner loop. - If the computer health goes below 0, count it as a player win and break out of the inner loop. - Otherwise, the inner loop will iterate again (i.e., the computer will attack and the player will pick another action). - You can remove the previous logic of determining a winner based on if it's an even or odd round. 2. **Update the block function to "return" two values.** It should have one value parameter (`computerDamage` from before) and two reference parameters (named `blockAmount` and `hitAmount`). The function should calculate how much of the attack the user blocks. To do this, select a random number between 0 and `computerDamage` and assign it to `blockAmount`. After determining how much of `computerDamage` is blocked, assign the rest to `hitAmount`. In main, print the value of each (we will have access to both since the arguments will be passed by reference). 3. **Update your program so that when the user decides to quit, it saves the number of wins and losses to a file.** When the program starts, load the data (if it exists). When the program ends, *overwrite* the previous data with the updated data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.
### Employee Management Program

This simple C++ program allows users to manage employee records. The program gives users three choices: lookup an employee, add an employee, or quit the application.

#### Code Explanation

1. **Main Function**:
   - The program runs in a loop, continuously prompting the user to choose from three options:
     - Enter `1` to look up an employee.
     - Enter `2` to add a new employee.
     - Enter `3` to quit the program.
   - Based on the user's choice, the respective function (`lookupEmployee` or `addEmployee`) is called, or the program exits.

2. **Adding a New Employee**:
   - The `addEmployee()` function is invoked when the user chooses to add a new employee.
   - It collects the following details from the user:
     - **Employee ID**
     - **First Name**
     - **Last Name**
   - This information is appended to a file named `employees.txt`.

3. **Looking Up an Employee**:
   - The `lookupEmployee()` function is called to search for an employee by their ID.
   - The function opens and reads the `employees.txt` file.
   - If the employee ID entered by the user matches an ID in the file, the employee's name is displayed.
   - If the file does not exist or the ID is not found, appropriate messages are printed.

#### Detailed Considerations

- **File Handling**:
  - The program uses file operations to store and retrieve employee data.
  - It appends new records using `ofstream` and reads existing records using `ifstream`.

- **Error Handling**:
  - There is basic error handling to check if the file exists before attempting to read from it.
  - If an employee's record is not found during a lookup, an error message is displayed. 

This program serves as a basic introduction to file operations and control structures in C++. It could be expanded with features such as editing and deleting records or improved to handle larger datasets more efficiently.
Transcribed Image Text:### Employee Management Program This simple C++ program allows users to manage employee records. The program gives users three choices: lookup an employee, add an employee, or quit the application. #### Code Explanation 1. **Main Function**: - The program runs in a loop, continuously prompting the user to choose from three options: - Enter `1` to look up an employee. - Enter `2` to add a new employee. - Enter `3` to quit the program. - Based on the user's choice, the respective function (`lookupEmployee` or `addEmployee`) is called, or the program exits. 2. **Adding a New Employee**: - The `addEmployee()` function is invoked when the user chooses to add a new employee. - It collects the following details from the user: - **Employee ID** - **First Name** - **Last Name** - This information is appended to a file named `employees.txt`. 3. **Looking Up an Employee**: - The `lookupEmployee()` function is called to search for an employee by their ID. - The function opens and reads the `employees.txt` file. - If the employee ID entered by the user matches an ID in the file, the employee's name is displayed. - If the file does not exist or the ID is not found, appropriate messages are printed. #### Detailed Considerations - **File Handling**: - The program uses file operations to store and retrieve employee data. - It appends new records using `ofstream` and reads existing records using `ifstream`. - **Error Handling**: - There is basic error handling to check if the file exists before attempting to read from it. - If an employee's record is not found during a lookup, an error message is displayed. This program serves as a basic introduction to file operations and control structures in C++. It could be expanded with features such as editing and deleting records or improved to handle larger datasets more efficiently.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY