1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Doss [256]
2 years ago
9

C++ Write a program that initially asks a user to enter two positive integer numbers a and b. If either a or are zero or negativ

e, the program terminates right away. Then, generate an array of 20 integer numbers, each randomly generated between a and b. If b happens to be greater than a, then the array must contain elements randomly generated between b and a. Display the whole array on the screen. After creating and displaying the array, the program shows:
[A]verage [S]um [F]ind Please choose an option: Then, if the user selects:
- A (lowercase or uppercase): the program computes and displays the average of all elements of the array
-A (lowercase or uppercase): the program computes and displays the average of all elements of the array
-F (lowercase or uppercase): the program asks the user to insert an integer number to be found in the array
If present, the program displays "Found in position number followed by the position of the first occurrence.
If not present, the program displays "Number not found in the array"
Computers and Technology
2 answers:
qaws [65]2 years ago
5 0

Answer:

#include <iostream>

#include <algorithm>

using namespace std;

int main(){

int a, b, c[20], search, maxi, mini, totalSum = 0;

char option;

int * p;

cout<< "Enter value for a: ";

cin>> a;

cout<< "Enter value for b: ";

cin>> b;

if (a == 0 || b == 0){

cout<< "Both values must be greater than zero.";

} else if(a>b){

maxi = a;

mini = b;

}

else{

maxi = b;

mini = a;

}

for (int i =0; i < 20; i++){

c[i] = (rand() % maxi) + mini;

totalSum += c[i];

}

cout << "Please choose an option: 1 , 2, 3 ";

cin>> option;

option = tolower(option);

switch(option){

case 1:

cout << "The Average of the array items is: "<< totalSum/20;

break;

case 2:

cout<< "The sum of the array items is: "<< totalSum;

break;

case 3:

cout<< "Enter number to be searched: ";

cin>> search;

p = find (c, c+20, search);

if (p != c+20)

{

cout << "Element found in c array: " << *p << '\n';

}else{

cout << "Element not found in c array\n";

}

break;

}

}

Explanation:

The C++ source code prompts the user for the a,b, option and search values and executes either of the options from the switch statement. Is correct

Explanation:

Great work person above me! :)

Brut [27]2 years ago
3 0

Answer:

#include <iostream>

#include <algorithm>

using namespace std;

int main(){

   int a, b, c[20], search, maxi, mini, totalSum = 0;

   char option;

   int * p;

   cout<< "Enter value for a: ";

   cin>> a;

   cout<< "Enter value for b: ";

   cin>> b;

  if (a == 0 || b == 0){

      cout<< "Both values must be greater than zero.";

  } else if(a>b){

        maxi = a;

       mini = b;

   }

else{

        maxi = b;

        mini = a;

   }

    for (int i =0; i < 20; i++){

        c[i] = (rand() % maxi) + mini;

        totalSum += c[i];

    }

   cout << "Please choose an option: 1 , 2, 3 ";

   cin>> option;

   option = tolower(option);

   switch(option){

       case 1:

           cout << "The Average of the array items is: "<< totalSum/20;

           break;

        case 2:

           cout<< "The sum of the array items is: "<< totalSum;

           break;

       case 3:

            cout<< "Enter number to be searched: ";

            cin>> search;

             p = find (c, c+20, search);

             if (p != c+20)

{

                cout << "Element found in c array: " << *p << '\n';

             }else{

                 cout << "Element not found in c array\n";

             }

             break;

   }

}

Explanation:

The C++ source code prompts the user for the a,b, option and search values and executes either of the options from the switch statement.

You might be interested in
_______________ ________________ have human editors that evaluate, select, and organize websites into a hierarchy of categories.
faust18 [17]

Answer:

wtaf dude?! at least do so on you're own questions! now I lost all of my answers thanks to you bro -_-

Explanation:

6 0
2 years ago
What are some ways you can give staying off your phone a "boost" and make it easier to do?
Arte-miy333 [17]

Answer:

go do something outside and leave your phone inside to charge

Explanation:

7 0
3 years ago
What were the names of Henry VIII's six wives?
timurjin [86]

Answer:

Jane Seymour,Anne Boleyn,Katherine of Aragon,Anne of Cleves,Katherine Howard,Katherine Parr

Explanation:

7 0
2 years ago
Read 2 more answers
What is the benefit of the load balancing logic to end-user?
Alborosie

Answer:

<em>It can minimize response time, and minimize the costs for the end user.</em>

Explanation

Load balancing is a form of workload distribution across several computers or resources. It allows each segment of the system to process a smaller task, minimizing respond time, helping to avoid overload, and contributing to optimize resource use.

6 0
3 years ago
What is the difference between simple and complex waveforms?
Nataliya [291]
Simple waveform - something like a sine wave. Very pure sound like you used to get on the tv when that girl was sitting with the toys in the middle of the night. Complex waveform is like speech etc
5 0
3 years ago
Other questions:
  • This information is generally included on a fax cover sheet.
    15·1 answer
  • _____ is a subset of a data warehouse in which only a focused portion of the data warehouse information is kept. A. Data diction
    6·1 answer
  • You should always assign the Needs Met rating before assigning the Page Quality rating, T or F ?
    6·2 answers
  • , 13 dB correspond to a power ratio of ....?
    14·1 answer
  • Agile Software Development is based on Select one: a. Iterative Development b. Both Incremental and Iterative Development c. Inc
    11·1 answer
  • Create the logic for a program that prompts a user for 12 numbers and stores them in an array. Pass the array to a method that r
    8·1 answer
  • Who watches Riverdale ? if you do can we be friends(pLEASE DON'T DELETE) and also who is your fav character from Riverdale
    8·2 answers
  • Which is the correct expansion of the term Internet?
    15·2 answers
  • The goal of this problem is to cover all roads with cameras. A camera placed at a station can cover all the roads connected to i
    9·1 answer
  • What is the most used gaming keyboard in 2022?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!