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
Inessa [10]
3 years ago
10

Write a program that generates an array filled up with random positive integer

Computers and Technology
1 answer:
Scilla [17]3 years ago
8 0

Answer:

#include <iostream>

#include <cstdlib>  

using namespace std;

const int MIN_VALUE = 15;

const int MAX_VALUE = 20;

void fillArray(int arr[], int n) {

// fill up the array with random values

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

 arr[i] = rand() % (MAX_VALUE - MIN_VALUE + 1) + MIN_VALUE;

}

}

void displayArray(int arr[], int n) {

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

 cout << i << ": " << arr[i] << endl;

}

}

void main()  

{  

int myArray[10];

int nrElements = sizeof(myArray) / sizeof(myArray[0]);

fillArray(myArray, nrElements);

displayArray(myArray, nrElements);

char choice;

do {

 cout << "[P]osition [R]everse, [A]verage, [S]earch, [Q]uit ";

 cin >> choice;

 choice = toupper(choice);

 switch (choice) {

 case 'P':

  displayArray(myArray, nrElements);

  break;

 }

} while (choice != 'Q');

}

Explanation:

Here's a start. Now can you do the rest? ;-)

You might be interested in
nadine is the systems administrator for a network with a single subnet. The subnet uses 192.168.1.0 with a mask of 255.255.255.0
weeeeeb [17]

Answer:

Authorize Srv11

Explanation:

In order to fix this problem, Nadine should Authorize Srv11. The problem is most likely being caused due to failure of authorization of the server. This would prevent this server from being on the same scope as Srv1 and therefore, it is why the IPaddress being given is different. DHCP is an automatic protocol and would not be able to provide an IP address in the same scope if the server is not Authorized to do so.

3 0
3 years ago
Write a function called printbackwards() that will work with a c++ string. the function will print any c++ string backwards. you
dangina [55]
Hi!

Well, this isn't exactly a question - but rather just a request. However, I'm going to attempt to try and <em>describe </em>to you how to approach this problem, instead of just writing the code for you and sending you on your way.

So, what's our general base goal here? We want to take a string into a function, and then print it out backwards. Seems simple enough!

Right away, we already have an idea how to set this code up. We need a main method which will call <em>PrintBackwards(), </em>which will have to take a parameter of type string. 

This would look something like <em>PrintBackwards(string baseString). </em>Inside this method, we'd have to do something so we can see each character in this string and then store it in a new string. 

I encourage you to try and tackle this on your own, but I can give you an idea. We can have a new valueless variable called reversedString, which will store our baseString but backwards.

We could try looping through the baseString for each character it possesses, and then keep adding onto our reversedString by doing something like +=. What I mean, is we'd access the very last index of baseString, and then keep appending characters into it. 

So our loop would look something like <em>for(int i = baseString.length; i > 0; i--) {}. 

</em>I haven't used C++ in awhile, so you'll have to find the specific syntax requirements. But with that loop, i represents the index of each character in baseString. It starts with the last index, and keeps going down in reverse.
<em>
</em>Inside our loop, we could do something like reverseString += baseString.index(i); Again, I don't remember the specific syntax - so you'll have to do this on your own.
<em>
</em>Hopefully, this helps! =)<em>
</em>
6 0
3 years ago
C++
Cerrena [4.2K]

Answer:

#include <iostream>

#include<iomanip>

using namespace std;

double DrivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)

{

  double dollarCost = 0;

  dollarCost = (dollarsPerGallon * drivenMiles) / milesPerGallon;

  return dollarCost;

}

int main()

{

  double miles = 0;

  double dollars = 0;

  cout << "Enter miles per Gallon   : ";

  cin >> miles;

  cout << "Enter dollars per Gallon: ";

  cin >> dollars;

  cout << fixed << setprecision(2);

  cout << endl;

  cout << "Gas cost for 10 miles : " << DrivingCost(10, miles, dollars) << endl;

  cout << "Gas cost for 50 miles : " <<DrivingCost(50, miles, dollars) << endl;

  cout << "Gas cost for 400 miles: "<<DrivingCost(400, miles, dollars) << endl;

  return 0;

}

Explanation:

  • Create a method definition of DrivingCost that accepts  three input double data type parameters drivenMiles,  milesPerGallon, and dollarsPerGallon and returns  the dollar cost to drive those miles .
  • Calculate total dollar cost and store in the variable, dollarCost .
  • Prompt and read the miles and dollars per gallon  as input from the user .
  • Call the DrivingCost function three times  for the output to the gas cost for 10 miles,  50 miles, and 400 miles.

 

4 0
3 years ago
Read 2 more answers
Anyone can publish information on the internet without fact checking it. T or F
choli [55]
True. this is a danger in the internet.stay safe
5 0
3 years ago
Explain test-driven development and provide an example of how it can be used in your
dalvyx [7]

Answer:

 The test- driven development is basically use in the programming language for the designing various type of test cases in the computer system. The main goal of the test driven development is that it uses to make the system bug free and simple.

It basically use in the organization to avoid various duplication in the code and make the function more efficient.

The basic approach of the test driven development is that the test are develop so that it specify the function for the code to perform.

8 0
4 years ago
Other questions:
  • On a chart created in excel, the horizontal axis is also called the ____.
    15·1 answer
  • Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder)
    13·1 answer
  • A high bandwidth gives you faster what
    10·1 answer
  • Why is it a good idea to defrag your hard disk regularly?
    9·1 answer
  • John have subscribed to a cloud-based service to synchronize data between your mobile device and your PC. Before allowing the da
    14·2 answers
  • Which of the following components was a significant development featured in the Macintosh LISA computer?
    12·1 answer
  • The two roots of a quadratic equation, for example 2 + + = 0, can be obtained using the following formula: Two Roots: 1 = − + √
    14·1 answer
  • Comments should Your answer: rephrase the code it explains in English be insightful and explain what the instruction's intention
    15·1 answer
  • Digital computers use a........ system to encode date and programs.<br>​
    8·1 answer
  • Circle class
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!