Place all declarations and definitions needed for the tasks below in one file, i.e. main.cpp file. In your main() function, include code that shows testing

Answered step by step
Verified Expert Solution
Question
70 users unlocked this solution today!

Place all declarations and definitions needed for the tasks below in one file, i.e. main.cpp file.

In your main() function, include code that shows testing the functions and classes you created as thoroughly as possible.

Part 1 (2 points)

Create a function template named randomPick() with three parameters of the same type and a return value of the same type as the parameters. When called, it should randomly pick one of the three parameters, and return that value.

Part 2 (2 points)

Create a function template named getChoice(), that has:

  • Two string parameters
  • Two other parameters, with the same type as each other.
  • A return value with the same type as the two parameters.

When it runs, it presents the user with a prompt using the two strings. Using a loop, it does input validation to continue the prompt until the user picks one of the items. Once they have picked a valid item, it returns the corresponding value from the other two parameters.

For instance, if I were to call

getChoice("seven", "eleven", 7, 11)

the user should see something like:

Please pick seven or eleven:

If they (eventually) enter "seven", the function would return the integer value 7.

Part 3 (2 points)

Answer the following two questions at the top of the main.cpp file.

Question 1: Why normally the entire template class, including both the declaration and definition (i.e. implementation), are placed in the .h file? If we choose to let the definition of the class be in the .cpp file, what should be the way to include it?

Question 2: The getQuotient() function takes two integers or doubles as input and returns the quotient. Taking the getQuotient() as example, what may go wrong when using this template?

// answers to the questions at the top of the main.cpp /// Question 1: Why normally the entire template class, including both the /// declaration and implementation, are placed in the .h file? If we choose to let /// the definition of the class be in the .cpp file, what should be the way to /// include it? /// Question 2: Taking the getQuotient() function as example, what may go /// wrong when using this template? /// The following is the minimal set of testing code. int main() { cout << "Part 1" << endl; cout << randomPick('1','2','3') << endl; cout << randomPick (11,22,33) << endl; cout << randomPick ("Mac","PC","Others") << endl << endl; cout << "Part 2" << endl; cout << getChoice("x","y", 1, 2) << endl << endl; /// User enters z -> system fails to get a choice /// User enters y -> system returns 2 return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Link Copied!

Step: 1

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

100% Satisfaction Guaranteed-or Get a Refund!

Step: 2Unlock detailed examples and clear explanations to master concepts

blur-text-image_2

Step: 3Unlock to practice, ask and learn with real-world examples

blur-text-image_3

See step-by-step solutions with expert insights and AI powered tools for academic success

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon Order free textbooks.
  • tick Icon 100% Satisfaction Guaranteed-or Get a Refund!

Claim Your Hoodie Now!

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books
flashcard-anime

Study Smart with AI Flashcards

Access a vast library of flashcards, create your own, and experience a game-changing transformation in how you learn and retain knowledge

Explore Flashcards

Students Have Also Explored These Related Databases Questions!