ThreeQuarters.cpp #include // ------ // Part 1 // ------ // - Develop a C++ template function called ThreeQua

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

ThreeQuarters.cpp #include // ------ // Part 1 // ------ // - Develop a C++ template function called ThreeQua

Post by answerhappygod »

ThreeQuarters.cpp
#include <iostream>
// ------// Part 1// ------// - Develop a C++ template function called ThreeQuarters() thatdoes the following:// - Has one single T typeinput parameter// - Has a T type returnvalue// - Continually multiplies theinput parameter by 3/4 until it is reduced to less than 1// - Sum up all the individualvalues computed along the way// - See Blackboard for manydifferent examples of this function being used
// ------// Part 2// ------// - As you work your value down to below 1, if at any time thevalue ends up// between 3.14 and 3.15, throw an std::exception// - Put the new code into the same function you developed for thefirst part
int main(){ // ------ // Part 3 // ------ // - Wrap up the code below in a propertry/catch block // - The goal of course is to run through thiscode without issue // - But if an exception gets caught, print "Ispecifically asked for no pie!" instead std::cout << "PART 1 - Enter an integervalue: "; int x; std::cin >> x; std::cout << "The transformed value is: "<< ThreeQuarters<int>(x) << std::endl;
std::cout << "PART 1 - Enter a doublevalue: "; double y; std::cin >> y; std::cout << "The transformed value is: "<< ThreeQuarters<double>(y) << std::endl; // ------ // Part 4 // ------ // Find any other input value (nothing close to7.459) that actually triggers the exception case
return 0;}
1) Develop a C++ template function named ThreeQuarters()that does the following:
2) Add an std::exception case to the ThreeQuarters()function:
3) Wrap the code in the runner file's main() functionwith a proper try/catch block
4) Find a different value (not close to 7.459) thattriggers the exception in the function
Submit only your C++ source code file with its CPPextensionIt is your responsibility to ensure you submit source code filesthat compile, link and run properly as they are pulled back off ofBlackboard
ThreeQuarters<int>(0) = 0ThreeQuarters<int>(1) = 1ThreeQuarters<int>(2) = 2 + 1 = 3ThreeQuarters<int>(3) = 3 + 2 + 1 = 6ThreeQuarters<int>(4) = 4 + 3 + 2 + 1 = 10ThreeQuarters<int>(5) = 5 + 3 + 2 + 1 = 11ThreeQuarters<int>(6) = 6 + 4 + 3 + 2 + 1 = 16ThreeQuarters<int>(7) = 7 + 5 + 3 + 2 + 1 = 18ThreeQuarters<int>(8) = 8 + 6 + 4 + 3 + 2 + 1 =24ThreeQuarters<int>(9) = 9 + 6 + 4 + 3 + 2 + 1 =25ThreeQuarters<int>(10) = 10 + 7 + 5 + 3 + 2 + 1 = 28
ThreeQuarters<double>(0) = 0ThreeQuarters<double>(1.125) = 1.125 + 0.84375 =1.96875ThreeQuarters<double>(2.25) = 2.25 + 1.6875 + 1.26562 +0.949219 = 6.15234ThreeQuarters<double>(3.375) = 3.375 + 2.53125 + 1.89844 +1.42383 + 1.06787 + 0.800903 = 11.0973ThreeQuarters<double>(4.5) = 4.5 + 3.375 + 2.53125 + 1.89844+ 1.42383 + 1.06787 + 0.800903 = 15.5973ThreeQuarters<double>(5.625) = 5.625 + 4.21875 + 3.16406 +2.37305 + 1.77979 + 1.33484 + 1.00113 + 0.750847 = 20.2475ThreeQuarters<double>(6.75) = 6.75 + 5.0625 + 3.79688 +2.84766 + 2.13574 + 1.60181 + 1.20135 + 0.901016 = 24.297ThreeQuarters<double>(7.875) = 7.875 + 5.90625 + 4.42969 +3.32227 + 2.4917 + 1.86877 + 1.40158 + 1.05119 + 0.788389 =29.1348ThreeQuarters<double>(9) = 9 + 6.75 + 5.0625 + 3.79688 +2.84766 + 2.13574 + 1.60181 + 1.20135 + 0.901016 = 33.297ThreeQuarters<double>(10.125) = 10.125 + 7.59375 + 5.69531 +4.27148 + 3.20361 + 2.40271 + 1.80203 + 1.35152 + 1.01364 +0.760232 = 38.2193ThreeQuarters<double>(11.25) = 11.25 + 8.4375 + 6.32812 +4.74609 + 3.55957 + 2.66968 + 2.00226 + 1.50169 + 1.12627 +0.844703 = 42.4659
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply