Question
c++ please
Instructions The aim of this is to develop various functions on an array. First, create an array (A) with 10 integers, which
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream> 
#include <stdlib.h>
using namespace std; 

void Copy(int A[],int B[],int size){
        for(int i = 0;i<size;++i){
                B[i] = A[i];//copying element from A to B
        }
}

void Reverse(int A[],int B[],int size){
        for(int i = 0;i<size;++i){
                int n = size - 1 - i;//index of the element at A
                B[i] = A[n];//copying element from A to B
        }
}

int main() 
{ 
        int A[10];
        int B[10];

        for(int i = 0;i<10;++i){
                A[i] = rand()%100;//generating random numbers from 0 to 100
        }

        cout<<"Initialisation of A..."<<endl;

        //displaying the data
        cout<<"\tA : ";
        for(int i =0 ;i<10;++i){
                cout<<A[i]<<", ";
        }
        cout<<endl;

        Copy(A,B,10);//calling Copy function

        cout<<"After Copy (A,B)"<<endl;
        cout<<"\tA: ";
        for(int i =0 ;i<10;++i){
                cout<<A[i]<<", ";
        }

        cout<<endl;

        cout<<"\tB: ";
        for(int i =0 ;i<10;++i){
                cout<<B[i]<<", ";
        }

        cout<<endl;

        Reverse(A,B,10);//calling Reverse function

        cout<<"After Reverse (A,B)"<<endl;
        cout<<"\tA: ";
        for(int i =0 ;i<10;++i){
                cout<<A[i]<<", ";
        }

        cout<<endl;

        cout<<"\tB: ";
        for(int i =0 ;i<10;++i){
                cout<<B[i]<<", ";
        }

        cout<<endl;
        cout<<"Bye..."<<endl;

        return 0; 
} 









Pratyushs-MacBook-Pro:cpp pthapli$ 9++ test.cpp Pratyushs-MacBook-Pro:cpp pthapli$ ./a.out Initialisation of A... A : 7, 49,

Add a comment
Know the answer?
Add Answer to:
c++ please Instructions The aim of this is to develop various functions on an array. First,...
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
  • Write C++ Program The aim of this is to develop various functions on an array. First,...

    Write C++ Program The aim of this is to develop various functions on an array. First, create an array (A) with 10 integers, which will be randomly selected from the range of 0 to 100. Print the items of the array on screen as one line. Write a function to copy A to B. The function signature should be "void Copy(int A[], int B[], int size)". This function copies content of A into B in the same order. - Write...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • Complete the mult() and printArr() functions #include <iostream> using namespace std; void init(int arr]05], int x)t //initialization loop for row 1 and 2 for(int i = 0; i < 2; i++){ arr i]...

    Complete the mult() and printArr() functions #include <iostream> using namespace std; void init(int arr]05], int x)t //initialization loop for row 1 and 2 for(int i = 0; i < 2; i++){ arr i][j] x; void mult(int arr JSD //multiply the elements of row 2 by row 1, and store result in row3 void printArr int arr ][5]) // a loop to print out all the elements of the array int main) int arr[3105] 31 int x 32 34 // initialize...

  • c++, we have to write functions for the code given below and other instructions for it...

    c++, we have to write functions for the code given below and other instructions for it to compile. I am having issues understanding how to confront the problem and how to write functions and read the program so it can eventually be solved so it can be compiled 7/ * INSTRUCTIONS: Write two functions in the space // * indicated below. // * // * #1 => Find index of maximum value: Write a function that will // * find...

  • Suppose a binary tree data (in tiny written size) is stored in an array (A) as...

    Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a)      In-Order Traversal b)     Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...

  • c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study...

    c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with...

    C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see: 11 12 13 14 15 21 22 23 24 25 31 32 33 34...

  • Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one...

    Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one that returns a value, but does not produce an effect) and a mutating function i.e one that changes the value of its parameters). In this exercise, we ask you to demonstrate your understanding o this distinction by implementing the same functionality as both a pure function, and as a mutating function. Both functions take a list of int as a parameter. The pure variant...

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