Workshop_08

docx

School

Seneca College *

*We aren’t endorsed by this school

Course

100

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by MajorBearPerson1007

Report
Workshop 08 In this workshop, we will practice working with input, output, and random numbers. To achieve this, we will create a logic that mimics that of a magic 8 ball, which waits for questions, prints silly answers, and later provides statistics and a log of what the conversation was. Instructions Coding For this workshop, you will create a source code called workshop8.c . In it you will create logic to emulate a magic 8 ball, doing the following: 1. Your program will start by asking the user to enter a question (which might include spaces) 2. Following, your program will randomly select and print one of the following eight answers (with up to 64 characters), that are stored in a global variable: const char answers[8][64] = { "Yes, definitely", "Maybe", "Don't count on it", "Without a doubt", "Ask again later", "Outlook not so good", "Better not tell you now", "My sources say no" }; 3. Note that your program should keep track of all the questions that were asked, as well as all the answers that were provided. 4. Once the user enters “quit”, or after the user has entered 16 questions, your program should do the following: a. It should print a message saying that the answers are X per cent accurate, where X should be a random floating-point number between 90 and 100, printed with up to six digits, with two of them reserved for the decimal part. b. Following, it should print a log of the entire “conversation” showing each question that was asked, followed by each answer that was provided. 5. Finally, the program should terminate. General Instructions Make sure to break down your logic into a number of functions, where each function will do one thing, and one thing only! My recommendation is to create at least the following set of functions: One function to print a random answer (and possibly return the index of said answer). One function to keep a log of all the answers and questions. One function to print the log of the whole conversation. One function to print the stats about the accuracy of the answers.
Your code should have no global variables other than arrays[8][64]. Hints: To provide an array of char arrays to a function (like questions[8][64]), you must set the argument as a pointer to a char array (such as: char (*questions[64]) ). To compare a user input to “quit” , you must use the strcmp function from the string.h library. For example: strcmp(question, “quit”) return 0 if question is identical to “quit” To store a provided char array into a different char array, you must use the strcpy function from the string.h library. For example, strcpy(question, “Will I get rich?”) , stores the char array “Will I get rich?” into the char array question . Here is a possible example of a conversation. Reflection Can a computer really generate a random number? If so, explain how. If not, explain what computers can do instead to simulate randomness. Submission You should submit your source code file, workshop8.c , here on Blackboard. Make sure to add a comment at the top of the source code file containing the name of the workshop, and your name. For example:
// Workshop 08 – Hina Tariq Evaluation Generating random answers 0.50 marks Saving a log of questions and answers 0.75 marks Printing the conversation log 0.25 marks Calculating and printing stats 0.50 marks Reflection 1.00 marks
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help