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
Harrizon [31]
3 years ago
14

What order? (function templates) Define a generic function called CheckOrder() that checks if four items are in ascending, neith

er, or descending order. The function should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order. The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, strings, characters, or doubles. Ex. If the input is:
Computers and Technology
1 answer:
vlabodo [156]3 years ago
8 0

Answer:

Explanation:

The following code was written in Java and creates the generic class to allow you to compare any type of data structure. Three different test cases were used using both integers and strings. The first is an ascending list of integers, the second is a descending list of integers, and the third is an unordered list of strings. The output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Order: " + checkOrder(10, 22, 51, 53));

       System.out.println("Order: " + checkOrder(55, 44, 33, 22));

       System.out.println("Order: " + checkOrder("John", " Gabriel", "Daniela", "Zendaya"));

   }

   public static <E extends Comparable<E>> int checkOrder(E var1, E var2, E var3, E var4) {

       E prevVar = var1;

       if (var2.compareTo(prevVar) > 0) {

           prevVar = var2;

       } else {

           if (var3.compareTo(prevVar) < 0) {

               prevVar = var3;

           } else {

               return 0;

           }

           if (var4.compareTo(prevVar) < 0) {

               return 1;

           }  else {

               return 0;

           }

       }

       if (var3.compareTo(prevVar) > 0) {

           prevVar = var3;

       }

       if (var4.compareTo(prevVar) > 0) {

           return -1;

       }

       return 0;

   }

}

You might be interested in
1. Which of the following describes a way of memorizing a poem using a mnemonic device?
xenn [34]

Answer:

Singing the words of the poem to the tune of Happy Birthday"

Explanation:

Mnemonic devices are those tools which can be used to improve a persons ability to remember something efficiently. In short, it a technique to memorize something in short period of time and remember it for longer period of time.

Memorizing a poem by singing it to the tune of Happy birthday is also a technique to remember the poem and memorizing it efficiently.

3 0
3 years ago
What does UDP stand for?
sleet_krkn [62]
User Datagram Protocol
3 0
3 years ago
Read 2 more answers
A single central register of IP addresses and names (a DNS style system) is an efficient means of translating human readable nam
Harrizon [31]

Answer:

True

Explanation:

DNS stands for "Domain Name System" DNS is the system/service that is used to convert the Domain Names into IP addresses.

Whenever we write a URL to go to a web page in our browser for example Brainly(dot)com, the request first goes to a server which converts the named URL(Brainly(dot)com) into actual IP address. This actual IP address is then used to reach to the web files, as response to the URL search. This system is made to ease out the searches made by the users.

Therefore, the given statement is True.

8 0
3 years ago
Jonah disagrees with the opinion expressed in the post he just read. What should he do?
raketka [301]

Answer:

Respond to the post by acknowledging the person’s argument and explaining why he disagrees.

Explanation:

i just did it on edg and got it correct... hope this helps! :)

5 0
3 years ago
Read 2 more answers
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
snow_tiger [21]

Answer:

The program implemented in C++ is as follows:

#include <iostream>

#include <vector>

using namespace std;

int main(){

int lenlist;

vector<int> mylist;

cout<<"Length List: ";

cin>>lenlist;

mylist.push_back(lenlist);

int i =0; int num;

while(i<lenlist){

   cin>>num;

   mylist.push_back(num);  

   i++;

}

int min,max;

cout<<"Min: ";  cin>>min;

cout<<"Max: ";  cin>>max;

cout<<"Output!"<<endl;

for(int i=1; i < mylist.size(); i++){

  if(mylist.at(i)>=min && mylist.at(i)<=max){

      cout<<mylist.at(i)<<" ";

  }

}

  return 0;

}

Explanation:

This declares the length of the list as integer

int lenlist;

This declares an integer vector

vector<int> mylist;

This prompts user for length of the list

cout<<"Length List: ";

This gets input of length of the list from the user

cin>>lenlist;

This pushes user input to the vector

mylist.push_back(lenlist);

int i =0; int num;

The following iteration gets user inputs and pushes them into the vector

<em>while(i<lenlist){ </em>

<em>    cin>>num; </em>

<em>    mylist.push_back(num);  </em>

<em>    i++; </em>

<em>} </em>

This declares min and max variables

int min,max;

This prompts user for the lower bound

cout<<"Min: ";  cin>>min;

This prompts user for the upper bound

cout<<"Max: ";  cin>>max;

The following iteration checks for numbers within the lower and upper bound and print the numbers in that range

<em>cout<<"Output!"<<endl; </em>

<em>for(int i=1; i < mylist.size(); i++){ </em>

<em>   if(mylist.at(i)>=min && mylist.at(i)<=max){ </em>

<em>       cout<<mylist.at(i)<<" "; </em>

<em>   } </em>

<em>} </em>

3 0
3 years ago
Other questions:
  • ________ is the information about a file.
    7·1 answer
  • A company wishes to move all of its services and applications to a cloud provider but wants to maintain full control of the depl
    7·1 answer
  • [Submit on zyLabs] Please write a function with one input, a matrix, and one output, a matrix of the same size. The output matri
    10·1 answer
  • You should not define a class field that is dependent upon the values of other class fields: Group of answer choices In order to
    14·1 answer
  • What is the least number of options you should come up with to help you solve a problem?
    15·1 answer
  • You are given a 11-bit floating point representation with 1-sign bit, 3 bits for the exponent, and 7-bits for the mantissa. Expr
    9·1 answer
  • How to make a website
    15·2 answers
  • What does the computer receive when you press a key on a laptop keyboard?
    8·1 answer
  • Yahoo Messenger is an example of a/an __________ service on the Internet.
    5·2 answers
  • Q5: what is the difference between a spreadsheet and a relational database? when would you have to use a relational database ins
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!