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

Given the above shape, ask the user for the height and the width of the above re

ID: 3785410 • Letter: G

Question

Given the above shape, ask the user for the height and the width of the above rectangle.

Calculate the area for half the rectangle, the area for the half circle and the area for the entire shape.

Requirement:

1) Use cin to grab the height

2) Use scanf to grab the width

3) Use a single printf statement to display the area for half the rectangle, the half circle and the total for the entire shape

4) Use a single cout statement to display the area of half the rectangle, the half circle and the total for the entire shape Note: All the areas will have to be calculated based on only the information that was inputted by the user (Height and width of the rectangle)

(The shape looked something like this...There is one rectangle with a half circle connected to the right side of the rectangle.)

Explanation / Answer

#include <iostream>
#include <stdio.h>
using namespace std;
# define M_PI 3.14159265358979323846
int main(){
   int *p1;

   double height;
   double width;
   cout<<"Enter height : ";
   cin>> height;
   cout<<"Enter width : ";
   scanf("%lf", &width);
   //Area of rectange ar = height * width
   double rectange_area = height * width;
   //Area of Circle ac = pi * radius * radius; Assuming radius is half of the width(diameter of circle) of rectangle.
   double circle_area = M_PI * (width/2) * (width/2);
   //double total_area = area of rectangle + area of circle - area of intersection of rectangle and circle(half the circle area)
   double total_area = rectange_area + circle_area - (circle_area/2);
   cout<< "rectange_area : "<<rectange_area << " circle_area : "<<circle_area << " total_area : " << total_area << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote