Programming in C/C++

hasiwebmail

Member
Feb 27, 2007
501
52
0
Sri Lanka
hi guyss. that was my first post for elakiri.com. C++ kiyanne tikak complected language ekak. mama damma program eke C++ basics use wela thiyenne pointers witharai. other than that all the codes are based on WIN32 APIs . mamath hamadema danne na. eth danna tika kiyala dennum. kisma aulak na :D. Eth eka kohomada karanne kiyana eka oyagollo kiyanna. mokada mama me forum ekata aluth.


Welcome Bro.......
:yes::yes::yes::yes::yes::yes::yes:
 

Enigma_1

Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    meka maxa place ekak wage. thx machanla mawa sadarayen piligaththata. api okkoma set wela thiyena dewal bedagamu . mama kala programs keepyak thiyenwa. mama ewa explanations ekka hemita dannum
     

    hasiwebmail

    Member
    Feb 27, 2007
    501
    52
    0
    Sri Lanka
    //program to demonstrate dynamic allocation using new keyword
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    int *num;
    int len;
    cout<<"Enter the length of array";
    cin>>len;
    num=new int(len);
    for(int i=0;i<len;i++)
    {
    num=i;
    cout<<num<<"\t";
    }
    cout<<"\n";
    delete[] num;
    cout<<"Without assigning again ";
    cout<<"\n We get same output\n";
    num =new int(len);
    for(i=0;i<len;i++)
    {
    cout<<num<<"\t";
    }
    getch();
    }
    --------------------------------------------
    The output of the above program is:-
    Enter the length of array5
    0 1 2 3 4
    Without assigning again
    We get same output
    5 1 2 3 4

    using borland TC 3.0v
     

    hasiwebmail

    Member
    Feb 27, 2007
    501
    52
    0
    Sri Lanka
    //program to convert any infix expression to its post-fix form (BODMAS)
    #include "stdio.h"
    int top=-1;
    void main()
    {
    void push(char,char []);
    char pop(char []);
    int pref(char,char []);
    char as[20],fi[20],s[50];
    int y=0,i=0,j=0;
    printf("Enter a string infix :");
    gets(as);
    for(i=0;as!='\0';i++)
    {
    if(as>='a' && as<='z' || as>='A' && as<='Z')
    {
    fi[j]=as;
    j++;
    }
    else
    if(as=='+' || as=='-' || as=='/' || as=='*')
    {
    y=pref(as,s);
    if(y==0)
    {
    push(as,s);
    }
    else
    if (y==1)
    {
    while(y!=0)
    {
    fi[j]=pop(s);
    j++;
    y=pref(as,s);
    }
    push(as,s);
    }
    }
    }
    while(j<=i)
    {
    fi[j]=pop(s);
    j++;
    }
    puts(fi);
    }

    void push(char x,char s[])
    {
    top=top+1;
    s[top]=x;
    }

    char pop(char s[])
    {
    char x;
    x=s[top];
    top=top-1;
    return x;
    }

    int pref(char x,char s[])
    {
    if(x=='+' && s[top]=='*' || x=='+' && s[top]=='/' || x=='-' && s[top]=='+' || x=='-' && s[top]=='/' || x=='-' && s[top]=='*' || x=='*' && s[top]=='/')
    {
    return 1;
    }
    else
    return 0;
    }

    ------------------------------
    Tested using BorlandC++ 4.5v

    eg- input

    a+b

    output ab+

    input a-b/c

    output abc/-(operators shifted according to BODMAS proirity)
     

    hasiwebmail

    Member
    Feb 27, 2007
    501
    52
    0
    Sri Lanka
    /*possible combination program
    Enter String: 123 <- user enters
    and it prints,
    123
    321
    213
    132
    231
    312
    */

    //@hasi
    #include "stdio.h"
    #include "string.h"
    void posrot(char [],int);
    void permutate(char [],int);
    int main(void)
    {
    int n=0,m=0;
    char as[30];
    printf("Enter a string : ");
    gets(as);
    n=strlen(as);
    permutate(as,n);
    return 0;
    }

    void posrot(char as[],int pos)
    {
    int i=0;
    char temp;
    temp=as[0];
    while(i< pos)
    {
    as=as[i+1];
    i++;
    }
    as=temp;
    }

    void permutate(char as[],int n)
    {
    int l=0;
    for(l=1;l<=n;l++)
    {
    if(n!=2)
    {
    permutate(as,n-1);
    posrot(as,n-1);
    }
    else
    {
    for(l=1;l<=2;l++)
    {
    posrot(as,1);
    puts(as);
    }
    }
    }
    }
     

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    onna thwath pissu :rofl:code ekak thiyenawa. mechchara kal api dakala thibbe MSDOS wala colors na kiyala (e kiyanne only black and white) . me program eka DOS prompt eke text colors walin print karanawa.
    menna code eka

    Code:
    /*
    major colors are 
    FOREGROUND_RED,FOREGROUND_BLUE,FOREGROUND_GREEN
    BACKGROUND_BLUE,BACKGROUND_GREEN and BACKGROUND_RED
    you can create new colors by performing the bitwise operations on these colors 
    please note that the MSDOS is not based on RGB color scheme. So the MSDOS is 
    only support for 6 colors (as far as I know).
    
    FOREGROUND_INTENSITY - this increase the intensity of the text in the DOS screen
    BACKGROUND_INTENSITY - this will increae the intensity of the bcakground color of the DOS screen
    
    */
    
    
    #include <windows.h>
    #include <stdio.h>
    
    HANDLE hConsole;
    CONSOLE_SCREEN_BUFFER_INFO ScreenBufInfo;
    
    WORD colorWhite =BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED;
    
    //These constants are used to draw the lines 
    char line[] = {
                0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,
                0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,
                0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,
                0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0xDB,0x0A
              };
    
    void cPrintf(const char* szValue,WORD color);
    
    int main()
    {
        
        cPrintf("This is Red Color\n",FOREGROUND_RED);
        cPrintf("This is Blue Color\n",FOREGROUND_BLUE);
        cPrintf("This is Green Color\n",FOREGROUND_GREEN);
    
        printf("\n");
    
        cPrintf("This is Red with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_RED);
        cPrintf("This is Blue with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_BLUE);
        cPrintf("This is Green with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_GREEN);
        cPrintf("This is Yellow with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED);
        cPrintf("This is Green with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
        cPrintf("This is Purple with high intensity\n",FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED);
        
        printf("\n");
    
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_RED);
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_GREEN);
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED);
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
        cPrintf(line,FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED);
        
        printf("\n");
        cPrintf("This is Red Color with Background\n",FOREGROUND_RED|colorWhite);
        cPrintf("This is Blue Color with Background\n",FOREGROUND_BLUE|colorWhite);
        cPrintf("This is Green Color with Background\n",FOREGROUND_GREEN|colorWhite);
        printf("\n\n");
        system("pause");
        return 0;
    }
    
    
    void cPrintf(const char* szValue,WORD color)
    {
        // free the memeory for the struct
        ZeroMemory(&ScreenBufInfo,sizeof(ScreenBufInfo)); 
        //geting the handle of the console
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 
         // saving the original values of the console buffer
        GetConsoleScreenBufferInfo(hConsole,&ScreenBufInfo);
        //setting the new color
        SetConsoleTextAttribute(hConsole,color);
        //printing the value with new color
        printf(szValue);
        // resting the color to its normal values 
        SetConsoleTextAttribute(hConsole,ScreenBufInfo.wAttributes);
    }
    menna screen shot ekak
    colorli.jpg


    code eka comment karala thiyenna. eth first time APIS ekka deal karana kenek ta meka tikak amaru wei. onama problem ekak ahanna. ona support ekak dennum :D

    podi deyak kiyanna amathaka una. mama meka compile kale Visual studio 2005 eken. eth oyagollan ta anith IDEs unath use karanna puluwan. me program eka linux wala run karanna ba. windows OS eke witharai. Borland C++ compilers eken meka compile karanna puluwan weida kiyana eka gana num sure na. compilation errors awoth kiyanna
    http://www.microsoft.com/express/Downloads/
    me thiyenne Vs 2008/2010 Express editions download karaganna link ekak .
     
    Last edited:
    • Like
    Reactions: hasiwebmail

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    machanla C++ wala godak areas thiyenawa :yes:. for an Eg DirectX programing, Driver programing, win32API programing ....... . eth mama poddak hari danne win32API programing witharai. mama dannawa mama damma codes 2kama tiakak aul ewa kiyala. enisa mama hemita win32 API programing wala theories kiyala dennum. meka academic wise num echchara prayojanayak nathi wei. eth kawada hari final yr project eka hari ehemath nathnum real time commercial applications develop karanna awa dawasaka godak help ekak wei.:yes:
    basics mama mukuth karanne na. mokada speg eka karanawa ne. win32API basics karala api podi podi applications kattiyama set wela hadamu.

    machan la thawadayak mama OOP karanne na. godak welawata c++ walata wada C programing use wei mekedi. anith de thama mama kiyala denne MFC (Microsoft Foundation Classes) use karala GUI applications hadana hati neve. pure API use karala hadana hati. anith de thama mamath hamadema danne na:no:. mokda API 1000k ta wada thiyenawa MSDN eke document karala. enisa api okkoma set wela meka karamau. Issella mama 1st post ekak dannum. oya gollo hithanawa num meka use full wei kiyala kiyanna. ehema unoth mama hemita tika tika mama danna dewal tika kiyala dennum.mama waradi godak karai. oya gollo ewa pennala denna. ethakota api okkotama igena ganna puluwan. :D:D:D:D:D