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
Sedaia [141]
3 years ago
14

Write a C++ program to find if a given array of integers is sorted in a descending order. The program should print "SORTED" if t

he array is sorted in a descending order and "UNSORTED" otherwise. Keep in mind that the program should print "SORTED" or "UNSORTED" only once.
Computers and Technology
1 answer:
LenKa [72]3 years ago
4 0

Answer:

The cpp program for the given scenario is as follows.

#include <iostream>

#include <iterator>

using namespace std;

int main()

{

   //boolean variable declared and initialized  

   bool sorted=true;

   //integer array declared and initialized

   int arr[] = {1, 2, 3, 4, 5};

   //integer variables declared and initialized to length of the array, arr

   int len = std::end(arr) - std::begin(arr);

       //array tested for being sorted

    for(int idx=0; idx<len-1; idx++)

    {

        if(arr[idx] < arr[idx+1])

           {

               sorted=false;

            break;

           }

    }

    //message displayed  

    if(sorted == false)

     cout<< "UNSORTED" <<endl;

 else

    cout<< "UNSORTED" <<endl;

return 0;

}

OUTPUT

UNSORTED

Explanation:

1. An integer array, arr, is declared and initialized as shown.

int arr[] = {1, 2, 3, 4, 5};

2. An integer variable, len, is declared and initialized to the size of the array created above.

int len = std::end(arr) - std::begin(arr);

3. A Boolean variable, sorted, is declared and initialized to true.

bool sorted=true;  

4. All the variables and array are declared inside main().

5. Inside for loop, the array, arr, is tested for being sorted or unsorted.  The for loop executes over an integer variable, idx, which ranges from 0 till the length of the array, arr.

6. The array is assumed to be sorted if all the elements of the array are in descending order.

7. If the elements of the array are in ascending order, the Boolean variable, sorted, is assigned the value false and for loop is exited using break keyword. The testing is done using if statement.

8. Based on the value of the Boolean variable, sorted, a message is displayed to the user.

9. The program can be tested for any size of the array and for any order of the elements, ascending or descending. The program can also be tested for array of other numeric data type including float and double.

10. All the code is written inside the main().

11. The length of the array is found using begin() and end() methods as shown previously. For this, the iterator header file is included in the program.

You might be interested in
In 3 to 5 sentences, describe whether or not files should be deleted from your computer. Explain you answer.
daser333 [38]
I mean if your trying to delete like important files I dont think they should be deleted but that is My opinion. But if you do delete them then u could always got to the recycle bin in ur computer to get it back. I hope this helps !!
7 0
3 years ago
Read 2 more answers
What is hub.pls ans from pic. for computers​
schepotkina [342]

<h3>what is hub? </h3>

<h3>✅An Ethernet hub, active hub, network hub, repeater hub, multiport repeater, or simply hub is a network hardware device for connecting multiple Ethernet devices together and making them act as a single network segment.</h3>
5 0
3 years ago
Read 2 more answers
Tinh T = a1*a2*a3*...an<br><br> Giúp em với
Studentka2010 [4]

Answer:

??????

Explanation:

??????? okay okay

3 0
3 years ago
You will need to convert the following binary numbers to hexadecimal. Table 1 contains 16 problems. The first one is completed f
pantera1 [17]

Answer:

where is the table pls.........???..????

5 0
2 years ago
A company currently uses Microsoft Active Directory as its identity provider. The company recently purchased Oracle Cloud Infras
I am Lyosha [343]

A company currently uses Microsoft Active Directory as its identity provider. The company recently purchased Oracle Cloud Infrastructure (OCI) to leverage the cloud platform for its test and development operations. As the administrator, you are now tasked with giving access only to developers so that they can start creating resources in their OCI accounts. The step to achieve this is :

<u>B. Federate all Microsoft Active Directory groups with OCI to allow users to use their existing credentials.</u>

<u />

Explanation:

  • Go to the AD FS Management Console and sign in to the account you want to federate.
  • Add Oracle Cloud Infrastructure as a trusted relying party: From the AD FS Management Console, right-click AD FS and select Add Relying Party Trust.
  • Oracle Cloud provides Infrastructure as a Service (IaaS), Platform as a Service (PaaS), Software as a Service (SaaS), and Data as a Service (DaaS). These services are used to build, deploy, integrate, and extend applications in the cloud.
  • You can federate multiple Active Directory accounts with Oracle Cloud Infrastructure, but each federation trust that you set up must be for a single Active Directory account.

4 0
3 years ago
Other questions:
  • If you plan on operating several applications at s time, the amount of RAM should be considered when purchasing a computer
    10·2 answers
  • What privacy issues have arisen with webcams in mobile devices?
    8·1 answer
  • Given the three side lengths, how can you tell if a triangle<br>is a right triangle?​
    5·1 answer
  • Referential integrity states that:______.
    15·1 answer
  • What disese is sue suffering from
    15·2 answers
  • For a business that is properly using a social media information system, the system can
    13·1 answer
  • Why would an end-user not generally buy a server? Explain your answer by referring to the typical role that servers perform. ​
    12·1 answer
  • I NEED HELP, DO ASAP <br> Why do you have to adjust toys for different ages?
    11·2 answers
  • Need help with this, will give brainliest
    15·1 answer
  • Below you will find the requirements to identify the Account Diversity Grade of a user. Read the requirements carefully and iden
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!