Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is it. i need help with this assignment General Instructions: You are required to submit one .c files that contains the instructions that you

Here is it. i need help with this assignment

General Instructions: You are required to submit one .c files that contains the instructions that you have written to solve the following problems. Place the C source code to solve the first problem in a file called lab4.c. Remember to include the lab number, problem title, your name, section number and due date of the problem output of your C program files that you submit. Your programs must be neat, easy to read, easy to understand, and easy to compile, execute, and run. Remember to use appropriate comments within your programs and to clearly label all outputs.

Purpose: Give you practice (1) learning when to create and use programmer-defined functions, (2) creating programmer-defined functions that perform some action, but that do not return a value, (3) creating programmer-defined functions that return one value and (4) creating several programmer-defined functions that support the solution of a related task of working with fractions.

Grading: You will be graded on the following criteria:(1) programming style, (2) correctness (3) ease of understanding, (4) ease of use.

Problem: You are going to rewrite the guessing games program to remove the duplicate code by writing functions to perform each part of the program, cutting the amount of code in half.

Overview. You will use the following function which you declare as prototypes at the top of the code under the #define statements.

You must use these functions with these parameter names. No global variables, no additional parameters or not using parameters. The should be no unused variables in any function.

int getGuess(int max);

void printNumLine(int guess, int n, int max, int isHints);

void playGames(FILE * myfile, int max, int isHints);

Plan of attack. If you follow these instructions step by step this should be straight forward. Do one step and test before moving onto the next.

Warning, do not try to do this program until you have the original lab3 working completely correctly.

Write an empty function getGuess and copy the do while loop into it. Then place the function call in your original code in both type of games and test.

guess = getGuess(MAX);

Write the function printNumLine and copy the loop from the Hints part of your code.

Add if (isHints && guess < n) to the test to print -i

Replace the loop in both straight printNumLine(guess, n, MAX, 0); // note isHints is false

and hints printNumLine(guess, n, MAX, 1); // note isHints is true

with call to printNumLine and test.

Now you have the inner two loops working for both types of games.

Notice that the only difference between the two calls is the true false flag isHints.

Now we are going to write the playGames function which will also work for both types.

Copy the loop from either type game into the playGames function between the open file and close file.

Copy the variable declarations you need into playGames.

Replace the loop in both types of games with a call to playGames

playGames(myfile, GAMES, MAX, 0); // straight

playGames(myfile, GAMES, MAX, 1); // hints

in playGames replace the 0 or 1 in printNumLine with isHints

replace MAX with the parameter max

Test

Think about how you could write one function to read the statistics and print the results instead of two separate chunks of code using isHints.

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 Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions