NOTES:
-In order to use the string functionality described In the link and below, you need to add to the top of your program the include directive for the string type:
#include <string>
-You can compare strings using the typical operators (<, ==, >, etc.). The comparison is alphabetical. Therefore strings further down in the alphabetical order are considered "greater". That is, a string like "Hello there" is greater than "All is well" because in comparing one character at a time, 'H' comes later than 'A' in the alphabetical order.
-You can use the input operator >> to load strings into string variables, but if the string you type contains spaces, it will not be fully loaded. In order to read (input) the full string, use: getline(cin, str); where cin is, as usual, the name for the input stream from the keyboard and str is the name of the string variable which will store the string you typed. Of course, that variable can have any name you want, not necessarily str.
C++ Program
Write a program that stores three unsorted strings entered from the keyboard into three string variables a, b and c. After loading the variables, your program will sort the values in alphabetical order, that is, store into a the smallest string, in b the middle one and in c the largest. Careful: largest does not mean the string is longer, but rather that if we have two strings a and b, a is "larger" than b if a > b is true.
Display the sorted strings in three lines.
In the context of strings, a string is larger if it comes later in the typical alphabetical order.
You can use any other variables in addition to a, b, c, as you see fit.
You will have to use some variation(s) of the if construct.
There are many ways to program this, but your challenge will be to achieve this without doing all possible comparisons. In fact, three simple comparisons should be enough, if you, for example, determine the first string first, and keep track of its value in some way, so you can compare the other two, and then swap their values.
Swapping the contents of two variables can be achieved by using a temporary variable.
For instance:
temp = a;
a = b;
b = temp; would exchange the values of a and b, using a temp as a temporary intermediate storage,