c++ programming

This is a discussion on c++ programming within the C++ Programming forums, part of the General Programming Boards category; hello everybody, how invokes the main() function in c/c++ programmes...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    17

    Thumbs up c++ programming

    hello everybody,
    how invokes the main() function in c/c++ programmes
    srinu

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Each program can have only one function called main(). Each function also needs one of the standard header files, iostream, fstream or stdlib, if you are going to be able see results on the screen. main() is a function with a few special properties. First it needs no prototype and no definition. On the other hand it does need a return type, which should be type int, and it does need arguments, although the compiler will provide default arguments if you don't provide them explicitly. To invoke main() just do this:


    Code:
    #include <iostream.h>//or whatever version your compiler uses
    
    int main()
    {
      cout << "You did it.";
      return 0;
    }

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    7

    Smile

    i have algoritm and i want to check the number of comparations did, if you can help, send the message please, or code to build in c++, thank you

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Please post your algorithm, we can't help you when we don't know what you're doing.

    Small example of counting comparisons in a while-loop.

    Code:
    nr_of_comparisons = 0;
    while (a != b) // the comparison
    {
        nr_of_comparisons++;
        ....
    }

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    7

    Smile Help

    thank you for your help, my algoritm is the heap sort with numbers, and i want to now how many comparations do the algoritm with c++ code , thank you
    (code)
    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <stdio.h>
    #include <iomanip.h>
    #define n 100
    void heapsort(int[]);
    int i;
    void main()
    {
    int x[n];clrscr();
    for(i=0;i<n;i++)
    {
    x[i]=rand()%99000000+10000000;
    }
    gotoxy(23,1);
    cout<<"NUMEROS DE CONTROL SIN ORDENAR";
    gotoxy(23,2);
    cout<<"* Demostracion de Heapsort *\n\n";

    for(i=0;i<n;i++)
    {
    cout<<setw(10)<<x[i];
    }
    cout<<"\n";
    getch();clrscr();
    heapsort(x);
    }
    //------------------------------------------------------------------------------
    void heapsort(int x[])
    {
    int i,elt,s,f,ivalue;
    for(i=0;i<n;i++)
    {
    elt=x[i];
    s=i;
    f=(s-1)/2;
    while((s>0)&&(x[f]<elt))
    {
    x[s]=x[f];
    s=f;
    f=(s-1)/2;
    }
    x[s]=elt;

    }
    for(i=n-1;i>0;i--)
    {
    ivalue= x[i];
    x[i]=x[0];
    f=0;
    /*s=largeson(0,i-1)*/
    if (i==1)
    s=-1;
    else
    s=1;
    if((i>2)&&(x[2]>x[1]))
    s=2;
    while((s>=0)&&(ivalue < x[s]))
    {
    x[f]=x[s];
    f=s;
    /*s=largeson(f,i-1)*/
    s=2*f+1;
    if((s+1<=i-1)&&(x[s]<x[s+1]))
    s=s+1;
    if (s>i-1)
    s=-1;
    }/*fin del while*/
    x[f]=ivalue;
    }/*fin del for*/
    /*fin del heapsort*/
    //------------------------------------------------------------------------------
    gotoxy(23,1);
    cout<<"NUMEROS DE CONTROL ORDENADOS\n\n";
    for(i=0;i<n;i+=100)
    for(s=0;s<n;s++)
    {
    cout<<setw(10) <<x[i+s];
    }
    cout<<"\n";
    getch();
    }

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Angry Why don't you use the code tage

    Can you please use the code tage :
    if you don't know tell me I will teach you...
    C++
    The best

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Red face Here how to do it...

    You type in this ...

    with no spacing ..... just type CODE inside [] and thin when you are done with your code .. type in "/CODE" in "[]"
    remeber no spacing

    [CODE]
    cin>>
    Code:
    ;
    cout<< " this is the way"; 
    cin>>[:p/CODE];
    
    cout<< ":rolleyes:  I just learned that all yesterday....";
    C++
    The best

  8. #8
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    And also check the "Don't Display Smilies" box just above the send button.

Popular pages Recent additions subscribe to a feed

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