Simple Programming Tips On C/C++

Discussion in 'C++' started by subhasish, Apr 9, 2006.

  1. imrantechi

    imrantechi New Member

    Joined:
    Feb 12, 2008
    Messages:
    116
    Likes Received:
    4
    Trophy Points:
    0
    i feel the tips are fantastic
     
  2. elec.shabnam

    elec.shabnam New Member

    Joined:
    Feb 13, 2008
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    i really good the concept well
     
  3. elec.shabnam

    elec.shabnam New Member

    Joined:
    Feb 13, 2008
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    sorry i meant got
     
  4. rlearntowin1

    rlearntowin1 New Member

    Joined:
    Feb 26, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    fantastic tips
     
  5. rahul.mca2001

    rahul.mca2001 New Member

    Joined:
    Feb 13, 2008
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    0
    i m quite confused with memory leak , please help
     
  6. prerna_2712

    prerna_2712 New Member

    Joined:
    Jan 21, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Pls Help!!!

    I m making a project using C++ in graphics mode. the problem is that the code has exceeded 9000 lines and i m getting a linking error "Segment size exceeds 64K" on adding additional outtextxy statements..... What must I do??
     
  7. shipra

    shipra New Member

    Joined:
    Jul 7, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code to hack any computer password

    Hey Friend,
    I want to share some idea through which I succeeded to clear my interviews.Continiously I gave online exams where I improved my skill.Besides this i got some very important code for hacking that I got anywhere else.You can also do the same way....by joining here

    <<Deleted>>

    Regards,
    Shipra
     
  8. XXxxImmortalxxXX

    XXxxImmortalxxXX New Member

    Joined:
    Jun 27, 2007
    Messages:
    561
    Likes Received:
    19
    Trophy Points:
    0
  9. Chinmoy

    Chinmoy New Member

    Joined:
    Feb 13, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    And you cold have mentioned vortual functions, but otherwise, the article is simply great. Even i did not know of the new ANSI standard..thanks.
     
  10. Carlos

    Carlos New Member

    Joined:
    Dec 5, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    This is explicity typecasting in unsigned char.
    p1 = (unsigned char*)(ppt);

    But can u tell, what is the purpose of doing increament in pointer ppt
    p2 = (unsigned char*)(++ppt)
     
  11. Neillvan

    Neillvan New Member

    Joined:
    Jan 14, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys seems like all of you got the ideas uhmm can u help me out...

    we were told to make an infinite Loop that stops using the escape key on the keyboard.


    and im running out of time ..need to have it withing 10 hrs from now sorry for the rush request guys........i posted my prblem days before but non answered it ;d
     
  12. Tannoji Banerjee

    Tannoji Banerjee New Member

    Joined:
    Dec 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student.
    Location:
    Bally in Howrah
    I want to know more things for java(jsp).Then what am i do?By the way,this site is very much help ful for me.really essencial.
     
  13. adityapandey1207

    adityapandey1207 New Member

    Joined:
    Dec 30, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Re: Using the Volatile Keyword to Avoid Failures


    Can u plz tell me what exactly is a volatile dataype and why its used???
     
  14. A.Cloutier

    A.Cloutier New Member

    Joined:
    Mar 2, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    A simple tip to always keep in mind, which will more than likely save a lot of frustration:
    Plan out your program as thoroughly as possible on paper.

    Being a current student at UAT, there have been many times I dove head first into a project and spent hours going through issues that I could have resolved had I thought through the project or assignment first on paper. Having been taught to use the UML to make diagrams, it often doesn't occur to me to continue to do so, however, even on paper, writing out what you want to do with your program and breaking it down into pieces helps immensely. No matter what language you prefer, planning helps.
     
  15. spentak

    spentak New Member

    Joined:
    Mar 4, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Easily replace characters in string

    This is something useful I learned doing a homework assignment:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    int main (int argc, char * const argv[]) 
    {
    	string theString = "This is the# string that /has invalid() characters in it";
    	size_t illegalChar;
    		
    	cout << "\nThe String Before: " << theString << endl;
    	
    	illegalChar = theString.find_first_of("#$%^&*()!/[]{}");
    	
    	//Iterate through the string and replace all invalid characters with a space
    	while (illegalChar != string::npos)
    	{
    		theString[illegalChar] = ' ';
    		illegalChar = theString.find_first_of("#$%^&*()!/[]{}", illegalChar + 1);
    	}
    		
    	cout << "\nThe String After: " << theString << endl;
    	
        return 0;
    }
    
    spentak AKA Mark Price
     
  16. aaron_yox

    aaron_yox New Member

    Joined:
    Jun 30, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Simple C++ coding

    I am a UAT student, I am taking a C++ programming class. We're supposed to post something that we've found to be helpful to us.

    What I've found helpful is not to just follow other coding and not to just read about programming. It tends to help a lot to write your own code. If you tend to just write down other code from someone else, copy it, or just read about it you won't learn as much as you would actually doing the code and creating a program that you did on your own. It's also good to post a snippet online to get some feedback so you know different ways of doing a simple code. Like for example lets do "Hello World".

    To make sure you stop the window from closing right away, making it really hard to read what you have in the window, there are different ways of going through with this.

    example 1:

    Code:
    [COLOR=blue]#include[/COLOR] [COLOR=red]<iostream>[/COLOR]
     
    [COLOR=blue]using namespace[/COLOR] std;
     
    [COLOR=blue]int[/COLOR] main()
    {
     
           cout << [COLOR=red]"Hello World[SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]\nPress enter key to continue...[/COLOR][/SIZE][/COLOR][/SIZE]"[/COLOR] << endl;
           cin.get();
           [COLOR=blue]return[/COLOR] 0;
    }
    
    example 2:

    Code:
    [COLOR=blue]#include[/COLOR] [COLOR=red]<iostream>[/COLOR]
     
    [COLOR=blue]using namespace[/COLOR] std;
     
    [COLOR=blue]int[/COLOR] main()
    {
     
          cout << [COLOR=red]"Hello World"[/COLOR] << endl;
          system([COLOR=red]"PAUSE"[/COLOR]);
          [COLOR=blue]return[/COLOR] 0;
    }
     
    
    using namespace std is something helpful for less code. This makes it so that you don't have to type in std::cout every time you need that specfic code.

    int main() you will see on every code you see. Every code has a main to store the "Main" program in.

    cout lets you write a line to tell the user something of importance or instructions or something else.

    \n in the " " writes on the next line like pressing enter in a word document.

    endl is the end of the line you are writing on.

    system("PAUSE") is something you can do to have the program pause where it is at and wait untill the user presses any key.

    cin is retriving user input and the get() is getting that input. So the window doesn't close because it is waiting to get input from the user. By pressing enter it goes to the rest of the code.


    There is two examples of how to stop the window from closing. So you see code can have different ways of being put in but also sometimes how you put the code in depends how well your program will run. Like some games that come out tend to run slow but if the code would be changed so that it would make the game (program) run smoother it would be much better.

    I hope this helps and makes some newer programmers more intreged to start programming more.

    Also if we wanted to have the user input some value then have it appear on the window it would look something like this.

    Code:
    [COLOR=blue]#include[/COLOR] [COLOR=red]<iostream>[/COLOR]
     
    [COLOR=blue]using namespace[/COLOR] std;
     
    [COLOR=blue]int[/COLOR] main()
    {
         [COLOR=blue]int[/COLOR] x;
         cout << [COLOR=red]"Please enter in a value: "[/COLOR] << endl;
         cin >> x;
         cout << [COLOR=red]"\n\n"[/COLOR] << [COLOR=red]"Here is your entered value: "[/COLOR] << x << endl;
         system([COLOR=red]"[/COLOR][COLOR=red]PAUSE"[/COLOR]);
         [COLOR=blue]return[/COLOR] 0;
    }
     
    
     
  17. NateSwanson

    NateSwanson New Member

    Joined:
    Aug 3, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Aaron,

    Hello! I know we know each other from other classes (and we probably both know Mark too), but for sake of the assignment: I am another UAT student. It seems that you, Mark, and I all had the same assignment for our C++ Programming II course.

    Now then, you are right in that the expression using namespace std; will save you from having to use as much code. However, there is another option still instead of having to type std::cout at the beginning of every line where you need to output text. You can also use the compiler directive:

    Code:
    using std::cout;
    As an added benefit, I think (can anyone confirm?) that using the directive using std::cout; instead of using namespace std; will also save your program a small amount of memory because the compiler only has to include the specific instructions for how to implement cout into your program, rather than having to add the entire std library. This might not matter on small programs like our assignments, but I have a feeling that it is an important concept in larger programs where efficient use of memory can be an issue. Otherwise, why would I have seen so many people using just using std::cout; in example code rather than the entire using namespace std; version? (Can anyone answer this one too?)


    One other thing too, Aaron. system("PAUSE") is indeed a way of pausing the program, but it is dependent on the operating system having a console command called pause available to the user. I don't know if Macs or UNIX/Linux/etc has such a command built-in. But if they don't, then system("PAUSE") won't work. However, I do have a solution that will work across all platforms that I built into my own simple library:

    Code:
    void pause()
    {
        // Vars
        char *inputtedText = new char[1]; // std console input line = 80 chars max
        *inputtedText = '\0'; // default to empty
    
        // Display pause msg
        cout << "\nPress enter to continue...";
    
        // read new text into istream with getline
        istream & is = cin.getline(inputtedText, 1);
    
    } // end pause
    Then, after defining that function wherever best suits you to do so (I put mine in a separate file that contains my own personal library of often used functions), simply call the function wherever it is needed with a simple one line function call as follows:

    Code:
    pause();
    Hope that helps! See you around online! Good luck in the rest of your courses!
     
  18. akashtyagi36

    akashtyagi36 New Member

    Joined:
    Jan 6, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hey rght now am studying in 12 with c++. i have gr8 interest in this.
    now am facing problem in stack,queue,linked list and arrays.
    would you help me?
    reply me on akashtyagi36@yahoo.com
    pls pls help if u can and pls reply
     
  19. jorden

    jorden New Member

    Joined:
    Jan 10, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://topclassifiedsoftware.com
    Thanks for the information. This information is really helpful for me.
     
  20. ssaikaruna

    ssaikaruna New Member

    Joined:
    Apr 11, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi
    I want video tutorials for C,C++,C#,JAVA,.Net.
    Can anyone help me to get all these video tutorials pls.
    Thank u
    K.Sujatha
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice