I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f

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: 899604
Joined: Mon Aug 02, 2021 8:13 am

I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f

Post by answerhappygod »

I always give a positive rating!
Language is C++
I know this looks really long, but this is actually
pretty easy.
Just follow the steps in the document below and paste
your code in the answer.
Thanks!
I Always Give A Positive Rating Language Is C I Know This Looks Really Long But This Is Actually Pretty Easy Just F 1
I Always Give A Positive Rating Language Is C I Know This Looks Really Long But This Is Actually Pretty Easy Just F 1 (145.34 KiB) Viewed 49 times
In-Class 9 -Reference Parameter Functions In this exercise, you get practice writing functions that focus on returning information to the calling function. Please note that we are not talking about "returning" information to the user or person cxccuting the program. The perspective here is that onc function, like main(), can call another function, like swap or calculateSinglco). Your program passes information into the function using parameters; information is passed back "out" to the calling function using a single return value and/or multiple reference parameters. A function can only pass back 1 piece of information using the return statement. Your program must use reference parameters to pass back multiple pieces of information There is a sort of hierarchy of functions, and this assignment uses each of these: 1. nothing returned by a function - void functions 2. 1 value returned by a function using a return value 2 or more values returned by a function a function uses 2 or more reference parameters (void return value) b. a function uses a return value and reference parameters a. The main() function is provided below. You must implement the following functions and produce the output below: O o 1. double MaxNumbers(double numl, double num2); o Prompt and read 2 double in main() onuml and num2 not changed o Return the larger one between num1 and num2 If numl equals num2, return either one of them 2. Int calcCubeSizes(double edgeLen, double& surfaceArea, double& volume); pass by value incoming value edgelen o outgoing reference parameters surfaceArea and volume are set in the function retum 0 for calculations performed properly you return -1 for failure, like edgeLen is negative or 0 3. int splitNumber(double number, int& integral, double& digital); o pass by value incoming number as a double o split the absolute value of incoming number in two parts, the integral part and digital (fraction) part o outgoing reference parameters integral and digital are set in the function retrun O for calculation performed properly, return 1 if there is no fractional part, i.e. digital -- 0. And output "Integer number entered!" 4. int openAndReadNums(string filename, ifstream&fn, double&numl, double &num2); o pass by value incoming file name as a string o outgoing reference parameter iſstream fn, which you open in the function using the filename o read 2 numbers from the file you open, and assign outgoing reference parameters numl and num2 with the numbers 0

o the return value must be 0 when both the file opens OK and the numbers are read OK (OK means the fn variable is not 0 after you open and read) This means return O at the end of the function when things have executed OK. Inside the function: Check (!fn) after you try to open the file, and print "Error!" if it doesn't open, i.e. return 1 if the open fails. Check (!fn) after you (try to read the 2 values, and print "Error Reading!", if either read fails, return 2. Sample Input & Output Enter 2 numbers to find the max one: 82 The max one is: 8 Enter anedge Len: 2.4 Surface Area: 34.56 Volume: 13.82 Enter a number: 1.6 The integral part: 1 The decimal part: 0.60 Enter a filename to read from: sample1.txt first=2.10 second=3.50 third=3.70 ========================== second example I/O Enter 2 numbers to find the max one: 7.1 3.45 The max one is: 7.10 Enter a edgeLen: 3 Surface Area: 54.00 Volume: 27.00 Enter a number: 1618 The integral part: 1618 Integer number entered The decimal part: 0.00 Enter a filename to read from: sample2.txt first-1.10 second=3.00 third=4.10 Starter for main(: Don't forget to add include and using namespace statements. Several students did not use the starter code on the previous assignment, which caused horrible difficulties for them. Please just copy and use this code. int main() { int ret2;

double reti, numi, num2, number, area, volume, edgeLen; double f, s, third; int integ: double decimal; string filename; ifstream file; cout<<"Enter 2 numbers to find the max one: "; cin>> num1 >> num2; //function call #1 You add the call. reti = i cout<< fixed <<setprecision (2) << "The max one is: " « reti << endl; ; I! cout<< "\nEnter a edgeLen: "; cin >> edge Len; // function #2 You add the call, using surface and area as some of the parameters. ret2 = i cout << "Surface Area: " « area <<endl; « cout << "Volume: " <<volume<<endl; ; cout << "\nEnter a number: "; cin >> number; // function #3 You add the call, using number, 1/ numl as the integral and num2 as the decimal parameters. ret2 = i cout << "The integral part: " << integ <<endl; if ( > // You add a condition here { cout << "Integer number entered! \n"; } cout << "The decimal part: " << decimal <<endl; cout<<"Enter a filename to read from: "; cin>> filename: // function #4 You add the call, using file, numl, and num2 as some of the parameters. // You need to use the variables declared here in main(); make the // DATA TYPES in the CALL match the data types in the function definition! ret2 = ; if ( ! > // You add a condition here { // This variable file ifstream is the param returned by openAndReadNums (). // These statement reads and then print a third number. // You can read from file inside the function AND here because you // are passing file as a reference parameter, file >> third; cout<< "first=" « f«" second=" < s << " third=" « third <<endl; } else cout<< "File did not open or Read failed\n\n"; return 0; }

Submit Your Work to Web-CAT The assignment will be available on Web-CAT as soon as possible.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply