I’m working in c++ and can’t find what to put for the return value! I need it to get my arrays set up so my other functions can sort them.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
I’m working in c++ and can’t find what to put for the return value! I need it to get my arrays set up so my other functions can sort them.
gint PopulateArrays(int ascendingValues[], int descendingValues [], int RandomValues[])
{
int slot1;
int slot2;
int slot3;
int x =
144;
1999;
rand();
int y =
int z =
for (int i
= 0; i < MAX; i++)
{
int ascendingValues[]
{ x + 2 };
%3D
for (int i = 0; i < MAX; i++)
{
int descendingValues[] = { y - 2 };
%3D
for (int i = 0; i < MAX; i++)
{
int RandomValues[] = { z + rand() };
return "I dont know":
Transcribed Image Text:gint PopulateArrays(int ascendingValues[], int descendingValues [], int RandomValues[]) { int slot1; int slot2; int slot3; int x = 144; 1999; rand(); int y = int z = for (int i = 0; i < MAX; i++) { int ascendingValues[] { x + 2 }; %3D for (int i = 0; i < MAX; i++) { int descendingValues[] = { y - 2 }; %3D for (int i = 0; i < MAX; i++) { int RandomValues[] = { z + rand() }; return "I dont know":
Expert Solution
Problem Introduction

The requirement is to pass three empty arrays to a method named PopulateArray() and get that arrays filled with populated values.

Solution with Pass by Pointer

C++ does not support returning multiple values as well as returning multiple arrays. Thus this needs oto be achieved by passing a pointer of array's first element to the function. 

When pointer is passed, all the values in the array will be populated in called function PopulateArrays and there is no need to return the arrays as the changes are actually made at the address of the array in memory.

 

Thus the required function will have below prototype: 

 

void PopulateArrays(int *ascendingValues, int *descendingValues, int *RandomValues)

 

Void is the return type

PopulateArrays: The name of the function

Parameters: The function has three parameters which are pointers to the array

 

Implemented function

Please find below the function along with comments to understand the functionality. Please note that there is no need to add 3 for loops ( as used in shared function), all the arrays will be populated in single for loop.

 

void PopulateArrays(int *ascendingValues, int *descendingValues, int *RandomValues)
{
    int x = 144;//set initial x to 144 
    int y= 1999;
    int z = rand();
    for (int i = 0; i < MAX; i++){//use one loop for all arrays 
        ascendingValues[i] = {x+2};//ascendingValues will have value x+2 
        x= ascendingValues[i];//set x to previous element value + 2 
        descendingValues[i] = {y-2};//descendingValues will have value y - 2
        y = descendingValues[i]; //set y to previous element value -2
        RandomValues[i] = {z+rand()}; //this is random value which will add initial value of z to this method 
    }//end for 
}//end function 

 

Computer Engineering homework question answer, step 3, image 1

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY