I need to write an algorithm (just the outline in plain english) to this problem
ID: 3585959 • Letter: I
Question
I need to write an algorithm (just the outline in plain english) to this problem.
Outline guideliness:
This assignment will help you prepare for Programming Assignment 2. Read the problem set for Programming Assignment 2. Create an outline in plain English. Place this outline in either //line comments or /*block*/ comments. For the PA2, you will place the C++ code under the corresponding lines of comments. Place these comments in a file called main.cpp. Also provide a functions.h which gives the function prototypes and a file called functions.cpp which gives a brief description of each function and an outline in plain English (in comments) for the algorithm to complete that function. When complete zip those 3 files (and ONLY those three files) into a file formatted like lastnameFirstinitialPA2.zip (e.g. augustinetPA2.zip)
Problem:
Have you ever wanted to predict the future? Well the Magic Eight Ball does just that. The original game was a softball sized “8-ball”. You would ask a question, shake it up and look at the result. There are 20 responses…10 positive, 5 negative, and 5 are vague. These responses are given in the file responses.txtPreview the documentView in a new window and listed in the last page. For this project, we want to recreate this, but give the ability to read in a set of responses, and add additional responses, and print out all of the responses in alphabetical order. Of course, we have to give seemingly accurate responses, which we will do by giving a random response. Program Details: You should have a menu with five lettered options. You should accept both capital and lower case letters in your menu options. The menu should do the task, then return to the menu (except in the case of exit). Any incorrect responses should get an error message, followed by a reprint of the menu. a. Read responses from a file b. Play Magic Eight Ball c. Print out responses and categories alphabetically d. Write responses to a file e. Exit Each menu item must be implemented using a function or sets of functions with appropriate input parameters and return values. Functions will have prototypes in a file called functions.h and defined in a file called functions.cpp. Also, you will have a struct for the response and whether it is positive, negative, or vague. That struct will also be in the functions.h file. Here is a general explanation of what each option should do: a. Read responses from a file: This will read the responses and their category from the file responses.txt into an array. b. Play Magic Eight ball: User will ask a question, and a random response with a category is given from the array. c. Print out responses and categories alphabetically: Need to sort the responses in the array and print them. d. Write responses to a file: Write the array of responses with the categories (on separate lines) to a new file. You can name that file responsesOutput.txt. Implementation Detail 1: Remember you will need to #include “functions.h” into both your main.cpp and functions.cpp. Implementation Detail 2: You should have a “duplicate guard” in your functions.h like: #ifndef FUNCTIONS_H #define FUNCTIONS_H //your code here #endif Implementation Detail 3: In most IDEs, you need to make sure all of your files are included in the project. For VS and csegrid, make sure all files are in the same directory. For XCode, you will need to place them in the same directory, then go to Product->Scheme->Edit Scheme and Use custom working directory where your .cpp and .txt files are located. For the csegrid run your program with g++ -o pa2.o main.cpp functions.cpp. Then run with ./pa2.o Implementation Detail 4: You must use (at least) one array, and struct. You may not use vectors or classes. Example: struct Magic { string response; string category; } Implementation Detail 5: You can not have any global variables. So you will need to declare variables in main, then pass them (as appropriate) to your functions. Remember that there is no built in size for arrays, so you will have to pass the size (and MAXSIZE when trying to add to an array) Implementation Detail 6: You will need to choose a random response. See the example at http://www.cplusplus.com/reference/cstdlib/rand/ Note: You need some additional #include statements. You will use srand ONLY once, then use rand() with the modulus operator (%) to get a number between 0 and size -1
Explanation / Answer
First create response file for user's questions.
rand - function which gives you random number, so that you can choose any one response against user's question from the response file
for option a - you have to give a file name where your response text is given
option b - choose any random integer using rand function (0 - size-1), for this you have to generate random number and use modulus operator(%) with size, to get the number.
optioin c - print all responses and categories, which you stored in some array of structure which contains response as string and categories also string type.
option d - in this take one file name as an input, and write all responses and categories to this file
option e - exit
put all these option in while loop with condition always true.
ask user to insert any option (a - e), if user entered any other value return error - invalid input,
and show again the menu
according to user's input perform action.