Question

HI CAN YOU PLEASE PROGRAM THIS ASSIGNMENT USING C++

Ask the user to input a string. Then sort the string in reverse lexicographic order and print it out. Reverse lexicographic m

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int main() {
    string line;
    cout << "Enter a string: ";
    getline(cin, line);
    char temp;
    for (int i = 0; i < line.length(); ++i) {
        for (int j = 0; j < line.length() - 1; ++j) {
            if (line[j] < line[j+1]) {
                temp = line[j];
                line[j] = line[j+1];
                line[j+1] = temp;
            }
        }
    }
    cout << "String in reverse alphabetic order is " << line << endl;
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
HI CAN YOU PLEASE PROGRAM THIS ASSIGNMENT USING C++ Ask the user to input a string. Then sort the string in reverse lex...
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
  • Multi part question c++ and yes I'm going to rate you up thank youu! Part A...

    Multi part question c++ and yes I'm going to rate you up thank youu! Part A Ask the user to input a string. Then sort the string in reverse lexicographic order and print it out. This would be done using the integer values of the characters (ASCII table). Use any one of the sorting methods. For example: if the user enters "zeta" sorting it in reverse lexicographic order would give "ztea". if the user enters "ZETA" it would give "ZTEA"....

  • HI CAN YOU PLEASE PROGRAM THIS ASSIGNMENT USING C++ Use a stack to reverse a word. A user enters a word and the reverse...

    HI CAN YOU PLEASE PROGRAM THIS ASSIGNMENT USING C++ Use a stack to reverse a word. A user enters a word and the reverse of the word is printed out. The characters are reversed using a stack. Hint: you can use the stackArray implementation we did in class today, but instead of an int arr[SIZE], you can use a char arr[SIZE]: class Stack char arr[SIZE]; // array to store Stack elements Use a stack to reverse a word. A user...

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • please use pythom Write a program that ask the user for a string as input. It...

    please use pythom Write a program that ask the user for a string as input. It should duplicate of all the characters in the string and print it back out to the user. For example: AbC123 would be printed out as AAbbCC112233 Write a program that takes two lists and displays the items that occur in both lists. For example: ["a", "b", "c"] ["c", "a", "d"] would display a and c

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Using Java In this assignment we are working with arrays. You have to ask the user...

    Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • Hi All, Can someone please help me correct the selection sort method in my program. the...

    Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...

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