Q1. Write a function prototype and a function definition called minimum that rec
ID: 3577934 • Letter: Q
Question
Q1. Write a function prototype and a function definition called minimum that receives an
array of type double, and the number of elements in the array. It returns the maximum value in the array.
Q2: Write a function called failed which receives an integer array of scores and the number of elements.
Return the number of students who scored > 80.
Q3:
Rewrite this else- if code segment into a switch statement if (num >= 1 && num < 5)
a = a - 1;
else if (num == 7)
{
b = b + 1;
x = 6;
}
else if (num > 8 && num <= 11)
c = c + 1;
else
d = d * 3;
Q4
Rewrite the following conditional expressions as if/else statement:
num+= count == 1 ? sales : count * sales;
Q5
Rewrite the following conditional expressions as if/else statements:
cout << (((num % 2 ) == 1) ? “Odd ” : “Even ”) ;
Explanation / Answer
Question 1:
//protoType
double minimum(double array[],int SIZE);
//function
double minimum(double array[],int SIZE)
{
double min = array[0]; //assume that starting index value has min value
// loops from 1 to length of array
for(int i=1; i < SIZE ; i++)
{
if(min > array[i])
min = array[i];
}
return min;
}
Sample program to test:
#include <iostream>
using namespace std;
double minimum(double array[],int SIZE);
int main()
{
double a[] = {1,2,3,4,5,6,7,8,9};
cout << minimum(a,9) << endl;
return 0;
}
double minimum(double array[],int SIZE)
{
double min = array[0]; //assume that starting index value has min value
// loops from 1 to length of array
for(int i=1; i < SIZE ; i++)
{
if(min > array[i])
min = array[i];
}
return min;
}
Question 2:
int failed (int array[],int SIZE)
{
int count = 0; //hold the student count greater then 80
// loops from 1 to length of array
for(int i=1; i < SIZE ; i++)
{
if(array[i] > 80)
count++;
}
return count;
}
Sample program to test:
#include <iostream>
using namespace std;
int failed (int array[],int SIZE);
int main()
{
int a[] = {10,89,83,94,55,96,77,88,69};
cout << failed(a,9) << endl;
return 0;
}
int failed (int array[],int SIZE)
{
int count = 0; //hold the student count greater then 80
// loops from 1 to length of array
for(int i=1; i < SIZE ; i++)
{
if(array[i] > 80)
count++;
}
return count;
}
Question 3:
switch(num)
{
case 1:
case 2:
case 3:
case 4:
a = a - 1;
break;
case 7:
b = b + 1;
x = 6;
break;
case 9:
case 10:
case 11:
c = c + 1;
break;
default:
d = d * 3;
break
}
Question 4:
if(count == 1)
{
num += sales;
}
else
{
num += count * sales;
}
Question 5:
if((num % 2 ) == 1)
{
cout << "Odd ";
}
else
{
cout << "Even ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.