Question
solve it in c+*
Part II: Dynamic Arrays and Pointer Arithmetic Q5: Implement a subset function for a dynamic array which returns a new dynami
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;
void output(int *p,int size)
{
for(int i=0;i<size;i++)//print each of the array value
{
cout<<p[i]<<" ";
}
cout<<endl;
}
int* subSet(int *p,int size,int start,int end)
{
  
int len=end-start+1;//length of sub array
int *sub_arr=new int[len];//declare dynamic array of size len
for(int i=0;i<len;i++)
{
sub_arr[i]=p[i+start];//assign the correct values
}
return sub_arr;//return array
}
int main()
{
int size=20;
int *p=new int[size] {49,96,99,47,76,29,22,16,30,22,25,63,40,38,67,65,25,84,89,4};
output(p,size);
int *q=subSet(p,size,5,9);
output(q,9-5+1);

return 0;
}

comment if any doubts

Add a comment
Know the answer?
Add Answer to:
solve it in c+* Part II: Dynamic Arrays and Pointer Arithmetic Q5: Implement a subset function...
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
  • C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement...

    C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement the Inner and Outer classes (Circular Buffer of circular buffers using Queues). No need of any classes from the Standard Template Library (STL), not even vector. Add the member functions of those classes by following the codes of InnerCB.h and CBofCB.h below: // file: InnerCB.h // Header file for Inner Circular Buffer. // See project description for details. // #ifndef _INNERCB_H_ #define _INNERCB_H_ class...

  • -Create a function output() in C that takes the pointer to the array and its size...

    -Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (malloc format) (function prototype : void output(int *arrayPtr, int size); -Create a function check() in C that takes the pointer to the array and a number and checks if the number is in the array. If the number is in the array, returns the index of the element of the array holding the number. Otherwise, returns -1.

  • please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function...

    please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...

  • How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using...

    How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using namespace std; int main() {    // Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic    // tic tac toe board is an array of int pointers    // each int pointer in the board points to a row    // declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int)    const...

  • 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...

  • C++ problem with dynamic arrays is that once the array is created using the new operator...

    C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

  • 3460:209 Assignment 9-B Assignment9-B: The Element Shifter The purpose of this assignment is to help gauge...

    3460:209 Assignment 9-B Assignment9-B: The Element Shifter The purpose of this assignment is to help gauge your skills in writing small programs that involve pointers. The program also contains functions and may perform input, output, files and file processing, use arrays and vectors and/or c-string/string arrays, flow of control, and/or calculations. PROGRAM SPECIFICATION For this program, we are going to expand a standard array by dynamically allocating a new one with a larger footprint. The program will use a function...

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

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
ADVERTISEMENT