• ASCII Codes

    From Student Project@21:1/5 to All on Sun Sep 8 20:45:54 2024
    XPost: alt.comp.lang.c++.misc, free.test

    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    int main()
    {
    system("color 0A");
    system("cls");
    vector<string> obj = {
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "exclamation mark",
    "quotation mark",
    "number sign",
    "dollar sign",
    "percent sign",
    "ampersand",
    "apostrophe",
    "left parenthesis",
    "right parenthesis",
    "asterisk",
    "plus sign",
    "comma",
    "hyphen",
    "period",
    "slash",
    "digit 0",
    "digit 1",
    "digit 2",
    "digit 3",
    "digit 4",
    "digit 5",
    "digit 6",
    "digit 7",
    "digit 8",
    "digit 9",
    "colon",
    "semicolon",
    "less-than",
    "equals-to",
    "greater-than",
    "question mark",
    "at sign",
    "uppercase A",
    "uppercase B",
    "uppercase C",
    "uppercase D",
    "uppercase E",
    "uppercase F",
    "uppercase G",
    "uppercase H",
    "uppercase I",
    "uppercase J",
    "uppercase K",
    "uppercase L",
    "uppercase M",
    "uppercase N",
    "uppercase O",
    "uppercase P",
    "uppercase Q",
    "uppercase R",
    "uppercase S",
    "uppercase T",
    "uppercase U",
    "uppercase V",
    "uppercase W",
    "uppercase X",
    "uppercase Y",
    "uppercase Z",
    "left square bracket",
    "backslash",
    "right square bracket",
    "caret",
    "underscore",
    "grave accent",
    "lowercase a",
    "lowercase b",
    "lowercase c",
    "lowercase d",
    "lowercase e",
    "lowercase f",
    "lowercase g",
    "lowercase h",
    "lowercase i",
    "lowercase j",
    "lowercase k",
    "lowercase l",
    "lowercase m",
    "lowercase n",
    "lowercase o",
    "lowercase p",
    "lowercase q",
    "lowercase r",
    "lowercase s",
    "lowercase t",
    "lowercase u",
    "lowercase v",
    "lowercase w",
    "lowercase x",
    "lowercase y",
    "lowercase z",
    "left curly brace",
    "vertical bar",
    "right curly brace",
    "tilde" };

    cout << "\tCode" << "\tCharacter" << "\tWhat it means" << "\n";
    cout << "\t#####################################\n\n";
    for (int i = 33; i <= 126; i++)
    {
    cout << "\t" << i << "\t" << (char)i << "\t\t" << obj[i] << "\n";
    }

    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Student Project on Mon Sep 9 13:44:40 2024
    XPost: alt.comp.lang.c++.misc, free.test

    Student Project <[email protected]d> writes:

    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    Students tend to do this because it save a little typing, but it's
    generally considered a bad idea in anything but the shortest programs.

    int main()
    {
    system("color 0A");
    system("cls");
    vector<string> obj = {
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "exclamation mark",
    "quotation mark",
    "number sign",
    ...
    "digit 0",
    ...
    "digit 9",
    "colon",
    ...
    "at sign",
    "uppercase A",
    ...
    "uppercase Z",
    ...
    "grave accent",
    "lowercase a",
    ...
    "lowercase z",
    "left curly brace",
    "vertical bar",
    "right curly brace",
    "tilde" };

    One thing that would help a lot would be to stop relying on getting the
    order exactly right. You could, at the expense of more typing, use assignments:

    obj['!'] = "exclamation mark";

    This would make any errors obvious.

    And then, if you wanted to try something a little more sophisticated,
    you could use a loop for the digits and the letters.


    cout << "\tCode" << "\tCharacter" << "\tWhat it means" << "\n";
    cout << "\t#####################################\n\n";
    for (int i = 33; i <= 126; i++)
    {
    cout << "\t" << i << "\t" << (char)i << "\t\t" << obj[i] << "\n";
    }

    return 0;
    }

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Ahlstrom@21:1/5 to Ben Bacarisse on Mon Sep 9 09:43:05 2024
    XPost: alt.comp.lang.c++.misc, free.test

    Ben Bacarisse wrote this copyrighted missive and expects royalties:

    Student Project <[email protected]d> writes:

    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    Students tend to do this because it save a little typing, but it's
    generally considered a bad idea in anything but the shortest programs.

    Or functions.

    --
    Push where it gives and scratch where it itches.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Ahlstrom@21:1/5 to Keith Thompson on Mon Sep 9 09:41:54 2024
    XPost: alt.comp.lang.c++.misc, free.test

    Keith Thompson wrote this copyrighted missive and expects royalties:

    Student Project <[email protected]d> writes:
    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    I suggest dropping this and using `std::vector`, `std::string`,
    `std::cout` explicitly. It's a bit more typing, but IMHO it makes the
    code clearer.

    That's my feeling to. Explicit namespaces mean that the names of variables do not have to be as long.

    <other good advice snipped>

    --
    Keith Thompson (The_Other_Keith) [email protected]
    void Void(void) { Void(); } /* The recursive call of the void */

    Chuckling at the sig.

    --
    Someone is speaking well of you.

    How unusual!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Student Project@21:1/5 to Bonita Montero on Tue Sep 10 01:04:31 2024
    XPost: free.test, alt.comp.lang.c++.misc

    On 09/09/2024 17:52, Bonita Montero wrote:

    This also would help not to construct so much temporary string objects.



    Removed empty strings in vector and changed the code slightly to this:

    for (int i = 33; i <= 126; i++)
    {
    cout << "\t" << i << "\t" << (char)i << "\t\t" << obj[i - 33] << "\n";
    }

    The obj now starts from 0.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From red floyd@21:1/5 to Keith Thompson on Mon Sep 9 21:44:22 2024
    XPost: alt.comp.lang.c++.misc

    On 9/8/2024 2:32 PM, Keith Thompson wrote:
    Student Project <[email protected]d> writes:
    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    I suggest dropping this and using `std::vector`, `std::string`,
    `std::cout` explicitly. It's a bit more typing, but IMHO it makes the
    code clearer.

    int main()
    {
    system("color 0A");

    This set the console to black background (0) and light green foreground
    (A), but only under cmd.exe on Windows.

    system("cls");

    This clears the screen, but only on Windows.

    Both of these needlessly limit the portability of your program.

    On a system that doesn't have "color" and "cls" commands, the calls to system() will fail silently and do nothing, which is probably ok.

    But why would you want to clear the screen and change the foreground and background colors anyway? Why is that part of the desired behavior of
    your program?

    If I want to run a program that displays data on my screen, I'm going to
    be seriously annoyed if it erases *my* existing data and messes with my foreground and background colors.

    vector<string> obj = {
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "exclamation mark",
    "quotation mark",
    [...]
    "left curly brace",
    "vertical bar",
    "right curly brace",
    "tilde" };

    An observation: Writing the code this way makes it very easy to
    introduce errors that are going to be hard to detect. If you one extra
    or missing entry on that first line ("", "", "", ...), it's going to invalidate the entire output. You haven't made such an error as far as
    I can tell, but think about how might make the code more robust.

    One possibility is to read the data from a file that's known to be
    valid. Another is to write a program that reads from such a file and generates C++ code that you include in your program. I'm not
    necessarily suggesting that you do this right away, but it's something
    to think about.


    Or use a std::map<char, const char *> indexed by the character (or alternatively, a std::map<char, std::string>...

    const std::map<char, const char *> {
    { '!', "Exclamation mark" },
    { '"', "Quotation mark" },
    ...
    };

    That way, you don't have to worry about getting out of sync.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Student Project on Tue Sep 10 07:55:14 2024
    XPost: alt.comp.lang.c++.misc, free.test

    On 08.09.2024 23:45, Student Project wrote:
    This one works as expected but there is definitely a room for
    improvement. :-)

    #include <iostream>
    #include <vector>

    using namespace std;

    int main()
    {
    system("color 0A");
    system("cls");
    vector<string> obj = {
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

    I believe the last one above should be "space", not "". It is commonly
    grouped together with other punctuation characters like "exclamation mark".


    "exclamation mark",
    "quotation mark",

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)