Write a function including prototype and header which is passed an array of inte
ID: 3582292 • Letter: W
Question
Write a function including prototype and header which is passed an array of integers and the number of elements in the array. The function then sorts the array and returns to the calling program the value of the entry in the middle of the array. Heron's Formula for the area of a triangle with sides a, b and c is given by the formula: area = s(s-a) (s-b) (s-c) where s = (a+b+c)/2 Write a complete program which in main asks the user for the sides a, b and c of a triangle. Use variables of type double. Pass a, b and c to a function called area. In area calculate s defining s as a local variable. Then use s, a, b and c to calculate the area passing the answer back to main. In main, print the sides and the area with 2 decimal places as follows: The area of a triangle with sides a, b and c is xx.xx Example do not use: The area of a triangle with sides 3, 4 and 5 is 6.00 Write a complete C++ program which asks the user to enter 5 test scores. The program calculates the average to 2 places and passes it to a function which then determines the appropriate letter grade (90 or better A, 80 or better B, 70 or better C, 60 or better D, below 6 is an F). It returns the letter grade back to main. In main print the average and the letter grade. This is only a sample of output, do not use in your code. Enter 5 grades 75 80 85 90 95 Average= 85.00 grade BExplanation / Answer
int sort_array(int sortarr[],int n)//return integer value passing array and count of elements(n)
{
int i,j, tmp,middle;
for(i=0;i<=n;i++)
{
for(j=0;j<=n-i;j++)
{
if(a[j]>a[j+1])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
}
/*Print sorted array
cout<<"Sorted array: ";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}*/
middle= n/2;
cout<< "Middle of a"<<a[middle];
return a[middle];
}
/*Area of triangle*/
#include<iostream.h>
#include<conio.h>
// Function definition
double area(double a, double b,double c)
{
double area,s;
s=(a+b+c)/2;
Area=s*(s-a)*(s-b)*(s-c);//given in the ques as s(s-a)(s-b)(s-c)..but actually it should be sqrt(s*(s-a)*(s-b)*(s-c))
// Return area
return area;
}
int main()
{
double a,b,c,s,Area;
cout<<"Enter three sides of triangle : ";
cin>>a>>b>>c;
Area = area(a,b,c);
cout << "/the area of triangle with sides "<<a","<<b"and"<<c "is " << Area;
return 0;
}
/*Grades*/
#include<iostream.h>
#include<conio.h>
#include <iomanip.h>//to set precisions
char Findgrade(double avg){
char grade;
int avgr =(int)avg;
if(avgr>=90)
{
grade ="A";
}
else if(avgr>=80 && avgr<90)
{
grade ="B";
}
else if(avgr>=70 && avgr<80)
{
grade ="C";
}
else if (avgr >=60 && avgr<70)
{
grade ="D";
}
else
{
grade = "F"
}
return grade;
}
void main()
{
int grade[5], i;
double sum=0,avg;
char grade ;
cout<<"Enter 5 grades :";
for(i=0; i<5; i++)
{
cin>>grade[i];
sum=sum+grade[i];
}
avg=sum/5;
grade = Findgrade(avg);
//to get upto 2 places
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout<<"Average="<< avg
cout<<"Grade "<< grade;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.