Question

Please provide the full and correct solution to this problem.

Make sure to provide comments so I can understand what is going on.

Correct solution will receive thumbs up.

Thanks.

Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it o

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include<cstdlib>
#include <ctime>

using namespace std;


void display( int arr[] ,int size ){
    for (int i = 0; i < size ; ++i) {{


            cout<< arr[i] << " index  " << i;

        }
       cout<< endl ;

    }


}
void reverse( int arr[]  , int size ){

cout<< " THe array element in Reverse order is : " << endl;
    for (int i = size-1 ; i>=0  ; --i) {

        cout<< arr[i]<<" at index "<< size - 1 << endl ;

    }

   cout<<  endl ;

}


double average_array( int arr[]  , int size ){
double sum = 0 ;
    for (int i = 0; i <= size  ; ++i) {

        sum = sum + arr[i];


    }

    return sum/size ;// this will be the average

}

int search( int arr[]  , int size  , int element ){
int count = 0  ;
    for (int i = 0; i <=size  ; ++i) {

        if( arr[i] == element ){
            if ( count  == 0 ){
            cout << element << " is found at index : ";
                count++ ;}

            cout<< i  << " , ";

        }

    }
    cout<<endl ;

    if( count== 0 )
        cout<< " The searched element does not exist in the array "<< endl ;
}

int main(){
int arr[10];
   // to calculatee size of the array
    int size = sizeof(arr)/ sizeof(arr[0]);

    //

    srand(time(0));

    for (int i = 0; i <= size  ; ++i) {
        arr[i] =( rand() %5)  + 15 ;
    }
    char option ;
    int val ;//what to search
    while( option != 'Q' || option != 'q'){
    cout<< " Enter p to display array elements ."<<endl;
cout<<"Enter R to display reverse version of array "<< endl ;
    cout<< "Enter A to display average of the array elements"<< endl ;
    cout<< "Enter S to search an element in array "<< endl ;
    cout << "Enter Q to quit the program ";
    cin>> option;
        if( option == 'Q' || option == 'q')
            exit(1);

       if( option == 'P'|| option == 'p')
           display(arr , size );

    if( option == 'R' || option == 'r')
        reverse(arr , size );
    if( option == 'A' || option == 'a')
        cout<<"The average of all elements in the array is " << average_array(arr , size ) << endl<< endl << endl ;

    if( option == 's' || option == 'S') {
        cout << "Enter the element to search :";
        cin >> val;
        cout << endl;
        search(arr, size, val);


    }

    }

   return 0 ;

}

Enter p to display array elements Enter R to display reverse version of array Enter S to search an element in array Enter A tEnter p to display array elements Enter R to display reverse version of array Enter A to display average of the array element

Add a comment
Know the answer?
Add Answer to:
Please provide the full and correct solution to this problem. Make sure to provide comments so I can understand what is going on. Correct solution will receive thumbs up. Thanks. Write a program that...
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 a C++ program that generates an array filled up with random positive integer number ranging...

    Write a C++ program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of the array. -R (lowercase or uppercase): the...

  • in C++ please ELET 2300 Programming Assignment # 2 Write a program that generates an array...

    in C++ please ELET 2300 Programming Assignment # 2 Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array, the program displays the following: [P]osition [Reverse, [A]verage, (Search, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of...

  • Write a program that generates an array filled up with random positive integer number ranging from...

    Write a program that generates an array filled up with random positive integer number ranging from 60 to 100, and display it on the screen. After the creation and displaying of the array, the program displays the following: [R]everse [A]dd [S]earch E[xit] Please select an option:_ Then, if the user selects: - R (lowercase or uppercase): the program displays the reversed version of the array. - A (lowercase or uppercase): the program displays the sum of the elements of the...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

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