Respuesta :

Answer: The c++ program to implement order() method is given below.

#include <iostream>

using namespace std;

void order(int a, int b, int c);

int main() {

   int x, y, z;

   cout<<"This program displays numbers in descending order."<<endl;

   do

   {

       cout<<"Enter first number"<<endl;

       cin>>x;

       if(x<0)

           cout<<"Invalid input. Enter a positive number."<<endl;

   }while(x<0);

   do

   {

       cout<<"Enter second number"<<endl;

       cin>>y;

       if(y<0)

           cout<<"Invalid input. Enter a positive number."<<endl;

   }while(y<0);

   do

   {

       cout<<"Enter third number"<<endl;

       cin>>z;

       if(z<0)

           cout<<"Invalid input. Enter a positive number."<<endl;

   }while(z<0);

   order(x, y, z);

   return 0;

}

void order(int a, int b, int c)

{

   if((a>b)&&(a>c))

   {  

       cout<<"Numbers in decreasing order are"<<endl;

       cout<<a<<endl;

           if(b>c)

           {

               cout<<b<<endl;        

               cout<<c<<endl;

           }

           else

           {

               cout<<c<<endl;

               cout<<b<<endl;

           }

   }    

   if((b>a)&&(b>c))

   {  

       cout<<"Numbers in decresing order are"<<endl;

       cout<<b<<endl;

           if(a>c)

           {

               cout<<a<<endl;        

               cout<<c<<endl;

           }

           else

           {

               cout<<c<<endl;

               cout<<a<<endl;

           }

   }    

   if((c>b)&&(c>a))

   {  

       cout<<"Numbers in decreasing order are"<<endl;

       cout<<c<<endl;

           if(a>b)

           {

               cout<<a<<endl;        

               cout<<b<<endl;

           }

           else

           {

               cout<<b<<endl;

               cout<<a<<endl;

           }

   }

       

}

OUTPUT

This program displays numbers in descending order.

Enter first number

12

Enter second number

-9

Invalid input. Enter a positive number.

Enter second number

0

Enter third number

55

Numbers in decreasing order are

55

12

0

Explanation:

The method order() is declared as follows.

void order(int a, int b, int c);

The method is declared void since it does not return any value.

This program is designed to accept 0 and positive integers only. This is implemented by do-while loop while taking user input.

The program uses 3 integer variables to store the user input.

int x, y, z;

The method order() is designed to accept 3 integer parameters. This method is called once user enters valid input.

order(x, y, z);

These numbers are compared in order to display them in descending order.

No variable is used for comparison. The method simply compares the numbers and displays them using multiple if-else statements.