Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following functions: a. bool all_the_same(int x, int y, int z), return

ID: 3552029 • Letter: W

Question

Write the following functions:

a. bool all_the_same(int x, int y, int z), returning true only if the arguments are all the same.

b. bool all_different(int x, int y, int z), returning true only if the arguments are all different.

c. bool sorted(int x, int y, int z), returning true only if the arguments are sorted, with the smallest

one coming first.

Provide a program that tests all three of your functions via a loop construct for acquiring testing data.

Example run (with user input indicated with bold italics):

Enter three numbers or Q to quit: 2 1 3

Numbers are not all the same.

Numbers are all different.

Numbers are not sorted.

Enter three numbers or Q to quit: 4 4 4

Numbers are all the same.

Numbers are not all different.

Numbers are sorted.

Enter three numbers or Q to quit: Q

Explanation / Answer


Program:


#include <iostream>


using namespace std;


bool all_the_same(int x, int y, int z);

bool all_different(int x, int y, int z);

bool sorted(int x, int y, int z);


int main()

{

int a, b, c;

  

  

do

{

  

cout << " Enter three numbers or Q to quit: ";

cin >> a >> b >> c;

  

  

  

if (all_the_same(a,b,c))

  

cout << " Numbers are all the same";

else

cout << " Numbers are not all the same";

  

  

if (all_different(a,b,c))

{

cout << " Numbers are different";

}

else

{

cout << " Numbers are not different";

}

  

if ( sorted(a,b,c))

{

cout << " Numbers are sorted";

  

}

else

{

cout << " Numbers are not sorted";

}

}while (a != 'Q' || a != 'q');

  

return 0;

}


bool all_the_same(int x, int y, int z)

{

return ((x = y = z));

}


bool all_different(int x, int y, int z)

{

return (x != y && x != z && y != z);

}


bool sorted (int x, int y, int z)

{

return ( x < y && y < z);

}