Question

Write a program that consists of a main method and a isInOrder method. main should read...

 Write a program that consists of a main method and a isInOrder 
   method.  main should read in two integers from the keyboard
   and then call isInOrder, passing it the two integers.  isInOrder
   should return true if the first parameter is less than 
   or equal to the second paramenter.  Otherwise, it should 
   return false.  On return to main, main should test the value
   returned.  If it is true, it should display "in order".  
   Othewise,  it should display "not in order".
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>

using namespace std;

bool isInOrder( int n1,int n2) //bool datatype to return true or false
{
if (n1 <= n2) return true;
else return false;
}

int main()
{
int num1,num2;
   cout << "Enter two integers: " ;
   cin >> num1 >> num2; //store 2 integers
  
   if(isInOrder (num1,num2)) //pass them as parameter, check if it returns true
   cout << "In Order" << endl ;
   else
   cout << "Not In Order" << endl ;
}

The various test cases I used:

OUTPUT 1:

Enter two integers: 2 4
In Order

OUTPUT 2:

Enter two integers: 4 4
In Order

OUTPUT 3:

Enter two integers: 4 2
Not In Order



Add a comment
Know the answer?
Add Answer to:
Write a program that consists of a main method and a isInOrder method. main should read...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that at least consists of the main() function and a recursive...

    Write a complete C++ program that at least consists of the main() function and a recursive function gcd() with return value. Define function gcd() with two and only two parameters that calculates the greatest common divider of two given parameters. Hint: use the difference between two parameters or the remainder obtained using one parameter divide the other. In main() Read 2 positive integers with proper prompt. Call gcd() with proper syntax. Display the result, i.e. the greatest common divider of...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • 2) Write a complete program in which main creates two Integer arrayLists and then adds 1,...

    2) Write a complete program in which main creates two Integer arrayLists and then adds 1, 2, , 10 to the first ArrayList, and 21, 22, ^, 30 to the second ArrayList. main should call a method passing it the two ArrayLists. This method should create and return a third ArrayList, each slot of which contains the sum of the values in the corresponding slots of the first and second ArrayLists. On return to main, main should display the values...

  • Write a Java program that has the following methods: findSum - a method that takes in...

    Write a Java program that has the following methods: findSum - a method that takes in three integers and returns the sum of these three integers; findAverage - a method that takes in three integers and returns the average of these three integers (as a double value) Within the main method read in 3 integers from the user and call above two methods by passing the three integers. Your program should print the user provided three integers and results of...

  • In java, write method, shuffle, which accepts an array of int, creates a copy of the...

    In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the...

    Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the program just the two functions for my C++ program. I wanted to post the sample code from my class but it won't allow me it's too long. This calculate shall have the following five functionalities: Provide sign extension for a binary number Provide two’s complement for a binary nunber string signed_extension(string b);              // precondition: s is a string that...

  • Please help :) Problem 1: Complete separately Dr. Rocklino a) Write a program in which the...

    Please help :) Problem 1: Complete separately Dr. Rocklino a) Write a program in which the main method creates two arrays, each with 10 int slots. main initializes the first array to randomly generated integers. It then calls a method named copy, passing it the two arrays. Your copy method copies the contents of the first array to the second array. It then returns to main. main then displays the contents of both arrays. b) Write a program in which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT