Question

In: Computer Science

write a C++ program that uses function swap to enter three real value from the keyboard...

write a C++ program that uses function swap to enter three real value from the keyboard and outputs there in order from minimum to the maximum. For example 10,100,30 if were entered then the output would be 10,30,100. The program should use function get_data(a,b,c) and print_data(a,b,c)

Solutions

Expert Solution

ANS:

#include <string>
#include <iostream>

using namespace std;

void print_data(int a, int b, int c) {
        
        if(a < b && a < c) {
                
                cout << a << ",";
                
                if(b < c) {
                        cout << b << ",";
                        cout << c << endl;
                }
                else if(c < b) {
                        cout << c << ",";
                        cout << b << endl;
                }
        }
        else if(b < a && b < c) {
                cout << b << ",";
                
                if(a < c) {
                        cout << a << ",";
                        cout << c << endl;
                }
                else if(c < a) {
                        cout << c << ",";
                        cout << b << endl;
                }
        }
        else if(c < a && c < b) {
                
                cout << c << ",";
                
                if(a < b) {
                        cout << a << ",";
                        cout << b << endl;
                }
                else if(b < a) {
                        cout << b << ",";
                        cout << a << endl;
                }
        }
}

void get_data(int a, int b, int c) {
        
        cout << "Enter a: ";
        cin >> a;
        cout << endl << "Enter b: ";
        cin >> b;
        cout << endl << "Enter c: ";
        cin >> c;
        
        cout << endl;
        print_data(a, b, c);
}

int main() {
        
        int a1, b2, c2;
        
        get_data(a1, b2, c2);
}

  

Comment down for any queries
Please give a thumbs up if you are satisfied with answer :)


Related Solutions

write a C++ program that uses function swap (a,b) to enter two real numbers from the...
write a C++ program that uses function swap (a,b) to enter two real numbers from the keyboard and uses function min_max(a,b) to return a to be the smaller of the two numbers entered always.
Write an interactive C program that asks a user to enter a sentence from the keyboard,...
Write an interactive C program that asks a user to enter a sentence from the keyboard, and prints the sentence with all the words spelled backwards. Note: you may assume that each sentence will have at most 50 characters and each word is separated by a space. Sample code execution: bold information entered by user enter a sentence: hello ece 175 class olleh ece 571 ssalc continue (q to quit)? y enter a sentence: May the force be with you...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
Write a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
Write a program that reads three double numbers from the keyboard representing, respectively, the three coefficients...
Write a program that reads three double numbers from the keyboard representing, respectively, the three coefficients a, b, and c of a quadratic equation. Solve the equation using the following formulas: x1 = ( - b + square root (b2 – 4ac)) / (2a), x2 = ( - b + square root (b2 – 4ac)) / (2a) Run your program on the following sample values: a=1.0, b=3.0,c=2.0 a=0.5, b=0.5,c=0.125 a=1.0, b=3.0,c=10.0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT