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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education