Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 9: Functions with value and reference parameters and file 10 Due: 3/3/21 Problem: Suppose your math professor asks you to write a C++ program

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Lab 9: Functions with value and reference parameters and file 10 Due: 3/3/21 Problem: Suppose your math professor asks you to write a C++ program that calculates the areas of a rectangle and of an ellipse and sends the results to an output file. abb Area base height Area - ** radius a radius b Note all images extracted from http://www.mathrinfan.com/are-calculation tool.html Your task: implement in C++ the algorithm solution shown below. Algorithm solution (in pseudocode): To solve this problem your program must perform the following tasks: Declare a global constant named PI equal to 3.141592 Declare variable named out File to represent the output file Declare variables named base, height, radiusa, and radiusb that hold double precision numbers Declare variables named ree_area, and elli area that hold double precision real numbers Open output file "output).txt" and relate it to outFile Print on the screen "For the rectangle" Call void function getData() and receive in base and height the two lengths read from the keyboard Print on the screen "For the ellipse" Call void function getData() and receive in radiusa and radiusb the two lengths read from the keyboard Call function area rectangle() to calculate the area of a rectangle and assign the returned value to rocarea Call function area_area_ellipse() to calculate the area of an ellipse and assign the retumed value to elli area Call function printData() to print the output to the output file Close the file You need to define the following functions in the provided file my unctions.hto implement part of the solution: 1) To get the data you must define function getData(pari, par2), Gets two lengths from the keyboard and returns them to the caller through the parameter list. Prompt the mer to "Please enter two length b. Get both values from the keyboard and store them in parland par ae 2) To print the output you must define function printDatafoFile, b, h, ar, ra, rb, ae). Receives the output file, base of the rectangle, height of the rectangle, area of the rectangle, radius a of the ellipse, radius b of the ellipse, and area of the ellipse and prints the output to the file. Except for the file all the other values received are double precision real numbers, It must: a. Format the output to display the numbers in fixed format with two decimal digits. b. Print the message to the output file (formatted as shown in my examples): "The area of the rectangle with base", b." and height", h. "is", ar "The area of the ellipse with radius", ra," and radius", rb, "is 3) To round a real number to a user-defined number of digits you must define function round_off(value, digits). Receives a value (double precision real number) and a number indicating a quantity of digits (whole number) and returns the value rounded to the specified number of digits. 4) To calculate the area of a rectangle you must define function area_rectangle(b, h). Receives the base and the height of the rectangle (double precision real numbers) and returns the calculated area (a double precision real number) rounded to one decimal digit. 5) To calculate the area of an ellipse you must define function area_ellipse(ra, rh). Receives radius a and radius b of the ellipse (double precision real numbers) and returns the calculated area (a double precision real number) rounded to one decimal digit. IMPORTANT: you must choose the most appropriate type of function and type of parameters for each of the functions described above. The program must compile without errors or warnings Open lab09_FML.epp in your IDE and implement the above algorithm (already provided in the source code as comments). . Note: Do NOT remove or modify the statements that I use to test certain things in your program. Run my sample solution to know how your program must behave. Pay attention to the input and the output formats. Your solution must behave exactly like mine. Carefully analyze the following figures and use them as a reference to ensure you do the right things dised For the rectangle Please enter the lengths: 2.3 4.25 For the ellipse Please enter two lengths: 3.82 5.18 Screen shot of the input 6 7 8 #include #include #include using namespace std; 9 10 11 11 Ignore this; it's a little function used for making tests 12 inline void _test(const char* expression, const char* file, int line) 13 { 14 cerr

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

Students also viewed these Databases questions