Write a program that simulates a Magic 8-Ball. Prompt the user for a question, and randomly select a response from a vector. The attached Responses file is available if you want to use it, OR you may create your own response file, OR you can add/modify/remove the responses in the attached file. Continue to prompt for questions until the user wants to exit the program (Pick your own exit condition, but the program must loop until the condition is met!).
HINT: Read the contents of the response file into an a vector. When the user enters a question, generate a random index and display the response from the vector with that index. Make sure to check for the exit condition.
To generate the random index, use the following in main() - this should be familiar by now...unsigned seed = time(0);
Make sure to include all the necessary header files (cstdlib, ctime, vector, etc.).If you use the provided response file, download the attached text file and place in same location as your program.
If you create your own response file, make sure to place it in the same location as your program.
SAMPLE RUN:Welcome to the Magic 8-Ball program!Ask yes/no questions and the program will give you clarity about the outcome...Enter EXIT to exit the program.
Please ask your question: Will I get a good grade in this class?Without a doubt, yes.
Please ask your question: Does the professor know what he's talking about?I'll tell you after my nap.
Please ask your question: EXIT
Exiting program. Goodbye!
Language is C++
Please make it as simple as possible.
Make program and response.txt file in same directory (folder).
//header file include for console input and output
//header file include for srand function
//header file include time function
//header file include for vector
//header file include for file input
using namespace std;
cout<<"Hello, Welcome to the Magic 8-Ball program!Ask yes/no questions and the program will give you clarity about the outcome...Enter EXIT to exit the program."<<endl;
//do while loop
//message to user
cout<<"Please ask your question:"<<endl;
//Prompt the user for a question
//if file is unable to open
cout<<"Error while opning file"<<endl;
//read lines from file
//push_back lines in vector
//generate the random index
//randomly select a response from a vector
//closing of file
//do while condition
cout<<"Exiting program. Goodbye!"<<endl;
//return to console
Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*See Solution
Q: Write a C++ program: you are now working for an accounting firm. Your employer is interested in dete...
A: This program accepts the number of hours and pay rate of an employee as input.For 40 regular hours a...
Q: What are the four components of php application and explain why these are so important?
A: Four components of a PHP application are the following:DatabaseHTMLSessions/Authentication/ CookiesU...
Q: what are the major differences between php and asp.net?
A: PHP stands for PHP Hypertext Preprocessor, it is server-side scripting used to make interactive and ...
Q: In MS Access, to ensure that a promised date valued entered must a future point in time, whichvalida...
A: Now() function:The Now() function in Microsoft Access is used to return current date and time based ...
Q: What is single loss expectancy? What is annualized loss expectancy? What is wrong with these risk me...
A: Single loss expectancy is related to risk management and is considered as the value related to money...
Q: I have written a code following the instructions below, but the choice 2, convert Fahrenheit to Cels...
A: Reason for not asking the user to enter another value:In the code given in the question, if the choi...
Q: WHAT ARE THE STAKEHOLDERS OF BITCOIN VALUE CHAIN?
A: The stakeholders in bitcoin value chain are:Developers Developers play an important role as they use...
Q: Using the data file capabilities of C++, create a Personnel file, personnel.dat on your drive and th...
A: Program Instructions:Use do-while loop to repeatedly present the menu.Use switch statement to opt di...
Q: PLEASE EXPLAIN ALL STEPS In the following code, determine the values of the symbols this, that, and...
A: Before explaining the difference first user must know about the Assembly language.Assembly language:...