GO Language In this assignment, you will: · Define your own types (struct and interface) · Write code that works with interfaces to support changing the behavior · Get experience with when you need to use pointers to preserve changes for later accesses · Use the standard functions to support console input and output Here are the requirements: 1) You need to write guess_num.go so it supports the “guess a number between X and Y” kind of game, but allows the user to either choose the numbers themselves or allow the computer to automatically generate the guesses. The point of this assignment is to work with interfaces, so you will have some specific requirements on how you solve the problem. 2) Let’s start with the sample output: a) First, the case where the user enters their own numbers: (user input in bold and red) Guess a number to demo interfaces   You have 3 guesses to guess a number from 1 to 10 Do you want to make the guesses? (y/n -- if n guesses will be generated for you): y Enter your next guess: 5

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 6E
icon
Related questions
Question

In GO Language

In this assignment, you will:

· Define your own types (struct and interface)

· Write code that works with interfaces to support changing the behavior

· Get experience with when you need to use pointers to preserve changes for later accesses

· Use the standard functions to support console input and output

Here are the requirements:

1) You need to write guess_num.go so it supports the “guess a number between X and Y” kind of game, but allows the user to either choose the numbers themselves or allow the computer to automatically generate the guesses. The point of this assignment is to work with interfaces, so you will have some specific requirements on how you solve the problem.

2) Let’s start with the sample output:

a) First, the case where the user enters their own numbers: (user input in bold and red)

Guess a number to demo interfaces

 

You have 3 guesses to guess a number from 1 to 10

Do you want to make the guesses? (y/n -- if n guesses will be generated for you): y

Enter your next guess: 5

Too low

Enter your next guess: 8

You win!

b) Now the case where the user lets the computer pick the numbers:

Guess a number to demo interfaces

 

You have 3 guesses to guess a number from 1 to 10

Do you want to make the guesses? (y/n -- if n guesses will be generated for you): n

The computer has chosen 5

Too low

The computer has chosen 8

Too high

The computer has chosen 6

You ran out of guesses. Game over

3) Your file will include one interface, IPlayer:

a) It has just one function prototype, guess(), which takes no parameters and returns an integer

4) Your file will include three struct’s:

a) Game which includes

i) An IPlayer for the player making the guesses

ii) Integers for the number of guesses made so far, the (random) number the user is trying to match, and the most recent guess

b) Autoguess for an object that generates guesses. It includes

i) Integers for the min and max possible values

ii) A pointer to the Game

c) Human which is defined as an empty struct

5) You need to write the following methods:

a) func (g *Game) play()

i) This plays the game by calling the player’s guess() to get the next guess and outputting the appropriate response

b) func (h *Human) guess() (num int)asks the user for the next number to guess (why the 5 and 8 above are in red)

c) func (a *Autoguess) guess() (num int) will return an appropriate guess based on choosing the middle value of the possible remaining values

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning