CPP Assignment 2

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

In general always write your name and date of creation as comments in the files and
try to be “user friendly” when you write the code:
● Add comments on the code to remember yourself and the other what
the code does
● Manage the possible errors in the input given by the user
The 70% of this assignment consists in completing part 1) (including b) and 2) (a and
b), but if the mastermind program is not working 100% is ok!
1) Create a program to calculate the power of a number without using the function pow
or a loop. The base and exponent should be asked to the user and should be integer.
a) After that extend the program adding an additional function that takes the
same number of arguments (can have different type) of the previous one and
have the same name but calculate the n-square of the base, where n is the
exponent. (Here the function pow could be useful:
http://www.cplusplus.com/reference/cmath/pow/ )
b) What should be learn: overloading, functions
2) Have you ever played the game mastermind? Player A selects 4 balls of various
colors among 6 choices (RED(R), BLUE(B), GREEN(G), YELLOW(Y), PURPLE(P)
and ORANGE(O)), balls can not be repeated . Player B tries to guess what player A
choose by typing combinations of 4 colors. To every attempt players A replies with a
black ball for each color and position guessed correctly and with a white ball for every
color (and not position) correctly guessed by B. The game ends when player B guess
the position and colors of the 4 balls.
a) Try to code this, where player A is the computer and the combination is
selected random (remember that you can’t repeat the same ball more than
once, you need to re-extract if you get a ball already extracted). The user
should be able to play mastermind with the computer that at every turn should
reply with B or W or nothing depending on the combination of colors (letter)
given by the user
b) Output all the combinations needed by the user to guess the 4 balls in an
output file together with a message containing the number of combinations.
c) Try to write the code as composed by several functions that are called
in main.
d) What to learn: how to output to file, arrays, how to generate random number,
extensive use of functions, strings, pointers

  • CppAssignment2--rpvjt9.zip