Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is to be written in C++ and i use code blocks Convert the magic eight ball program from the arrays module to use a

This is to be written in C++ and i use code blocks

Convert the magic eight ball program from the arrays module to use a vector instead of an array. Be sure to do these things in your program:

use the push_back() function to initialize the array

modify the signature and prototype of the getAnswer() function

modify the code in the body of the getAnswer() function

remove any unneeded code, such as your constant for the number of answers

Here is the given code

#include #include #include

using namespace std;

string getAnswer (string m8Ball[], int nAnswers);

int main () { const int num = 12;

string array[num] = {"Yes of course", "without a doubt, yes", "you can count on it", "Forsure!", "Ask me later", "I'm not sure ", "I can tell you right now", " I'll tell you after my nap", "No way!", "I don't think so", " without a doubt, no", "the answer is clearly NO"};

srand((unsigned int) time (NULL));

while (1) { string userinput;

cout << "Enter the Question: " << " "; getline(cin, userinput);

if (userinput.compare ("x")==0) break; cout << "the magic ball says: "<< getAnswer(array, num) << " "; } } string getAnswer (string m8Ball[], int nAnswers) { int index = rand() % nAnswers;

return m8Ball[index];

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

Students also viewed these Databases questions

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago