Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Considerthe class Terrarium below. class Terrarium l friend std::ostream& operator>tstd::istreama, Terrarium&); private: std::string name; double price, weightIan; bool rqueeklyWatering; i ; Implement the extraction operator

image text in transcribedimage text in transcribed
Considerthe class Terrarium below. class Terrarium l friend std::ostream& operator>tstd::istreama, Terrarium&); private: std::string name; double price, weightIan; bool rqueeklyWatering; i ; Implement the extraction operator function, such that when the following lines are executed: Terrarium ter; cin >> ter; the extraction operator function will prompt user to enter the name of the terrarium, the price (in USD), the weight in kilograms, whether it requires watering on a weekly basis; so as to initialize its own arguments: name, price, weightIan and rqueeklyWatering respectively. Note that data like name could consist of more than 1 word. Also, user should only need to key in lowercase "y" (true) or "n" (false) when asked if terrarium requires weekly watering. The entire Terrarium object should be thrown (as an exception object), if any of the following condition(s) are true : o the price (entered by user) is negative, or exceeds $1500.00 0 the weight in kilograms (entered by user) is negative, or exceeds 3 kg 0 whetherterrarium requires watering (entered by user) is NOT 'y' or'n' 0 any string variables (entered by user) is an empty string (6 marks) 8. Implement a function template that returns true if its 1" argument is a factor of its 2" argument, false if otherwise. a ) Write the function template for arglIsAFactorOfArg2. The template definition should include 2 generic types named 'U' and 'V'. The arglIsAFactorOfArg2 () function takes in two arguments, argument 1 is of parameterized type 'U', and argument 2 is of parameterized type 'v'. The return type for arg1IsAFactorOfArg2 ( ) is a boolean value. The return value is true only if argument 2 is fully divisible by argument 1, without remainder (i.e. remainder is 0 ) . Examples: long 1 = 22; int i = 600; short s = 3; char c = 'B'; arglIsAFactorofArg2 (s, c) returns : true arglIsAFactorOfArg2 (1, c) returns : true arglIsAFactorOfArg2 (s, i) returns : true arglIsAFactorOfArg2 (48, i) returns : false (3 marks) b) Suppose you are writing a program that invokes arglIsAFactorOfArg2 () . How many template functions would be generated at compile time, based on the above example? (1 mark)

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

Students also viewed these Programming questions