Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intensive Programming ================== # passByReference.c #include /* void func(int a, int b) { a += b; printf(func: a = %d b = %d , a,

Intensive Programming

image text in transcribed

image text in transcribed

image text in transcribed

==================

# passByReference.c

#include  /* void func(int a, int b) { a += b; printf("func: a = %d b = %d ", a, b); } void main() { int x = 5, y = 7; func(x, y); printf("main: x = %d y = %d ", x, y); } */ void func(int *a, int *b) { *a += *b; printf("func: a = %d b = %d ", *a, *b); } void main() { int x = 5, y = 7; func(&x, &y); printf("main: x = %d y = %d ", x, y); }
Task: Write a C program to play Mastermind against a human codebreaker. Mastermind is a simple two-player code-breaking board game. In the game, one player is the codemaker and the other is the codebreaker. The codemaker secretly selects a code consisting of an ordered sequence of four colors (c1, c2, c3, ca), each chosen from a set of six possible colors, with repetitions allowed. The codebreaker then tries to guess the code by repeatedly proposing a sequence of colors (g, g2, g3, ga). After each guess, the codemaker tells the codebreaker two numbers (b, w): the number of correct colors in the correct positions (b) and the number of colors that are part of the code but not in the correct positions (w) For example, consider the six colors: Blue, Green, Orange, Purple, Red, and Yellow. If the code is (B, G, 0, 0) and the codebreaker's guess is (O, G, P, 0), then the codemaker's response would be (2, 1), since the codebreaker has guessed the G and the second O correctly and in the correct positions, while having guessed the first O correctly but in the wrong position The codebreaker continues guessing until either the codebreaker guesses the code correctly or until twelve incorrect guesses are made Additio nal Specifications: The code to be guessed should be given as a command-line argument Use standard input and standard output only The input/output must exactly match the samples given, character for character Deliverables: A file named mastermind.c containing the ANSI C source code. The submission will not receive a grade if the file mastermind.c produces compilation warnings or errors. So, before submitting your solution, make sure it compiles cleanly using the gcc compiler as follows: $. gcc -ansi -Wall -Wextra -Werror mastermind . c Input/Output Sample 1 $ ./a.out PORG Available Colors: (B)lue (G) reen (0)range (P)urple (R)ed (Y)ellow No. guesses left: 12 Enter your guess: BB00 Feedback: 0, 1 No. guesses left: 11 Enter your guess: BBGG Feedback: 1, No. guesses left: 10 Enter your guess: OPPG Feedback: 1, 2 No. guesses left: 9 Enter your guess: OPYG Feedback: 1, 2 No. guesses left: 8 Enter your guess: PORG Feedback: 4, 0 YOU WIN! Input/Output Sample 2 $ ./a.cut PORG Available Colors: (B)lue (G)reen (0)range (P)urple (R)ed (Y)ellow No. guesses left: 12 Enter your guess BBBB Feedback: , 6 No. gues ses left: 11 Enter your guess: GGGG Feedback: 1, 0 No. guesses left: 18 Enter your guess: 0000 Feedback: 1, E No. guesses left: 9 Enter your guess: PPPP Feedback: 1, 0 No. gues ses left: 8 Enter your guess: RRRR Feedback: 1, No. guesses left 7 Enter your guess: YYYY Feedback: 0, 0 No. guesses left: 6 Enter your guess: GOPR Feedback: 1, 3 No. guesses left 5 Enter your guesS: OGPR Feedback: e, 4 No. guesses left: 4 Enter your guess: PGOR Feedback: 1, 3 No. guesses left: 3 Enter your guess: GPOR Feedback: e, 4 No. gues ses left: 2 Enter your guess: OPGR Feedback: 0, 4 No. guesses left: 1 Enter your guess: POGR Feedback: 2, 2 YOU LOSE! The code is PORG

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Explain the place of planning in human resource management

Answered: 1 week ago