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

The area of the circular crown is given by the following formula: * (r2^2 - r1^2

ID: 3603627 • Letter: T

Question


The area of the circular crown is given by the following formula: * (r2^2 - r1^2)
where r1 and r2 are the inner and outer radius, respectively.
Write a function that will receive pairs of lengths of radii as input arguments, and will return the areas of the crowns. The function should work when: the inputs are a pair of vectors, i.e. one vector of inner radii (R1) and a corresponding vector of outer radii (R2), of the same length n. In this case the function will return n values for the areas where each is calculated as * (R2i2 – R1i2) for each i n. For this case, your code needs to handle the user error when the two vectors provided as inputs do not have the same length. your code needs to handle the user error for vector inputs.

Explanation / Answer

#include<iostream>
#include<vector>

using namespace std;

int main(){

   vector<int> vec1,vec2;
   int a,count;
   cout << "Enter vector1 (-1 to end the vector) :";
   int count1 = 0;
   while(1){
       cin >> a;
       if (a == -1)
          break;
       vec1.push_back(a);
       count1++;
   }
   cout << "Enter vector2 (-1 to end the vector) :";
   int count2 = 0;
   while(1){
       cin >> a;
       if (a == -1)
          break;
       vec2.push_back(a);
       count2++;
   }
   if (count1 == count2){
       for (int i = 0; i<count1; i++){
          cout << "A[" << i << "]=" << 3.14 * (vec2[i] * vec2[i] - vec1[i] * vec1[i]) << endl;
       }
   }
   else {
        cout << "Radii vectors are of different size ";
   }
   return 0;
}

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