Answer to Question #157878 in C++ for Talha

Question #157878

Initialize a string of size 40. Write a program that prints all unique alphabets from string. After printing them sort them in ascending order.

For example: Hi world I am here to help you.

Unique characters are: H, I, W, O, R, L, D, A, M, E, T, P, Y, U.

Sorted: A, D, E, H, I , L,M, O, P, R, T, U, W, Y


1
Expert's answer
2021-01-24T11:09:53-0500
#include <iostream>
#include <string>
using namespace std;
int main () {
    char str[40] = "hi world i am here to help you.";
    string unique_character = "";
    for (int i = 97; i <= 122; i++) {
        for (int j = 0; j < 40; j++) {
            if (char(i) == str[j]) {
                unique_character += char(i) - 32;
                unique_character += char(44);
                break;
            }
        }
    }
    cout << "Sorted: " << unique_character;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS