C CODING Exercise 1 15 points Write a function that uses the

C++ CODING!!!

Exercise 1 (15 points)

Write a function that uses the declaration of constant PI, const double

PI = 3.1419;, which stores the value of p and accomplishes the following:

Prompt the user to input the value of a double variable r, which stores

the radius of a sphere. The program then outputs the following:

i. The value of A = 4r2, the surface area of the sphere.

ii. The value of V = (4/3)r3, the volume of the sphere.

Grading scheme: Declare and use PI correctly - 5 points; a function to calculate surface area correctly - 5 points; to calculate the volume correctly - 5 points.

Exercise 2 (15 points)

Write a function that takes as input five float numbers and return the average, then output squares of these numbers in your function. You should show this average number in main function using return statement.

Grading scheme: a function to calculate the mean - 5 points; a function to calculate squares - 5 points; a main function to call the functions above correctly - 5 points.

Exercise 3 (20 points)

Write a function bool isLeapYear(int year) to check for a leap year. A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400. Write a program to call your function.

Grading scheme: isLeapYear() function that checks a leap year - 10 points; a main function that takes the input and call the function (5 points).

Solution

Exercise 1:Code

#include<bits/stdc++.h>// cin cout

using namespace std;


double calSurfaceArea(double r)
{
   const double PI = 3.1419;
   return (double)4*PI*r*r;
}
double calVolume(double r)
{
   const double PI = 3.1419;
   return (double)(4/3)*PI*r*r*r;
}
int main() {


double r;
cout<<\"Enter radius r\ \";
cin>>r;
cout<<\"Suraface Area is \"<<calSurfaceArea(r)<<endl;
cout<<\"Volume is \"<<calVolume(r)<<endl;

return(0);
}

==================================================================================

Exercise 2:Code

#include<bits/stdc++.h>// cin cout

using namespace std;

float getSquare(float n)
{
   return n*n;
}
float calMean(float n1,float n2,float n3,float n4,float n5)
{
   float sum=0,avg=0;
   cout<<\"Square of \"<<n1<<\" is \"<<getSquare(n1)<<endl;
   cout<<\"Square of \"<<n2<<\" is \"<<getSquare(n2)<<endl;
   cout<<\"Square of \"<<n3<<\" is \"<<getSquare(n3)<<endl;
   cout<<\"Square of \"<<n4<<\" is \"<<getSquare(n4)<<endl;
   cout<<\"Square of \"<<n5<<\" is \"<<getSquare(n5)<<endl;
   sum=n1+n2+n3+n4+n5;
   avg=sum/5;
   return avg;
}

int main() {


float n1,n2,n3,n4,n5;
cout<<\"Enter 5 float numbers\ \";
cin>>n1;
cin>>n2;
cin>>n3;
cin>>n4;
cin>>n5;
cout<<\"Mean is \"<<calMean(n1,n2,n3,n4,n5);
return(0);
}

=================================================================================

Exercise 3:Code

#include<bits/stdc++.h>// cin cout

using namespace std;

int isLeapyear(int year)
{
   if(year %400==0)
return 1;
else if (year %100==0)
return 0;
else if(year % 4 == 0)
return 1;
else
return 0;
}

int main() {


int year;
cout<<\"Enter year\ \";
cin>>year;
if(isLeapyear(year))
{
   cout<<year<<\" is Leap Year\"<<endl;
  
}
else
{
   cout<<year<<\" is Not Leap Year\"<<endl;
}

return(0);
}

===============================================================

Please comment about my work

C++ CODING!!! Exercise 1 (15 points) Write a function that uses the declaration of constant PI, const double PI = 3.1419;, which stores the value of p and accom
C++ CODING!!! Exercise 1 (15 points) Write a function that uses the declaration of constant PI, const double PI = 3.1419;, which stores the value of p and accom
C++ CODING!!! Exercise 1 (15 points) Write a function that uses the declaration of constant PI, const double PI = 3.1419;, which stores the value of p and accom

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site