Question

ELET 2300 Programming Assignment # 2 Write a program that generates an array filled up with random positive integer number ra

in C++ please

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <ctime> using namespace std; int main() {  int val;        int arr[1000];  int index=5;             for (int i = 0; i < index; i++) {   //to generate and add random number to array arr[i]=15 + (rand() % 6); }        while(1){//to continously itterate the program          char x;                 int key;                int l=0;                                 cout<< "Generated Number:\n";     //to display randomly generated array   for (int i = 0; i < index; i++)      {              cout<< arr[i];            cout<<'\t';               }                                               cout<<"\n[P]ostion,[R]everse,[A]verage,[S]earch,[Q]uit:\n";               cin>> x;                          if(x=='P' || x=='p') {                                          //to print key value pairs                      cout<< "Position Value Pairs:\n";                  for (int i = 0; i < index; i++)              {                      cout<<"("<<i<<","<< arr[i]<<")\n";                        }                                       }else if(x=='R' || x=='r') {                                            //to reverse the array and print the integers                   cout<<"Reversed Array:\n";                        for (int i=index-1; i>=0;i--) {                              cout<< arr[i];                    cout<<'\t';                       }                       cout<<"\n";                                       }else if(x=='A' || x=='a') {                                            //to calculate and print average of values of integers                                          int avg=0;                                       for (int i = 0; i < index; i++)              {                      avg+=arr[i];                    }                       avg/=5;                                                 cout<<"Average:"<<avg<<"\n";                                  }else if(x=='s'||x=='S'){                                               //to search and print the position of the key value                     cout<<"Enter Key to search: ";                    cin>>key;                         for(int i=0;i<index;i++){                                                            if (key==arr[i]) {                                                                              if(l==0){                                               cout<<"\n"<<key<<" is found at:\n";                                   }                                       cout<<i<<"\t";                                      l=1;                            }                       }                                               if (l==0) {                             cout<<key<<" is not found.\n";// if key not found                   }               }else if(x=='q' || x=='Q'){                     break;//to exit from loop               }                               cout<<"Add number to array:";                             cin>>val;                 arr[index]=val;                 index++;        }                } 

OUTPUT:

Generated Number: 20 20 19 19 20 [P]ostion, [R]everse, [A]verage, [S]earch, [Q]uit: Position Value Pairs: (0,20) (1,20) (2,19

Add a comment
Know the answer?
Add Answer to:
in C++ please ELET 2300 Programming Assignment # 2 Write a program that generates an array...
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...

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

    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 on the screen. After the creation and displaying of the array, the program displays the following: [Plosition [RJeverse, [Ajverage, [SJearch, [Qjuit Please select an option: Then, if the...

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

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • write a c++ program: User enter in 5 numbers, stores  them in an array then displays them...

    write a c++ program: User enter in 5 numbers, stores  them in an array then displays them from least -> greatest. Then create a char array the user will enter some letters, it gives a count on every 'a' then it gets replaced by an uppercase 'A'. Display the result. Then display only the last letter.

  • 2. Write a program that reads N integer numbers of array from the user and then...

    2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

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