ut/cin.getline() for the third string similar to the ones for first and second strings. 3. Add the appropriate case to the "if/else if" structure such that the three strings will be displayed in alphabetical order. Hint: There are 6 possible cases (3!, 3 factorial = 3*2*1 = 6) for all complete permutations. The easiest check is to input the three strings as single letters like: "a", "b", and "c". You "if/else if" should cover 6 cases for the these possible input order: abc, acb, bac, bca, cab, cba. Regardless of the input order the output should be always abc. First "if" condition check is like: if ( strcmp(name1,name2) < 0 && strcmp(name2,nam

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In C++ with comments please

Modify the program 12-7 from page 826 as follows:

1. Add a third C-string as name3[NAME_LENGHT].

2. Add a pair of cout/cin.getline() for the third string similar to the ones for first and second strings.

3. Add the appropriate case to the "if/else if" structure such that the three strings will be displayed in alphabetical order.

Hint: There are 6 possible cases (3!, 3 factorial = 3*2*1 = 6) for all complete permutations. The easiest check is to input the three strings as single letters like: "a", "b", and "c". You "if/else if" should cover 6 cases for the these possible input order: abc, acb, bac, bca, cab, cba. Regardless of the input order the output should be always abc.

First "if" condition check is like:

if ( strcmp(name1,name2) < 0 && strcmp(name2,name3) < 0 )

cout << name1 << " " << name2 << " " << name3 << endl;

You have to complete the rest of the 5 "else if" condition. The last "else" can be used to display the message that all three strings are the same.

Save and submit you program as pr12-7_Lab.cpp.

pr12-7:

// This program uses the return value of strcmp to

// alphabetically sort two strings entered by the user.

#include <iostream>

#include <cstring>

using namespace std;

 

int main()

{

// Two arrays to hold two strings

const int NAME_LENGTH = 30;

char name1[NAME_LENGTH], name2[NAME_LENGTH];

 

// Read two strings

cout << "Enter a name (last name first): ";

cin.getline(name1, NAME_LENGTH);

cout << "Enter another name: ";

cin.getline(name2, NAME_LENGTH);

 

// Print the two strings in alphabetical order

cout << "Here are the names sorted alphabetically:\n";

if (strcmp(name1, name2) < 0)

cout << name1 << endl << name2 << endl;

else if (strcmp(name1, name2) > 0)

cout << name2 << endl << name1 << endl;

else

cout << "You entered the same name twice!\n";

 

return 0;

}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education