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
1. Given two numbers, n and k ( 0&lt; n, k &lt;=12), generate all the pemutations taking k letters from n letters (nPk) consider
mixer [17]
It is 5jsjsjdhhdhdhdhdhdhdhdhdhd
8 0
3 years ago
Hi guys, so I dont have a homework related question. I was just wondering if it was possble to upload screenshots on Brainly ins
Anastaziya [24]

Answer:

yes it is possible to upload a screenshot on brainly

7 0
3 years ago
It is best to say that electric motors require _______ to work.
Mila [183]
Electricity (energy, current, power, voltage ... depending on the context)
4 0
3 years ago
A __________ is a device that allows a computer, which works with digital information, to communicate over lines that use analog
navik [9.2K]

Answer:

MODEM(Modulator Demodulator)

Explanation:

A modem is a device used in data communication that allows analog signal to be sent over a telephone line.

The modem works by converting the analog signal into digital data that the computer understands. The digital data is converted back to its original form at the receiver end.

Modem modulates analog signal from a telephone line to digital data the computer can understand. also, at the receiver end, it demodulates the digital data back to its original analog signal.

3 0
3 years ago
In older systems, often the user interface mainly consisted of _____ screens that allowed a user to send commands to the system.
marshall27 [118]

Answer:

Option (2) i.e.,  process-control is the correct answer

Explanation:

In the following statement, Process-control screen provides users to send command to the system when the interface of the following users is mainly made up of in the older systems. So, that's why the user interface generally consists of a process-control screen which permits the user to transfer the following details in the system.

7 0
3 years ago
Other questions:
  • JavaScript
    10·1 answer
  • __________ is when a person feels compelled to acquire and abuse a drug despite the harm it causes him or her personally, and de
    7·2 answers
  • What is meant by polling mode in communication between software andUART and what is its disadvantage as compared to interrupt mo
    14·1 answer
  • An arrangement in which local businesses team up with schools, hiring students to perform jobs that use knowledge and skills tau
    9·2 answers
  • Which type of computing device is best suited to having a digital pen as an input device?
    9·1 answer
  • [C++ for array week|
    8·1 answer
  • Assume that you have 22 slices of pizza and 7 friends that are going to share it (you've already eaten). There's been some argum
    9·1 answer
  • Ryo currently earns a monthly salary of $2200. She has been offered a raise of $250 per month. How much more will she earn per y
    14·1 answer
  • (Reverse number) Write a program that prompts the user to enter a four-digit inte- ger and displays the number in reverse order.
    9·1 answer
  • In this exercise, you'll raise a manual exception when a condition is not met in a particular function. In particular, we'll be
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!