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
DENIUS [597]
2 years ago
14

How to write a C++ program that allows a user to enter their rating of the three movies in the Dark Knight Trilogy and then disp

lay each rating entered, the highest rating, the lowest rating, and the average of the ratings??
Computers and Technology
1 answer:
8_murik_8 [283]2 years ago
8 0

The program is an illustration of arrays.

Arrays are used to hold multiple values in one variable.

The program in C++ where comments are used to explain each line is as follows:

#include <iostream>

using namespace std;

int main(){

   //This declares an array of three elements for the three ratings

   int ratings[3];

   //This initializes the sum of the ratings to 0

   int total = 0;

   //The following iteration gets input for the three ratings

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

       cin>>ratings[i];

       //This calculates the sum of all inputs

       total+=ratings[i];

   }

   //This declares and initializes the lowest and the highest ratings

   int lowest = ratings[0], highest = ratings[0];

   //This iterates through the array

   for(int i = 1; i<3;i++){

       //The following if condition determines the lowest rating

       if (lowest > ratings[i]){    lowest = ratings[i];        }

       //The following if condition determines the highest rating

       if (highest < ratings[i]){            highest = ratings[i];        }

   }

   //This prints the output header

   cout<<"The ratings are: ";

   //The following iteration prints the three ratings

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

       cout<<ratings[i]<<" ";   }

   //The prints the highest ratings

cout<<endl<<"Highest: "<<highest<<endl;

   //The prints the lowest rating

   cout<<"Lowest: "<<lowest<<endl;

   //The prints the average rating

cout<<"Average: "<<total/3<<endl;

   return 0;

}

At the end of the program, the ratings entered, the highest rating, the lowest rating, and the average of the ratings are printed.

See attachment for sample run

Read more about similar programs at:

brainly.com/question/13261254

You might be interested in
Type (dog, cat, budgie, lizard, horse, etc.) Create a class that keeps track of the attributes above for pet records at the anim
Alenkinab [10]

Answer:

If you did the exercise with two Dog objects, it was a bit boring, right? After all, we have nothing to separate the dogs from each other and no way of knowing, without looking at the source code, which dog produced which bark.

In the previous article, I mentioned that when you create objects, you call a special method called a constructor. The constructor looks like the class name written as a method. For example, for a Dog class, the constructor would be called Dog().

The special thing about constructors is that they are the path to any new object, so they are a great place to call code that initializes an object with default values. Further, the return value from a constructor method is always an object of the class itself, which is why we can assign the return value of the constructor to a variable of the type of class we create.

However, so far, we have not actually created a constructor at all, so how come we can still call that method?

In many languages, C# included, the language gives you a free and empty constructor without you having to do anything. It is implied that you want a constructor; otherwise there would be no way of using the class for anything, so the languages just assume that you have written one.

This invisible and free constructor is called the default constructor, and, in our example, it will look like this:

public Dog(){ }

Notice that this syntax is very similar to the Speak() method we created earlier, except that we do not explicitly return a value nor do we even declare the return type of the method. As I mentioned earlier, a constructor always returns an instance of the class to which it belongs.

In this case, that is the class Dog, and that is why when we write Dog myDog = new Dog(), we can assign the new object to a variable named myDog which is of type Dog.

So let’s add the default constructor to our Dog class. You can either copy the line above or, in Visual Studio, you can use a shortcut: type ctor and hit Tab twice. It should generate the default constructor for you.

The default constructor doesn’t actually give us anything new because it is now explicitly doing what was done implicitly before. However, it is a method, so we can now add content inside the brackets that will execute whenever we call this constructor. And because the constructor runs as the very first thing in an object’s construction, it is a perfect place to add initialization code.

For example, we could set the Name property of our objects to something by adding code such as this:

public Dog()

{

   this.Name = "Snoopy";

}

This example will set the Name property of any new objects to “Snoopy”.

Of course, that’s not very useful because not all dogs are called “Snoopy”, so instead, let us change the method signature of the constructor so that it accepts a parameter.

The parentheses of methods aren’t just there to look pretty; they serve to contain parameters that we can use to pass values to a method. This function applies to all methods, not just constructors, but let’s do it for a constructor first.

Change the default constructor signature to this:

public Dog(string dogName)

This addition allows us to send a string parameter into the constructor, and that when we do, we can refer to that parameter by the name dogName.

Then, add the following line to the method block:

this.Name = dogName;

This line sets this object’s property Name to the parameter we sent into the constructor.

Note that when you change the constructor’s signature, you get a case of the red squigglies in your Program.cs file.When we add our own explicit constructors, C# and .NET will not implicitly create a default constructor for us. In our Program.cs file, we are still creating the Dog objects using the default parameter-less constructor, which now no longer exists.

To fix this problem, we need to add a parameter to our constructor call in Program.cs. We can, for example, update our object construction line as such:

Dog myDog = new Dog(“Snoopy”);

Doing so will remove the red squigglies and allow you to run the code again. If you leave or set your breakpoint after the last code line, you can look at the Locals panel and verify that your object’s Name property has indeed been? Got it?

5 0
2 years ago
A network administrator wants to change the frequency of their wireless network to allow more channels that do not interfere wit
MA_775_DIABLO [31]

Answer:

2.4GHz

Explanation:

In the 2.4 GHz band, 1, 6, and 11 are the only non-overlapping channels

8 0
3 years ago
Where should you look in order to find words as they are used in a variety of contexts?
Elodia [21]
You'd want to look at the <span>glossary.</span>
8 0
2 years ago
What language(s) must be used to display a bare-minimum web page?
Reil [10]

Answer: Hyper Text Markup Language (HTML)

Explanation:  

Computers use language to communicate, just like people do and the way that computers communicate with the internet is through a language that is called Hyper Text Markup Language/ HTML

Hyper Text is the process of linking objects to each other, so that when one object is clicked the linking object can be viewed. Hyper Text Markup Language was created by Tim burners in 1990


8 0
3 years ago
Read 2 more answers
True or False? To reduce hazards, flexible cords must connect to devices and fittings in ways that prevent tension at joints and
anastassius [24]
<span>It can be true and is really necessary for this type of things when fittings in ways that prevent tension at joints and terminal screws. So, Flexible cords are finely stranded for flexibility, so straining a cord can cause the strands of one conductor to loosen from under the many joints.</span>
5 0
3 years ago
Other questions:
  • Ad designers use movement in order to
    9·2 answers
  • CHALLENGE ACTIVITY |
    12·1 answer
  • Which one of the following is true about employer responsibility in providing fall protection to workers? not selected A. Employ
    15·2 answers
  • How do you interpret field in contest of a DBMS?
    5·1 answer
  • Technician a says that the above illustration shows one method used to keep the chain tension tight in an indirect drive camshaf
    8·2 answers
  • On Microsoft teams, how do teachers know that you are on a different page?
    10·2 answers
  • The association between a UCS and a CS can be extended to include more stimuli (more stimuli related to the CS can elicit the CR
    7·1 answer
  • Write a C# program named DoubleDecimalTest thatdeclares and displays two variables - a double and a decimal.Experiment by assign
    9·1 answer
  • What is the first thing you should do when you discover a computer is infected with malware? The second thing?
    7·1 answer
  • Your supervisor has asked you if it is possible to monitor servers for potential port scans via SNMP. What two OIDs can you prov
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!