1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// Program to refine use of void and prototype functions.
#include<iostream> // I leave a space between the include and the <>
#include <string> // like this, but each to their own.
using namespace std; // I don't often use this.
/*
Its bad to use the 'using namespace' this in header files but
I also avoid it in cpp files as well. The main reason being that
it can get confusing as to which class you are referring to.
But obviously sometimes it really makes the code clearer. It is good
to remember that you can use that in a single function so as not to
pollute the whole file.
*/
string CHOICE; // personally I tend to reserve CAPS for macro definitions.
int COUNTER = 1;
/*
I personally only use Caps at the beginning of an identifier for class declarations.
But it seems to be fairly common to use them for function declarations as you
have in the Microsoft world.
*/
void Starline(int STAR_COUNT, int WHITESPACE, int PRE_ENDL, int POST_ENDL);
/* Variable order:
number of stars, number of spaces before, lines before, lines after. */
// I never explicitly use void in this context. Not since the days when C demanded it :)
int main(void)
{
/*
I have religiously used tabs and religiously set my tab spacing to 4 characters.
That seems most common but I have seen people set to 8 character spacing.
I have hardly ever seen anyone use spaces rather than tabs.
*/
Starline(79, 0, 0, 1);
cout << " Test Program";
Starline(79, 0, 1, 1);
Starline(39, 20, 1, 2);
cout << "Please hit Enter to exit.";
getline(cin, CHOICE);
return 0;
}
//Starline function defined here.
void Starline(int STAR_COUNT, int WHITESPACE, int PRE_ENDL, int POST_ENDL)
{
for(COUNTER = 1; COUNTER <= PRE_ENDL; COUNTER++) cout << endl;
for(COUNTER = 1; COUNTER <= WHITESPACE; COUNTER++) cout << " ";
for(COUNTER = 1; COUNTER <= STAR_COUNT; COUNTER++) cout << "*";
for(COUNTER = 1; COUNTER <= POST_ENDL; COUNTER++) cout << endl;
}
/*
I recently changed from using post increment to pre increment in my for loops like this:
*/
for(size_t i = 0; i < vec.size(); ++i);
/*
I also use size_t in preference to int when I am using unsigned integers like
for accessing an array or something similar.
*/
|