Question

In C++ Create a method that populates an array: pArray(), be sure to have the appropriate...

In C++ Create a method that populates an array: pArray(), be sure to have the appropriate return type, and parameters. Call pArray() in your main() method.

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int* pArray(int size){
    int* arr = new int[size];
    for(int i = 0;i<size;i++){
        cout<<"Enter value: ";
        cin>>arr[i];
    }
    return arr;
}

int main()
{
    int* arr = pArray(5);

    cout<<"Array:"<<endl;
    for(int i = 0;i<5;i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    return 0;
}

 
Know the answer?
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
Similar Questions
Be sure to ONLY Program this problem in C You are going to use an array...
Be sure to ONLY Program this problem in C You are going to use an array and a function, and print the values of that array backwards. Here's some guidelines to follow to help you out: 1. Setup your array manually (whichever values you want are ok, with as many as you want, and whichever datatype you prefer. That's all fine). 2. Be sure to call your function by sending two parameters to such function: the array’s length and the...
Be sure to create the algorithms (pseudocode or flowcharts) for all 4 functions plus the main...
Be sure to create the algorithms (pseudocode or flowcharts) for all 4 functions plus the main program. Create a very simple larger( ) function that takes 2 positive numbers as parameters and returns the larger value of the two numbers.    Use your larger function to help create the following functions -- reuse your function code. Create a simple larger3( ) function that takes 3 positive numbers as parameters and returns the largest value of the three numbers.   Create a simple...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Create a python class that initializes a position and an array Then create a method within...
Create a python class that initializes a position and an array Then create a method within that class that decides the next permutation of the array. Change the current permutation into whatever the next one will be as seen in the johnson trotter algorithm do your best with this information. dont have any more to give
Please create an array of Leg objects, one constructor that takes three parameters as constant C...
Please create an array of Leg objects, one constructor that takes three parameters as constant C string, and one number representing the distance in miles between the two cities Write a code block to create a static array (that is, not dynamic and not a vector) of 3 Leg objects using city names of your choosing. That's THREE objects, each created using THREE parameters. For example, the Leg class declaration looked like, class Leg { const char* const startCity; const...
Create a Python program that populates an array variable whose values(at least 5) are input by...
Create a Python program that populates an array variable whose values(at least 5) are input by the user. It should then perform some modification to each element of array using a loop and then display the modified array in a second loop. Include Header comments in your program that describe what the program does.
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Java Lab Assignment Write a method named findMax. The method will take an array of doubles...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) . method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for...
Create a main method inside the ShoppingCart - create a vegetable object - call the addprice...
Create a main method inside the ShoppingCart - create a vegetable object - call the addprice method polymorphically - call the display method polymorphically - create a meat object - call the addprice method polymorphically - call the display method polymorphically
C++ Write a recursive routine that will have a character array and an index as parameters...
C++ Write a recursive routine that will have a character array and an index as parameters and will return the count of all vowels (assume lowercase). You may assume that the index starts out at the END of the array.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT