Groups | Search | Server Info | Login | Register
Groups > comp.lang.c++ > #120003
| From | Ben Bacarisse <ben@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c++, alt.comp.lang.c++.misc, free.test |
| Subject | Re: ASCII Codes |
| Date | 2024-09-09 13:44 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87jzflknd3.fsf@bsb.me.uk> (permalink) |
| References | <Q%nDO.343686$8jx2.215799@fx17.iad> |
Cross-posted to 3 groups.
Student Project <student@invalid.invalid> 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.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
ASCII Codes Student Project <student@invalid.invalid> - 2024-09-08 20:45 +0000
Re: ASCII Codes Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-08 14:32 -0700
Re: ASCII Codes "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-09-08 14:37 -0700
Re: ASCII Codes "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-09-08 14:39 -0700
Re: ASCII Codes Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-09-09 09:41 -0400
Re: ASCII Codes red floyd <no.spam.here@its.invalid> - 2024-09-09 21:44 -0700
Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-09 14:32 +0200
Re: ASCII Codes Ben Bacarisse <ben@bsb.me.uk> - 2024-09-09 13:44 +0100
Re: ASCII Codes Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-09-09 09:43 -0400
Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-09 18:52 +0200
Re: ASCII Codes Student Project <student@invalid.invalid> - 2024-09-10 01:04 +0100
Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-10 10:32 +0200
Re: ASCII Codes Paavo Helde <eesnimi@osa.pri.ee> - 2024-09-10 07:55 +0300
csiph-web