Question

(C++) Topic: Please write a function Order (int *largest, int *medium, int*smallest). The function of this...

(C++) Topic: Please write a function Order (int *largest, int *medium, int*smallest). The function of this function is to rearrange the value of the whole index pointed to by the three indicators, that is, how to set the indicator that is passed in. If the function ends, it must be largest to point to the largest value, smallest to the smallest value, medium to point to The value in the middle. For example, consider the following main(). The order of its output should be 300, 200, 100.
Int main(){
 Int a, b, c;
 a = 100;
 b = 200;
 c = 300;
 Order(&a, &b, &c);
 Cout << a << "," << b << "," << c << endl;
}
Claim:
1. This assignment must not use global changes.
2. The results submitted must be complete and executable. That is, you must have the appropriate main() function. Order( ) must be called in the main() function to display its functionality.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
#include<fstream>

using namespace std;

void Order(int *largest, int *medium, int *smallest)
{
   int a, b, c;
   a = *largest;
   b = *medium;
   c = *smallest;
   if(a > b && a > c)//a is largest
   {
      *largest = a;
      if(b > c)//b is medium and c is smallest
      {
         *medium = b;
         *smallest = c;
      }
      else
      {
         *medium = c;
         *smallest = b;
      }
   }
   else
   if(b > a && b > c)//b is largest
   {
      *largest = b;
      if(a > c)//a is medium and c is smallest
      {
         *medium = a;
         *smallest = c;
      }
      else
      {
         *medium = c;
         *smallest = a;
      }
   }
   else//c is largest
   {
      *largest = c;
      if(a > b)//a is medium and b is smallest
      {
         *medium = a;
         *smallest = b;
      }
      else
      {
         *medium = b;
         *smallest = a;
      }
   }
}

int main() 
{
   int a, b, c;
   a = 100;
   b = 200;
   c = 300;
   Order(&a, &b, &c);
   cout << a << "," << b << "," << c << endl;
}

OUTPUT:
CAUsers Shubham\Desktop\ Main.exe 300,200,100 Process exited after 0.2008 seconds with return value e Press any key to contin

(Feel free to reach me out in comments for any help)

Add a comment
Know the answer?
Add Answer to:
(C++) Topic: Please write a function Order (int *largest, int *medium, int*smallest). The function of this...
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 generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the...

    Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{    int x,y;    bool operator<(const Point& p) {        return (x<p.x || (x==p.x&&y<p.y));    } }; int...

  • Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel –...

    Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...

  • Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array...

    Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array and // its size and returns the index of the first occurrence of the largest element II in the array. Also, write a function to display the array #include ·peh.h" #include <iostream> using namespace std const int ARRAY_SIZE = 15; int main int list[ARRAY SIZE56, 34, 67, 54, 23, 87, 66, 92. 15, 32, 5, 54, 88, 92, 30 cout < List elements: "...

  • Use the functions below to write a C++ program to find the smallest Fibonacci number greater...

    Use the functions below to write a C++ program to find the smallest Fibonacci number greater than 1,000,000 and greater than 1,000,000,000. #include <iostream> using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return...

  • I need help fixing my code: In C++ *************** 1) I want to sum the digits...

    I need help fixing my code: In C++ *************** 1) I want to sum the digits of an n*n matrix 2) find the average I have completed the rest ****Do not use C++ standard library. You must use pointers and pointer arithmetic to represent the matrix and to navigate through it. MY CODE: (I have indicated at which point I need help) #include <iostream> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp;...

  • using C++ only. The findFirstZero function is supposed to find the first element in an array...

    using C++ only. The findFirstZero function is supposed to find the first element in an array whose value is zero, and sets the parameter  p to point to that element, so the caller can know the location of that element holding the value zero. Explain why this function won't do that, and show how to fix it. Your fix must be to the function only; you must not change the  main routine below in any way. As a result of your fixing...

  • c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc...

    c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc b. Job: The function will modify line such that every occurrence of c is replaced by a "*". It will also return the count of c in line. The main() function is provided. You only need to implement the function Processline. #include <iostream> #include <string> using namespace std; int main() char line 200), c; int Count; { cout<<"Enter some text: "; cin.get(line, 200); cout<<"Enter...

  • Use only C++ for all function Introduce a call-by-value function that computes the volume of a...

    Use only C++ for all function Introduce a call-by-value function that computes the volume of a box. Hint: Length, width, and height of a box is needed. Introduce a call-by-reference function with void output. that computes the square of an integer. Please double check the value of the function input before and after function call. Introduce a call-by-pointer function with void output. that computes the square of an integer. Please double check the value of the function input before and...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

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