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
tamaranim1 [39]
3 years ago
13

#include

Computers and Technology
1 answer:
rodikova [14]3 years ago
7 0

Output

SORTED                                                                                                                                

4 7 10 69                                                                                                                              

                                                                                                                                     

SORTED                                                                                                                                

10 9 7 3                                                                                                                              

                                                                                                                                     

NOT SORTED                                                                                                                            

19 12 23 7                                                                                                                            

                                                                                                                                     

SORTED                                                                                                                                

5 5 5 5

Code

//The added part is in the bottom

#include <iostream>

using namespace std;

const int SIZE = 4;

bool isSorted (const int arr[], int size);

bool isNonDecreasing (const int arr[], int size);

bool isNonIncreasing (const int arr[], int size);

void printArr (const int arr[], int size);

int

main ()

{

 int test1[] = { 4, 7, 10, 69 };

 int test2[] = { 10, 9, 7, 3 };

 int test3[] = { 19, 12, 23, 7 };

 int test4[] = { 5, 5, 5, 5 };

 if (!isSorted (test1, SIZE))

   cout << "NOT ";

 cout << "SORTED" << endl;

 printArr (test1, SIZE);

 if (!isSorted (test2, SIZE))

   cout << "NOT ";

 cout << "SORTED" << endl;

 printArr (test2, SIZE);

 if (!isSorted (test3, SIZE))

   cout << "NOT ";

 cout << "SORTED" << endl;

 printArr (test3, SIZE);

 if (!isSorted (test4, SIZE))

   cout << "NOT ";

 cout << "SORTED" << endl;

 printArr (test4, SIZE);

 return 0;

}

bool

isSorted (const int arr[], int size)

{

//Added part

 if (isNonDecreasing (arr, size) || isNonIncreasing (arr, size))

   {

     return true;

   }

 else

   {

     return false;

   }

}

bool

isNonDecreasing (const int arr[], int size)

{

 for (int i = 0; i < (size - 1); i++)

   {

     if (arr[i] > arr[i + 1]) //It compares the n value with the n-1 value and output

{

  return false;

  break;

}

   }

 return true;

}

bool

isNonIncreasing (const int arr[], int size)

{

 for (int i = 0; i < (size - 1); i++)

   {

     if (arr[i] < arr[i + 1]) //It compares the n value with the n-1 value and output reautilization of previous function by replacing only “<”

{

  return false;

  break;

}

   }

 return true;

}

void

printArr (const int arr[], int size)

{

 for (int i = 0; i < size; i++)

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

 cout << endl << endl;

}

You might be interested in
How many megapixels is in a macbook air 2017 camera
Anastasy [175]

Answer:

.7

Explanation:

3 0
3 years ago
What is the job of a bootloader?
VladimirAG [237]

Answer:

A bootloader, also known as a boot program or bootstrap loader, is a special operating system software that loads into the working memory of a computer after start-up.

Explanation:

6 0
3 years ago
Read 2 more answers
Help!!!
Butoxors [25]

Answer:

ummmm try the inequality protragathron theorum

Explanation:

ok

3 0
3 years ago
An alarm clock draws 0.5 A of current when connected to a 120 volt circuit. Calculate its resistance.
mixas84 [53]

Answer:

120 vpm

Explanation:

8 0
3 years ago
12. Which one of the following items would you be most likely to keep in a database?
AysviL [449]
The item that would be most likely to keep in a database would be the payroll records. The other items such as address book, financial statements and sales reports would not necessarily be placed in a database.

The answer would be letter A. 
3 0
3 years ago
Other questions:
  • What concerns do you need to have with individuals hacking your information, computer, personal devices, and car? How can you pr
    5·1 answer
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • _______________________ is a short-term program, typically 30 hours long, in which a therapist, social worker, or trained probat
    5·1 answer
  • Why does my Office Computer send packet #1? What device responds by sending back packet #2? What information does my Office Comp
    15·1 answer
  • Drugs of addiction act upon a portion of the Brain called the lambic system ? True or false.
    7·1 answer
  • Choose the risks from the options below to presenting yourself differently online than offline?
    12·1 answer
  • What is a major way that a consumer can protect himself/herself when getting a credit card? A) Making sure that they get a very
    8·1 answer
  • What kind of printers tend to have problems with ink drying out inside the nozzles when the printer is not used for a period?
    15·1 answer
  • How does recorded audio stay on an audio tape
    12·1 answer
  • A good information that contains the facts necessary for decision makers to solve a problem is characterized by the __________.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!