I began with GWBasic largely due to the fact it came with DOS 1.0. I would think of a simple application like temperature conversion. Then I would expand upon that to put conditionals in there, like limiting input between -40 to +50. In essence, I'd just dream something up and then try to build code that would work, and then improve upon it.
Soon I realized two things. (1) Interpretive languages are really, really slow, especially when it comes to sorting large amounts of data. (2) being limited to only machines that run GWBasic. It did allow me though to write one line of code and then immediately see the result. Such languages prompted one immediately if you code was syntactically incorrect. This did however get me in the habit of top down development, meaning I would do a small piece and then make sure every combination and permutation of it worked properly.
The most comprehensive application I wrote was in "C", but "C++" is brand new to me. Therefore, I'm taking a lot of code I've done before and some new stuff and implementing classes and becoming familiar with nuances particular to "C++". To that end C++ Primer 5th edition is something you might want to look into. It is an intensive read, but if your serious about application development or embedded system, I think it would be well worth your while.
As an example, this is how I start with top/down. Everything that is associated with reading an writing to disk, will be in "main". As you can see by lines 43 44 45, I avoid nesting code blocks any deeper than three levels before breaking into functions such as at line 41. The user can just simply type application name or with one argument which should be the filename to be used. Optionally the file can be created. The point is, in this block I've pretty much covered everything associated with files.
NOTE: I don't mean to advocate I'm using fstream correctly, but if there is a disk problem, it'll be easy to find the problem. If you do this and don't move onto more complex things until you completely understand the fundamentals, you'll be surprised how fast you'll learn.
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
|
int main (int ArgC, char **ArgS) {
string FileNme = "Infom.dat";
time (&Now); // Seconds since 1-Jan-1970
if ( ArgC == 2 )
FileNme = ArgS[1]; // Replace with name passed by user
// Initial display
system ("cls");
cout << "\n\tSession # [" << hex << Now << "] ";
Data.open (FileNme, fstream::in | fstream::binary);
if ( Data.is_open () )
cout << "Processing " << FileNme << " ";
else {
char Response;
cout << "Create " << FileNme << " [Y/N]";
cin >> Response;
if ( toupper (Response) == 'Y' ) {
Data.open (FileNme, fstream::out | fstream::binary);
if ( Data.is_open () ) {
cout << "\n\n\tPlease enter following information:\n" << endl;
GetOwnerInfo (Data);
Data.close ();
}
}
}
return 0;
}
|