Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Declare a global constant named PI equal to 3.141592; 2. Declare variables na

ID: 3735109 • Letter: 1

Question


1. Declare a global constant named PI equal to 3.141592;

2. Declare variables named base, height, radiusa, radiusb, rec_area, and elli_area that hold real numbers.

3. Print on the screen “For the rectangle”

4. Call void function getData(base, height) that gets two lengths from the keyboard and returns them to main( ).

5. Print on the screen “For the ellipse”

6. Call void function getData(radiusa, radiusb) that gets two lengths from the keyboard and returns them to main( ).

7. Calculate the area of the rectangle and store the result in rec_area.

8. Calculate the area of the ellipse and store the result in elli_area.

9. Call void function printData(rec_area, elli_area) that receives the two areas and prints on the screen the message:

"The area of the rectangle is ", rec_area "The area of the ellipse is ", elli_area

Function getData(rpar1, rpar2 ) must:

1. Prompt the user to "Please enter two lengths: "

2. Get both values from the keyboard and store them in rpar1 and rpar2.

Note: rpar1 and rpar2 are reference parameters.
  

Function printData(vpar1, vpar2) must:

1. Format the output to display the numbers in fixed format with one decimal digit.

2. Print the message on the screen.

Note: vpar1 and vpar2 are value parameters.

IMPORTANT: See examples of void functions in the textbook and on my web page to get a starting point.

------------------------------------------------------------------------------------------------------------------------

Part B (16 points)

Modify the above program so that the areas are calculated by a couple of value-returning functions named area_rectangle( ) and area_ellipse( ). Each of these functions must call getData() to get the values, calculate the area, and return it through the function’s value.

IMPORTANT: steps 3 through 8 specified in Part A should be replaced by a couple of statements where these functions are called.

------------------------------------------------------------------------------------------------------------------------

Part C (5 points)

Modify the above program so that: printData() sends the output to an output file named output7.txt.

Note: The file must be opened in main() and passed to printData() as an argument. Don’t forget to close it at the end of your program.

Explanation / Answer

ANSWER:

#include <iostream>

#define PI 3.14159

using namespace std;

void getDataa(int base,int height){

cout<<"For the Rectangle";

cout<<"Base is: "<< base;

cout<<"Height is: "<<height;

}

void getDatae(int radiusa,int radiusb){

cout<<"For the Ellipse";

cout<<"Radius A is: "<< radiusa;

cout<<"Radius B is: "<<radiusb;

}

int rec_area(int base, int height){

cout<< "Area of Rectangle is: " <<base * height;

return base * height;

}

int elli_area(int radiusa, int radiusb){

cout<< "Area of Ellipse is: " << PI radiusa radiusb;

return radiusa * radiusb;

}

void printData(int rec_area,int elli_area){

cout<<rec_area;

cout<<elli_area;

}

int main() {

int base,height,radiusa,radiusb,rec_area,elli_area;

cout<<"Enter two lengths:";

cout << "Enter Height" << endl;

cin>>height;

cout << "Enter Base" << endl;

cin>>base;

getDataa(base,height);

rec_area(base,height);

cout<<"Enter two lengths:";

cout << "Enter Radius A" << endl;

cin>>radiusa;

cout << "Enter Radius B" << endl;

cin>>radiusb;

getDatae(radiusa,radiusb);

elli_area(radiusa,radiusb);

return 0;

}