Question

1. Write code for a function that receives two parameters (a,and b) by value and two...

1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double.
The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value.

From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement.

2. After part 1 is completed, write code to get 20 integer numbers from the user. The code then displays how many of those numbers are above the average. To get proper credit you must follow these steps:

a. write a for loop to fill the array with numbers from the user. Use an array for this.

b. use a pointer to calculate the average of the numbers entered into the array of part a above, in another loop.

c. write a function, then pass the array, its size, and the average to that function. The function arguments would be a pointer to int, an int, and a float and it returns the count of the number of elements that are above the average.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1:

Answer:

#include <iostream>

using namespace std;

//function to calculate division and multiplication using reference variable
void calculateValues(double a, double b, double &c, double &d)
{
c = a / b;
d = a * b;
}
int main()
{
//variable declaration
double a, b, c, d;
  
//display message
printf("Enter the first number: ");
scanf("%lf", &a);
  
//display message
printf("Enter the second number: ");
scanf("%lf", &b);
  
//function calling
calculateValues(a, b, c, d);
  
//display result
printf("\na / b = %.2lf", c);
printf("\na * b = %.2lf", d);

return 0;
}

OUTPUT:

Question 2:

Answer:

#include <iostream>

using namespace std;

//function to count the number above average
int countAboveAvg(int a[], int size, float avg)
{
int count=0;
for(int i=0; i<20; i++)
{
if(a[i] > avg)
{
count++;
}
}
  
//return statement
return count;
}

int main()
{
//array and variable declaration
int num[20], total = 0, aboveAvg;
float avg;
  
//display message
cout<<"Enter 20 integer numbers: "<<endl;
for(int i=0; i<20; i++)
{
cin>>num[i];
}
  
for(int i=0; i<20; i++)
{
total = total + *(num+i);
}
  
avg = total / 20;
  
//function calling
aboveAvg = countAboveAvg(num, 20, avg);
  
//display result
printf("\nThe number of elements above average is: %d", aboveAvg);

return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
1. Write code for a function that receives two parameters (a,and b) by value and two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

  • C and C++ Console Application for Student Data 1- Write a function named Average that a....

    C and C++ Console Application for Student Data 1- Write a function named Average that a. Receives two integer numbers as parameter and returns the average b. Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above 2- Define a class named Student with following members: a. private data: 2 grades and a GPA (average). b. public constructor to initialize the members...

  • We want to write a function called sortTwo that takes two integer parameters, and after the...

    We want to write a function called sortTwo that takes two integer parameters, and after the function is called the first parameter is the smaller of the two values, and the second parameter is the larger of the two values. In other words, this is a miniature sorting function. For this problem you must supply the missing code for PARTs 1, 2, and 3 in the program below. // PART 1: function prototype int main ( ) { int x,y;...

  • C language 3. (10 pts) Write a function readSegment that takes three parameters, a float array...

    C language 3. (10 pts) Write a function readSegment that takes three parameters, a float array as a pointer p as the first parameter, and two int indices startldx and endldx. The function readSegment reads the content of the array between startIdx and endldx, without using additional local variables. 4. (10 pts) Write a function called doubleOdds that takes two parameters, an array of double pointed to by pointer p and endldx of int type. The function doubleOdds doubles (multiply...

  • Define a function called DisplayMax that has 3 parameters: the first two parameters are parallel arrays...

    Define a function called DisplayMax that has 3 parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMax must work when called with various types of actual arguments, for example string DisplayMax(string names[], int calories[], int size) or int DisplayMax(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with the...

  • Using the code snippet below, complete the missing sections using the comments as a guide ********************************************************************************...

    Using the code snippet below, complete the missing sections using the comments as a guide ******************************************************************************** #include <stdio.h> #include <stdlib.h> // The four arithmetic operations ... one of these functions is selected // at runtime with a switch or a function pointer float Plus (float a, float b) { return a+b; } float Minus (float a, float b) { return a-b; } float Multiply(float a, float b) { return a*b; } float Divide (float a, float b) { return a/b;...

  • Write in C code What to do Write a function with the following signature: float* matrix...

    Write in C code What to do Write a function with the following signature: float* matrix multiplication(float* left, float* right, int rows, int shared, int columns); The first two arguments are two pointers to the beginning of two matrices with the dimensions (rows,shared) and (shared, columns) correspondingly. The remaining arguments specify these dimensions. The return value will return a pointer to the very beginning of the result matrix. That said, you need to provide the space for the result matrix...

  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

  • Create a C project named login_l03t1. Create an array of int from parameters passed on the...

    Create a C project named login_l03t1. Create an array of int from parameters passed on the command line. Use argc to define the size of the array. Print the contents of the array in the format and Generate and print the total of the values in the array twice: once by using an index i, and a second time by incrementing a pointer to the array. I need help with this please! what I have done is below: int n...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT