1. Write a function called void swap with two parameters, which will receive the address of x and y as pointer. The function should swap the value of x and y only if x is larger than y. Print the value of x and y after the function call. 2. Write a function called double getAverage(int *array, int SIZE), where it accept the array as pointer, and return the average of the array. Print the returned value from this function. Always use *array rather than subscript to access the array value.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question


1. Write a function called void swap with two parameters, which will receive the address
of x and y as pointer. The function should swap the value of x and y only if x is larger than
y. Print the value of x and y after the function call.


2. Write a function called double getAverage(int *array, int SIZE), where
it accept the array as pointer, and return the average of the array. Print the returned
value from this function. Always use *array rather than subscript to access the array
value.

ChangeIt_1 : 10
ChangeIt_2 : 6
ChangeIt_3 : 7
ChangeIt_4 : 8
Process exited after 0.2283 seconds with return value e
Press any key to continue .
Compner KESUUICES ompEog V DEDug STIna KESUItS a CIOSE
Transcribed Image Text:ChangeIt_1 : 10 ChangeIt_2 : 6 ChangeIt_3 : 7 ChangeIt_4 : 8 Process exited after 0.2283 seconds with return value e Press any key to continue . Compner KESUUICES ompEog V DEDug STIna KESUItS a CIOSE
#include <iostream>
using namespace std;
3E void ChangeIt_1(int n) {
n = 5;
}
void ChangeIt_2(int *n) {
*n = 6;
4
6.
7
}
99 void ChangeIt_3(int &n) {
n = 7;
}
int ChangeIt_4(int n) {
n = 8;
10
11
12
13
14
return n;
}
main(){
int *p; //declare p as pointer
int x=10, y=7, SIZE=5, data[SIZE]={1,3,2,5,4};
p=&x; //reference of x
15
16
17
18
19
20
ChangeIt_1(x);
cout « "ChangeIt_1 :
21
22
« *p <« endl;
23
ChangeIt_2(&x);
cout « "ChangeIt_2 :
24
25
« *р <« endl;
26
ChangeIt_3(x);
cout <« "ChangeIt_3 :
27
28
« *р << endl;
29
ChangeIt_4(x);
cout <« "ChangeIt_4 :
30
X =
31
« *р <« endl;
32
33
Transcribed Image Text:#include <iostream> using namespace std; 3E void ChangeIt_1(int n) { n = 5; } void ChangeIt_2(int *n) { *n = 6; 4 6. 7 } 99 void ChangeIt_3(int &n) { n = 7; } int ChangeIt_4(int n) { n = 8; 10 11 12 13 14 return n; } main(){ int *p; //declare p as pointer int x=10, y=7, SIZE=5, data[SIZE]={1,3,2,5,4}; p=&x; //reference of x 15 16 17 18 19 20 ChangeIt_1(x); cout « "ChangeIt_1 : 21 22 « *p <« endl; 23 ChangeIt_2(&x); cout « "ChangeIt_2 : 24 25 « *р <« endl; 26 ChangeIt_3(x); cout <« "ChangeIt_3 : 27 28 « *р << endl; 29 ChangeIt_4(x); cout <« "ChangeIt_4 : 30 X = 31 « *р <« endl; 32 33
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,