Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I print out the Misses in alphabetical order?

+1 vote
asked Jan 15, 2021 by TylerBlachowiak (330 points)

2 Answers

+1 vote
answered Jan 16, 2021 by Peter Minarik (55,660 points)

There could be various ways to do this.

  1. Before printing out, you sort your characters in a string alphabetically.
  2. You do not use a StringBuilder to store your characters, but a byte array instead. Every character is represented by a byte from 0 ('a') til 26 ('z'). You initialize the array to 0 (false). If the user tries one of the letters, you mark that one 1 (true). In the end, you iterate through the array and print only those letters that have their id marked as true. Tip: char ch; (ch - 'a') will give you their id.
Good luck
commented Jan 18, 2021 by Fidel Mendoza Jr (100 points)
// Answering a Question on the ASK A QUESTION PORTION:
//Fix  it  ends...How to get the protons and nuetrons... know the fix please
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>


using namespace std;

int main()
{
    string MyStr;
    int x = 0;
    
    cout<<"               SCIENCE PROJECT \n You have 3 choices \n";
    cout<<" What is the smallest particle in the World? \n";
    cout<<"   1. Atom 2. cells 3. element \n";
    
    cout<<" ENTER YOUR ANSWER HERE, NUMBER ONLY: ";
    getline (cin, MyStr);
    stringstream (MyStr)>>x;
    
    if (x==1){
        cout<<"       CORRECT. THE ATOM IS THE SMALLEST PARTICLE IN THE WORLD \n";
    }
    else cout<<"      WRONG. 'RUN' THE PROGRAM AGAIN AND TRY AGAIN \n";

    cout<< "   SORRY, you're next quiz about \n  ... how to get the protons and neutrons of an element \n";
    cout <<"   (a) Atomic mass  atomic number (b) atomic number  atomic mass \n";
    cout<<"    ... is VERY CONFUSING";
    return 0;
}
0 votes
answered Jan 23, 2021 by Dev Gaur (140 points)
  1. Before printing out, you sort your characters in a string alphabetically.
  2. You do not use a StringBuilder to store your characters, but a byte array instead. Every character is represented by a byte from 0 ('a') til 26 ('z'). You initialize the array to 0 (false). If the user tries one of the letters, you mark that one 1 (true). In the end, you iterate through the array and print only those letters that have their id marked as true. Tip: char ch; (ch - 'a') will give you their id.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...