A very basic program I've been playing with

This is a discussion on A very basic program I've been playing with within the C++ Programming forums, part of the General Programming Boards category; I have recently picked up learning to program where I left of some time ago. I have always loved the ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    2

    Post 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 ). 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 spaceBeforestring textStringint textStringLengthint pausesBetweenint lineBreaksint sleepAfter)
        {
             
    int lengthOfText textString.length();
             if(
    textStringLength != 0){lengthOfText textStringLength;};
             for(
    int x=0x<spaceBeforex++)
                     {
    cout << " ";};
             for(
    int x=0x<lengthOfTextx++)
                     {
                       
    cout << textString[x];
                       
    Sleep(pausesBetween);
                     };
             for(
    int x=0x<lineBreaksx++)
                     {
    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(0running050175);
        
    Output(0initializing050175);
        
    Output(13winInterface050050);
        
    Output(0dots1047500);
        
    cout << init << endlSleep(75);
        
    Output(13ioStream050050);
        
    Output(0dots1415000);
        
    cout << init << endlSleep(75);
        
    Output(13WNI085175);
        
    Output(30WLANb05000);
        
    Output(0dots1115000);
        
    cout << init << endlSleep(75);
        
    Output(30WLANg05000);
        
    Output(0dots1115000);
        
    cout << init << endlSleep(75);
        
    Output(30WLANn05000);
        
    Output(0dots1115000);
        
    cout << init << endlSleep(75);
        
    Output(30Wired05000);
        
    Output(0dots725000);
        
    cout << init << endlSleep(75);
        
    Output(30testInter08000);
        
    Output(0dots575000);
        
    cout << init << endlSleep(75);
        
    Output(13identNetwork05000);
        
    Output(0dots1520000);
        
    cout << "LAN identified!" << endlSleep(75);
        
    Output(13identInternet05000);
        
    Output(0dots920000);
        
    cout << "Connection Established!" << endlSleep(75);
        
        
    cout << endl << endl;
        
    Output(0initSuccess05012300);
        
    //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 0mainMenuRepeat 1;}
           else if(
    repetition == 'n'){repeatError 0mainMenuRepeat 0;}
           else {
    repeatError 1Error(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 << endlsystem("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(0exitString035175);
        
    //for(x=0; x<31; x++){Output(exitString[x],35);};
        //cout << endl;
        //Sleep(75);
        
    Output(0exiting035075);
        
    Output(0Dots10750350);
        
    //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 1Error(2);};};
        }while(
    mainMenuRepeat == 1);
               
        return 
    0;
    };






    int main(int argcchar *argv[])
    {


        
    mainMenu();
        
        return 
    EXIT_SUCCESS;



    Without comments:
    main commentless.cpp

    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.

    Last edited by patrioticparado; 09-21-2012 at 02:25 PM.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    First, a blatant insult: your program is too much of a pile of junk for me to make much sense of it or to have any real interest in it. Normally, a program does one useful thing well. I don't see any unity in the things your program does. But that's your call.

    As for the slashes with the cd command, you're using the wrong slash. Try \\ instead of //.

    And you don't have to use endl all the time. Instead of this:
    cout << " Error!" << endl;
    you can simply do this
    cout << " Error!\n"; // note the direction of the slash

    Also, it doesn't make much sense to post your code as PHP code or to fool with the default font for the main body of your post.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Yuck, red orange and blue code?! That's horrible. Please just post as plain text and let the forums automatically do the syntax hilighting.
    You don't need to use a non-default font either.
    This is too annoying to read and so I'm not going to bother. (Just being honest)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    2
    For whatever reason since posting I was only able to edit the OP once. Now I no longer have the option for God and Alex only know why. First off, I used the PHP tags because the CODE tags left my code in plain text, black and white. And the font is for readability, I find the default font to run together too easily (especially on late night eyes). As I said before I know very little code so its difficult for this program to be much more than a steaming pile of venereal disease infested crap, but it has helped me to practice implementation of very basic principles and given me a foundation to build on. Thank you both for your replies and I look forward to retrying the "cd" command with correct slashes.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Quote Originally Posted by patrioticparado View Post
    For whatever reason since posting I was only able to edit the OP once. Now I no longer have the option
    Most (all?) forums give you a finite time to make changes. If you modify something after 6 replies, it makes all the replies look stupid.

    Quote Originally Posted by patrioticparado View Post
    First off, I used the PHP tags because the CODE tags left my code in plain text, black and white.
    So it's in plain text. That's what we expect. That's how the 100000+ other posts look. We're used to it.

    Quote Originally Posted by patrioticparado View Post
    And the font is for readability, I find the default font to run together too easily (especially on late night eyes).
    And after 150000+ threads, the default font has been chosen for a reason. Increase the font on your screen. Ctrl+Scroll-wheel works quite well.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    Quote Originally Posted by patrioticparado View Post
    And the font is for readability, I find the default font to run together too easily (especially on late night eyes).
    But the whole point of serif strokes is to make it look like the letters are connected together.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Music playing program
    By corey.heffernan in forum C Programming
    Replies: 0
    Last Post: 04-07-2011, 07:37 PM
  2. Help with a very basic C++ program
    By Method4ever in forum C++ Programming
    Replies: 15
    Last Post: 02-12-2009, 08:24 AM
  3. Very basic program - In need of help
    By gohan2091 in forum C Programming
    Replies: 10
    Last Post: 05-31-2006, 04:36 PM
  4. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  5. playing sounds in a DOS program
    By Geo-Fry in forum C++ Programming
    Replies: 1
    Last Post: 03-18-2003, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21