Program to add two numbers by using classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sardana
    New Member
    • Nov 2007
    • 1

    #1

    Program to add two numbers by using classes

    [code=cpp]
    class class1
    {
    public : void sum1(int,int);
    };

    void class1::sum1(c, d)
    {
    int c,d;
    int sum;
    sum=c+d;
    cout<<"sum="<su m;
    }
    void main()
    {
    int a=1,b=2;
    class1 p;
    p.sum1(a,b);
    getch();
    }[/code]

    Check errors in it and reply
    Last edited by Frinavale; Nov 16 '07, 02:53 PM. Reason: Added [code] tags
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    There are a few errors in it that I can see, but I'm not here to do your work for you. I'm here to help you understand it, so you can do it yourself.

    With that in mind, what did you get? What do you think are the errors in there? (Hint: running this through a compiler will probably help show errors...)

    Comment

    • meetharry19
      New Member
      • Nov 2007
      • 7

      #3
      u can do this by declaring datamembers in class only and then used these data members in the member funtion to get the desired result.
      there few other errors in code,see by your ownself.

      Comment

      • mostafa110
        New Member
        • Oct 2007
        • 6

        #4
        Dear,
        You must type blew code instead of your code:
        [code=cpp]
        class class1
        {
        public : void sum1(int,int);
        };

        void class1::sum1(in t C,int D) //Note here
        {
        int sum;
        sum=C+D;
        cout<<"sum="<su m;
        }
        void main()
        {
        int a=1,b=2;
        class1 p;
        p.sum1(a,b);
        getch();
        }[/code]

        Comment

        Working...