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]
2 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]2 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
explain why the database system would not allow a tuple to be inserted into the database through this view
Andrej [43]
For the view of Exercise 4.18, explain why the database system would not allow a tuple to be inserted into the database through this view.
For reference
For the database of Figure 4.12, write a query to find the ID of each employee with no manager. Note that an employee may simply have no manager listed or may have a null manager. Write your query using an outer join and then write it again using no outer join at all.
OUTER JOIN
select e.ID from employee e left outer join manages m on e.ID = m.ID
where m.manager_id is null;
NO OUTER
select e.ID from employee e where e.ID not in (select m.ID from manages m) or e.ID in (select m.ID from manages m where m.manager_id is null);
6 0
2 years ago
Inputting a range of numbers comprising a batch and then inputting each serially numbered document is characteristic of the cont
Fynjy0 [20]

Answer:

batch sequence check.

Explanation:

A batch sequence check can be defined as a strategic and systematic control plan which typically involves the process of inputting a range of numbers comprising a batch and then inputting each serially numbered document.

The steps for checking an event data within a batch using a batch sequence check include the following;

I. You'll enter a range of serial numbers of the document in a batch.

II. You'll enter each serially pre-numbered document one after the other.

III. The input documents are sorted by a computer into a serial (numerical) order, match the sequence number range against the input documents, and then reports any part of the document that is missing, a duplicate and out of range.

6 0
3 years ago
Match the different sources of payments to their descriptions. an electronic device that aids consumers to make online payments
LekaFEV [45]

<u>Automatic Draft-</u> A convenient payment method where funds are automatically debited from your account.

<u>Cash-</u> The physical form of currency.

<u>Credit Card-</u> Allows you to make a purchase and pay for it later.

<u>Digital Wallet-</u> An electronic device that aids consumers to make online payments through various websites.

For anyone still looking, hope this helps.

6 0
3 years ago
Ali rolled a ball down a hill. This graph shows the kinetic and potential energy of the moving ball.
denis23 [38]
Ghhsususuhwbababahaha
8 0
1 year ago
Which command suppresses the visibility of a particular row or column in a worksheet?
Gwar [14]

Answer:

Hide command suppresses the visibility of a particular row or column in a worksheet

Explanation:

Hide command is used to hide the row or column in an excel worksheet. To suppress the visibility of a particular row or column in a worksheet, you have to select that particular row or column and then right-click on column or row header. A popup screen will appear as like when you refresh the computer. Then on this screen, at the bottom, you will find the hide command, click the hide command. And, as you click the hide command that particular row or column will become invisible. if you want to show it again, click the Unhide command. Therefore, hide command suppresses the visibility of a particular row or column.

Why other options are not correct

Autofit

Autofit command is used when you want that a particular cell of row or column to automatically adjust / or accommodate the content. Autofit command does not affect the visibility of a row or column.

Insert

Insert command is used to insert contents in a particular worksheet. Insert command is based on groups of various commands such as inserting tables, charts, graphs, text, symbols, add-ins, sparklines, and links.

Replace

Replace command is used in excel to replace the text with some other text. If you want to replace some text with some other text, then you have to use the replace command.

8 0
3 years ago
Other questions:
  • How to burn mp3 on dvd
    13·2 answers
  • Describe how you center text.
    7·2 answers
  • What are all the folders located on the DOCK called?
    11·1 answer
  • The main devices in a rectifier are:
    14·2 answers
  • Describe a time when you influenced someone else’s knowledge around technology, whether it be an app, a new gadget, etc. What di
    14·1 answer
  • You are the CISO of a company and you need to create logging policies. Please review NIST SP800-92, specifically sections 4–3 th
    12·1 answer
  • Draw the hierarchy chart and then plan the logic for a program that calculates a person’s body mass index (BMI).
    11·1 answer
  • Which activity represents a violation of the licensing agreement?
    13·2 answers
  • What is the purpose of the new window command
    6·1 answer
  • 6. kinukuha nito ang kabuuang bilang ng mga numerical na datos sa mga piniling cells
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!