Question

In: Computer Science

Your textbook mentions that relational operators can be used to compare letters and words, thanks to...

Your textbook mentions that relational operators can be used to compare letters and words, thanks to ASCII. This simple program will ask the user to enter two letters and then two words to see if we can really "sort" these entries alphabetically with relational operators.

Prompts:

This is a Letter and Word sorting program
Enter two different letters separated by a space: [assume user inputs: b a]

Enter two different words separated by a space: [assume user inputs: bob alex]

Output:

a goes before b
alex goes before bob

Notes and Hints:

1) Do NOT convert the user's entry to uppercase. Some of the test cases will be comparing lowercase to uppercase letters (the results are interesting!)

2) Don't worry about the possibility of the user entering the same letters/words or entering something else. Keep this program simple.

// VARIABLES
  

// INITIAL INPUT
cout << "This is a Letter and Word sorting program" << endl;
cout << "Enter two different letters separated by a space: ";
  
cout <<endl; // For Mimir
cout << "Enter two different words separated by a space: ";
  
cout << endl; // For Mimir

//Processing// LETTER ANALYSIS
// The < means letter1 is alphabetically before letter2
cout << letter1 << " goes before " << letter2 <<endl;
  
cout << letter2 << " goes before " << letter1 << endl;

// WORD ANALYSIS
// The < means word1 is alphabetically before word2
cout << word1 << " goes before " << word2 << endl;
cout << word2 << " goes before " << word1 << endl;

Solutions

Expert Solution

Please find your solution below and do upvote if any doubt or need change comment.

CODE:

#include <iostream>
using namespace std;

int main()
{
    // VARIABLES
    char letter1,letter2;
    string word1,word2;
    
    // INITIAL INPUT
    cout<<"This is a Letter and Word sorting program"<<endl;
    cout<<"Enter two different letters separated by a space:";
    cin>>letter1>>letter2;
    cout <<endl; // For Mimir
    
    cout<<"Enter two different words separated by a space:";
    cin>>word1>>word2;
    cout << endl; // For Mimir
    
    //Processing// LETTER ANALYSIS
    // The < means letter1 is alphabetically before letter2
    if(letter1<letter2)
    {
        cout << letter1 << " goes before " << letter2 <<endl;
    }
    else
    {
        cout << letter2 << " goes before " << letter1 << endl;
    }
    
    // WORD ANALYSIS
    // The < means word1 is alphabetically before word2
    if(word1<word2)
    {
        cout << word1 << " goes before " << word2 << endl;
    }
    else
    {
        cout << word2 << " goes before " << word1 << endl;
    }
    return 0;
}

OUTPUT:


Related Solutions

Relational Operators For Cpp Discuss why relational operators can be used with enumeration types. Provide at...
Relational Operators For Cpp Discuss why relational operators can be used with enumeration types. Provide at least 2 examples of relational expressions with enumeration types. Explain your examples
Macionis, your textbook author, mentions in chapter 5 that there is now some evidence that people...
Macionis, your textbook author, mentions in chapter 5 that there is now some evidence that people can become "addicted" to social media and that social media can have some very negative effects on our lives. If you believe that your personal use of social media has had very important negative impacts on your life, so many negative impacts that you have given up the use of social media for some significant period of time, please describe those impacts in detail....
Suppose you want to form words with 3 letters and all letters in the alphabet can...
Suppose you want to form words with 3 letters and all letters in the alphabet can be used except A and B (so, XYZ would be a word for example even though it does not make sense). a) How many possibilities do you have if repetition is permitted and ordering is relevant, how many possibilities do you have if repetition is not permitted and ordering is relevant; how many possibilities do you have if repetition is not permitted and ordering...
how can object -relational database be used to implement an SDBMS?
how can object -relational database be used to implement an SDBMS?
Find the number of five letter words that can be formed from the letters of the...
Find the number of five letter words that can be formed from the letters of the word PROBLEMS. ( please explain with details.) (a) How many of them contain only consonants? (b) How many of them begin and end in a consonant? (c) How many of them begin with a vowel? (d) How many contain the letter S? (e) How many begin with B and also contain S? (f) How many begin with B and end in a vowel? (g)...
Compare a Scientific Law to a Scientific Theory You can refer to the textbook or other...
Compare a Scientific Law to a Scientific Theory You can refer to the textbook or other reliable source or web site such as wikipedia, encyclopedia Britannica or similar, since this is a pretty standard topic. Always type in the sources used for your discussion posting at the end of the document. Present concrete examples of scientific models and scientific laws from physics, chemistry or biology. Twenty lines are enough; you don't have to write a paper.
Identify, compare, and contrast the major dividend theories that are discussed in your textbook. Be specific.  ...
Identify, compare, and contrast the major dividend theories that are discussed in your textbook. Be specific.   -Dividend Aversion (The Tax Effect Theory) -The Clientele Effect -The Residual Dividend Theory -The Signaling Effect of Dividends -The Expectations Theory
For each of the situations below (in your words - do not copy from textbook), describe...
For each of the situations below (in your words - do not copy from textbook), describe the analysis to be done and what would be the deciding factors in making each choice? *Make or Buy *Scrap or rework *Sell as is or process further *Sales Mix Selection *Segment Elimination *Keep assets or Replace assets
a)     How many four-letter words can be formed from the letters of the word LAUNDRY if each...
a)     How many four-letter words can be formed from the letters of the word LAUNDRY if each letter can only be used one time in a word? Y is NOT considered a vowel in this word. b)    How many contain the letter Y? c)     How many contain both vowels? d)    How many of them contain exactly three consonants? e)    How many of them begin and end in a consonant? f)      How many begin with N and end in a vowel? g)     How many begin with N and...
1) How many different ways can you arrange the letters in the words a) “friends” b)...
1) How many different ways can you arrange the letters in the words a) “friends” b) “initial” c) “probability” Show your calculations.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT