Hi!

For the past few months I've been self-learning C++ with the book "C++ Primer Plus" by Stephen Prata. After having gotten through chapter 7, I decided to check my progress by writing a little program, Baztro.

Baztro stands for Basic Astrology Tool. It asks you for birthdate(s) and will tell you what astrology sign you are, or how you get along with others, along with a simple menu system with a command-line user interface.

However, I did not create this to be a hardcore astrology software, but only to assess my coding progress. So, like the name has suggested, its astrology aspect is not very deep. The emphasis is on the code writing.

Because I'm new to the C++ scene, and I haven't been in any C++ class, I'd love to know if my coding practices are good and clear, whether the design is efficient, whether the code is easy to read. I'd love to know the opinions and critics from experienced coders. That's why I'm posting the code here, hoping others will give their voices and, heh, 'grade' me!

So, if you are interested, I've attached the source .cpp (I have yet to have a good grasp at multi-file source files, and after a few unsuccessful attempts I decided that I'll leave it as it is, one single .cpp. I try to make it as easy to read as possible ^^").
I've also packaged the files into archives (just to get a feel of distributing releases xD) and uploaded them into MediaFire, at http://preview.tinyurl.com/baztro. The Baztro_vx.x.x.x_publicXXXX.7z archives contain the binary, the source code, and the development log. The Baztro_v1.0_publicReleaseWithSRCs.7z archive contains all the above, along with the VC++ project folder. I would also like to know if the archives' structures are good enough and easy to understand, if anyone is willing =)

So, if you are interested (and are still reading lol), grade me!

Now i am curious about few things.
1. why astrology? (casual question, no need for answer)
2. why not "using namespace std;"
3. how come i am the first one to appreciate this?

its definitely a good program, and so are your coding habits.

Your comments are a bit excessive, I know this is something very personal but generally you'll want to have few comments that help understand the code, not comments that repeat what the code says. Don't take this too harshly though, I am really a comment-minimalist.

E.g.

#include <iostream>		// For Standard C++ console IO facilities
#include <string>		// for std::string
#include <Windows.h>	// For WinAPI facilities

Any somewhat-experienced C++ coder will know what these headers are for

int indicateSign(int birthDay, int birthMonth);
// Arguments: 2 ints, as birthDay-birthMonth
// Return: int, as the zodiac order number correspondent with birthDay-birthMonth

Commenting function input/output is ok, but I'd suggest to use a 'standard' format like Doxygen, so that you could also easily generate project documentation just by running Doxygen. And people reading your code, who are familiar with Doxygen will know exactly where to look.

For me, personally(!), the massive // *** <something> *** ==================== is very cluttering. When I am looking for e.g. the declaration of QUALITY I'll either use the IDE's built-in 'goto declaration' or use a search anyway.


Another example of excessive comments - "CLEAR_CONSOLE" is obvious enough.

bztConsole("CLEAR_CONSOLE"); // Clear the screen

You compare userCommand to both upper and lowercase strings, e.g.:

if ((userCommand == "E") || (userCommand == "e"))

Why not first make userCommand all lower-case and just do if( userCommand == "e" ) ?

I usually prefer to write if( "e" == userCommand ), as this will generate an error when you accidentally write if( "e" = userCommand ). if( userCommand = "e" ) will compile without warnings, but is mostly not what you want.

In analyzeCompatibility there are some huuuge if statements, a good exercise would be to abstract this into classes, overloading the operator==. I don't know how feasible this is because I don't know exactly what the comparisons are for, though.


Your bztConsole works with strings, while this works fine I think it would be easier to use enums. This would also get rid of the if( command == "<something>" ) as you could just use a switch( command ) { case SET_TITLE: break; }


And like vinayakagarg said, why not using namespace std? You can 'safely' use this in .cpp files, as long as you remember not to put it in header files.

Now i am curious about few things.
1. why astrology? (casual question, no need for answer)
2. why not "using namespace std;"
3. how come i am the first one to appreciate this?

