1 Attachment(s)
A very basic program I've been playing with
I have recently picked up learning to program where I left of some time ago. I have always loved the idea of programming and find C++ fascinating(ly complicated). I have, at this point, essentially the knowledge level of an "Intro to C++" class and what else I have found searching the interwebs. I have been working on this program as way to practice implementation as I move forward. My goal is to, over time, expand it's functionality to actually useful operations and to have something to rewrite from scratch whenever I learn groundbreaking new concepts or techniques (structures are next :D). In time I hope to have this program turn into a useful customized program to handle mundane or repetitive tasks in my Windows (7 x64) environment (eventually it will become a Win32 app with a GUI). I have included two versions in my post. One with my original comments and one without (for grumpy and the like who don't like them). I believe my use of function names and structuring should make it relatively easy to follow without them. Please take a look.
With comments:
PHP Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <ctime> //some of these are for future use
using namespace std;
int mainMenuRepeat = 1; //temporarily here. I hope to move this into
//int main() but caused errors. ?
//For error handling
int Error(int errorCode)
{
switch (errorCode) {
case 1: //Menu selection error
system("cls");
cout << " Error!" << endl
<< " -> Menu item does not exist or is currently unavailable" << endl
<< " ->You are being returned to the main menu" << endl;
system("pause");
break;
case 2: //Menu repeat error
system("cls");
cout << " Error!" << endl
<< " -> Menu repeat or program exit error" << endl
<< " ->You are being returned to the main menu" << endl;
system("pause");
break;
case 3: //"Run next program?" error
cout << " Error!" << endl
<< " -> Invalid input. Please reply \"y\" or \"n\"." << endl << endl;
break;
default: //Unrecognized error
cout << " Error!" <<endl
<< " -> Error code not recognized!" << endl
<< " ->Error code passed: " << errorCode << endl
<< " ->You are being return to the main menu" << endl;
system("pause");
break;
};
};
//For handling output
void Output(int spaceBefore, string textString, int textStringLength, int pausesBetween, int lineBreaks, int sleepAfter)
{
int lengthOfText = textString.length();
if(textStringLength != 0){lengthOfText = textStringLength;};
for(int x=0; x<spaceBefore; x++)
{cout << " ";};
for(int x=0; x<lengthOfText; x++)
{
cout << textString[x];
Sleep(pausesBetween);
};
for(int x=0; x<lineBreaks; x++)
{cout << endl;};
Sleep(sleepAfter);
};
//For creating and editing documents
int Notepad()
{
int choice;
int repeat = 1;
do{
system("cls");
cout << "Notepad started." << endl << "What would you like to do?" << endl
<< "(X) Start a new doc" << endl
<< "(X) Open a previous document" << endl
<< "(X) Delete a document" <<endl
<< "(4) Exit notepad" << endl;
cin >> choice;
switch (choice) {
case 4:
repeat = 0;
break;
default:
Error(1);
break;
};
}while(repeat == 1);
};
//Purely visual entertainment
int Hack()
{
system("cls");
string running = "Running Application";
string comp = "Complete!";
string init = "Initialized!";
string success = "Success!";
string dots = "................................";
string initializing = "Initializing:";
string ioStream = "User I/O stream";
string winInterface = "Win32 API Interface";
string WNI = "Windows Network Interfaces:";
string WLANb = "WLAN 802.11b";
string WLANg = "WLAN 802.11g";
string WLANn = "WLAN 802.11n";
string Wired = "Wired Connection";
string testInter = "Testing Interfaces";
string identNetwork = "Identifying Local Network";
string identInternet = "Identifying Internet Connection";
string initSuccess = "Application Initialized Successfully!";
Output(0, running, 0, 50, 1, 75);
Output(0, initializing, 0, 50, 1, 75);
Output(13, winInterface, 0, 50, 0, 50);
Output(0, dots, 10, 475, 0, 0);
cout << init << endl; Sleep(75);
Output(13, ioStream, 0, 50, 0, 50);
Output(0, dots, 14, 150, 0, 0);
cout << init << endl; Sleep(75);
Output(13, WNI, 0, 85, 1, 75);
Output(30, WLANb, 0, 50, 0, 0);
Output(0, dots, 11, 150, 0, 0);
cout << init << endl; Sleep(75);
Output(30, WLANg, 0, 50, 0, 0);
Output(0, dots, 11, 150, 0, 0);
cout << init << endl; Sleep(75);
Output(30, WLANn, 0, 50, 0, 0);
Output(0, dots, 11, 150, 0, 0);
cout << init << endl; Sleep(75);
Output(30, Wired, 0, 50, 0, 0);
Output(0, dots, 7, 250, 0, 0);
cout << init << endl; Sleep(75);
Output(30, testInter, 0, 80, 0, 0);
Output(0, dots, 5, 750, 0, 0);
cout << init << endl; Sleep(75);
Output(13, identNetwork, 0, 50, 0, 0);
Output(0, dots, 15, 200, 0, 0);
cout << "LAN identified!" << endl; Sleep(75);
Output(13, identInternet, 0, 50, 0, 0);
Output(0, dots, 9, 200, 0, 0);
cout << "Connection Established!" << endl; Sleep(75);
cout << endl << endl;
Output(0, initSuccess, 0, 50, 1, 2300);
//Find host, drive enumeration, etc. will go here
/*REWRITE for new Output() REWRITE for new Output()
//Pretends to count up a drives size
mystring = "Checking HDD size";
for(x=0; x<17; x++){Output(mystring[x], 50);};
Sleep(150);
for(x=0; x<5; x++){Output(dots[x],250);};
cout << endl;
int z=0;
int w;
int y=(rand()%100) + 15000;
for(x=0; x<y; x++)
{
w=rand()*5;
z+=w;
cout << "\r";
cout << z;
Sleep(1);
};
*/
cout << endl;
cout << "Application End" << endl;
int repeatError = 1; //sets 'error' as the default state
do{
char repetition = 1;
cout << "Run another app? (y or n)" << endl;
cin >> repetition;
if(repetition == 'y'){repeatError = 0; mainMenuRepeat = 1;}
else if(repetition == 'n'){repeatError = 0; mainMenuRepeat = 0;}
else {repeatError = 1; Error(3);}
}while(repeatError == 1);
};
//For testing code without necessarily having to rely on another section
int currentTest()
{
};
//For checking error handling
int causeError()
{
system("cls");
cout << "Input desired error code: ";
int errorNumber;
cin >> errorNumber;
Error(errorNumber);
cout << endl; system("pause");
return 1;
}
//Exit the program
int Exit()
{
system("cls");
//int x;
string exitString = "Thank you for using The Toolbox";
string exiting = "Now exiting";
string Dots = "..................";
Output(0, exitString, 0, 35, 1, 75);
//for(x=0; x<31; x++){Output(exitString[x],35);};
//cout << endl;
//Sleep(75);
Output(0, exiting, 0, 35, 0, 75);
Output(0, Dots, 10, 75, 0, 350);
//for(x=32; x<43; x++){Output(exitString[x],35);};
//for(x=0; x<10; x++){Output(Dots[x],75);};
//Sleep(250);
return 0;
};
//The for() loops above are how I originally handled output throughout
//the program. I eliminated about 90 lines of code using the new method
//Welcome Screen
int mainMenu()
{
srand((unsigned int)time(0));
int choice;
do{
system("cls");
cout << "Welcome to The Toolbox" << endl << "Please select a tool:" << endl
<< "(X) Encryptor" <<endl
<< "(X) Notepad" <<endl
<< "(X) Game" <<endl
<< "(X) Options" <<endl
<< "(5) Hack" << endl
<< "(X) Calculator" << endl
<< "(7) Current Test" << endl
<< "(8) Error Maker" << endl
<< "(9) Exit" <<endl;
cin >> choice;
switch (choice){
case 1:
//Encryptor
Error(1);
break;
case 2:
//Notepad
Notepad();
break;
case 3:
//Game
Error(1);
break;
case 4:
//Options
Error(1);
break;
case 5:
Hack();
break;
case 6:
//Calc
Error(1);
break;
case 7:
//Current Test
currentTest();
break;
case 8:
//Error maker
causeError();
break;
case 9:
//Exit;
return Exit();
default:
Error(1);
break;
};
if(mainMenuRepeat != 1){if(mainMenuRepeat != 0){mainMenuRepeat = 1; Error(2);};};
}while(mainMenuRepeat == 1);
return 0;
};
int main(int argc, char *argv[])
{
mainMenu();
return EXIT_SUCCESS;
}
Without comments:
Attachment 11987
A few questions I have:
1) Are there any mistakes I've made that demonstrate a clear lack of proper understanding for a concept?
2) I included at one point:
PHP Code:
system("cd c:/"); //I tried "cd c://" too to literally pass the "/"
system("dir"); //which still may not have been correct
This was to display the contents of the root of C:/ to the user, however the "cd" function never appeared to run. The "dir" command functioned as one would expect displaying the contents of the currently active directory. Why did the "cd" command not function as expected? Is it that it was not (or could not) be passed correctly to system()? Or did it simply execute in a new window that closed to quickly to see?
3)Is there anything in particular that I should look into next besides simply the next tutorial on the list?
Any other comments, questions, criticisms or blatant insults are welcome and greatly appreciated. Thank you all for the help you've already provided me via replies to other user's posts.