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
Which type of connection is needed to synchronize data with a cloud service?
Svetllana [295]

Answer:

Internet

Explanation:

The "Cloud" is an Online service this means it works on the Internet and without the Internet you can't have access to it.

7 0
3 years ago
An automotive engine’s camshaft rotates?
ryzh [129]
<span>C. The same speed as the crankshaft..... hope this helps!
</span>
8 0
3 years ago
Change the function definition for myint so that xyzfunc uses the same memory locations for myint as in the calling program.
sattari [20]

Answer:

b) void xyzfunc (int &myint);

Explanation:

To use the same memory location as the variable in the calling function we have to pass the variable by reference means passing the same address to the function.So to do that we have use & operator which stands for address.

We will do this as following:-

void xyzfunc (int * myint);

Hence the answer is option b.

8 0
3 years ago
What are two great ways to find clues to locate commands on the ribbon?
Lapatulllka [165]

Solution:

Look at the tabs and hover over images. are two great ways to find clues to locate commands on the ribbon.

There are six main categories for command which are; one-click, toggle, split buttons, drop-down and tick box.  Categories can be mixed so it is useful to understand the basics to develop the Excel skills.

The ribbon is a user interface element created by Microsoft, which was introduced with Microsoft Office 2007. It is part of the "Microsoft Office Fluent" interface and combines the menu bar and toolbar into a single floating pane. By default, it is located at the top of the screen in Office applications, such as Access, Excel, PowerPoint, Word, and Outlook.

This is the required solution.


6 0
2 years ago
A narrative is a:
drek231 [11]
It is B.series of links to other stories.
7 0
2 years ago
Read 2 more answers
Other questions:
  • How is the Task Manager helpful in displaying which resources your computer is using and how fast?
    5·2 answers
  • Your manager asks you to calculate the sale price if the product is marked down 20 percent. You enter the original price in cell
    9·1 answer
  • What are parts of the prewriting process
    8·2 answers
  • Click to visit W3Schools.com
    14·2 answers
  • Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alre
    6·1 answer
  • Kathy created a video presentation of her company, which will be shown on a television show as an advertisement. Her company wan
    11·1 answer
  • An analog signal maintains a constant signal level for a period of time, then abruptly changes to a different constant level.
    5·2 answers
  • Complete the function favoriteFlower(). Note that the program will not run as is because the function is incomplete. The purpose
    15·1 answer
  • Which of these is installed only on Apple smartphones and tablets?
    5·2 answers
  • How to mark a discussion as read on canvas dashboard.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!