its definitely a good program, and so are your coding habits.

1. It's because I've always been interested in astrology. It's mysterious, intriguing and miraculously correct if you use it, heh, correctly. Just something for my passion =D

2. It's a feeling, actually. I feel that using namespace std; is wasteful. I mean, I'm not using everything in the namespace, so why would I include the whole thing in? That seems... lazy, and perhaps 'uncontrolled', lol.

3. That depends. What is it you appreciate?

Your comments are a bit excessive, I know this is something very personal but generally you'll want to have few comments that help understand the code, not comments that repeat what the code says. Don't take this too harshly though, I am really a comment-minimalist.

E.g.

#include <iostream>		// For Standard C++ console IO facilities
#include <string>		// for std::string
#include <Windows.h>	// For WinAPI facilities

Any somewhat-experienced C++ coder will know what these headers are for

int indicateSign(int birthDay, int birthMonth);
// Arguments: 2 ints, as birthDay-birthMonth
// Return: int, as the zodiac order number correspondent with birthDay-birthMonth

Commenting function input/output is ok, but I'd suggest to use a 'standard' format like Doxygen, so that you could also easily generate project documentation just by running Doxygen. And people reading your code, who are familiar with Doxygen will know exactly where to look.

For me, personally(!), the massive // *** <something> *** ==================== is very cluttering. When I am looking for e.g. the declaration of QUALITY I'll either use the IDE's built-in 'goto declaration' or use a search anyway.


Another example of excessive comments - "CLEAR_CONSOLE" is obvious enough.

bztConsole("CLEAR_CONSOLE"); // Clear the screen

You compare userCommand to both upper and lowercase strings, e.g.:

if ((userCommand == "E") || (userCommand == "e"))

Why not first make userCommand all lower-case and just do if( userCommand == "e" ) ?

I usually prefer to write if( "e" == userCommand ), as this will generate an error when you accidentally write if( "e" = userCommand ). if( userCommand = "e" ) will compile without warnings, but is mostly not what you want.

In analyzeCompatibility there are some huuuge if statements, a good exercise would be to abstract this into classes, overloading the operator==. I don't know how feasible this is because I don't know exactly what the comparisons are for, though.


Your bztConsole works with strings, while this works fine I think it would be easier to use enums. This would also get rid of the if( command == "<something>" ) as you could just use a switch( command ) { case SET_TITLE: break; }


And like vinayakagarg said, why not using namespace std? You can 'safely' use this in .cpp files, as long as you remember not to put it in header files.

Ahh, I see. There are comments that are unnecessary. It wouldn't hurt to remove them, really. Also doing that will help make the code easier to read! Yeah, comments should be only used to annotate, not to restate the obvious. Thanks =D

That is the first time I've heard of Doxygen, and also the first time I've heard of automated documentation! Oh man, there is lots to things to learn xD Looking for more on that now :3

The // *** <something> *** =================== is my idea of breaking the code into blocks ^^" I think with all the excessive comments cut out, those lines wouldn't really be cluttering.

Those are nice pointing-outs, really! lowercase-ize the userCommand, use switch case break, use enum as symbolic constants for bztConsole, and re-order the sides of =='s. I'll do those!
About classes, well, I've yet to reach that fortress, so that is not an available opton for me xD

Thanks!

This is the revised version of the program. I hope this will help if anyone happens to have interest in this thread =) The comments are trimmed out, the std::string commands replaced by handy enums <3, the easy-to-follow switch-case... Check them out if you are interested!

I will now stop developing Baztro. It had been fun ^0^, produced a little handy and stable program which I am content with, and I am ready to move on =D

I attached the latest cpp in this post.

If anyone is interested, (s)he can download the latest package at http://tinyurl.com/baztro or http://www.mediafire.com/?827paotar1faw. (S)he can also download the GoldenPackage which contains EVERYTHING Baztro xD

Thanks for the two who took time to read my work and commented!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.