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...
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...
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...
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.
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
Write a program to determine the minimum element in an array of ten elements. The program...
Write a program to determine the minimum element in an array of ten elements. The program should have the following: 1. Class Name as ArrayProcessing. The main method should create an array of size 10 2. There should be two methods besides the main method in the class namely inputArray and MinimumElement 3. InputArray method should assign the ten elements in the array. Use scanner to input these elements. The array of 10 numbers in the method "InputArray" should be...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...