1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Addition of 3 array using c++

Discussion in 'C++' started by c_user, Aug 23, 2009.

  1. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    Good morning Seniors and hi to all frds..;)


    this is my first thread and i m writing on the addition of the 3 array...:shy:
    I like programming and i will be posting many in near future....

    please specify your valuable comments :p

    Code:
    #include<iostream.h>
    #include<conio.h>
    class demo1;
    class demo2;
    class demo
    {
     private:
     int a[5];
     public:
     void getdata();
     friend demo2 sum(demo d,demo1 d1,demo2 d2);
    };
    void demo::getdata()
    {
      cout<<"enter the elements for first array"<<endl;
      for(int i=0;i<5;i++)
      cin>>a[i];
    }
    class demo1
    {
           private:
     int b[5];
     public:
     void getdata();
     friend demo2  sum(demo d,demo1 d1,demo2 d2);
    };
    void demo1::getdata()
     {
      cout<<"enter the elements for second array"<<endl;
      for(int i=0;i<5;i++)
      cin>>b[i];
     }
    class demo2
    {
     private:
     int c[5],s[5];
     public:
     void getdata();
     friend demo2 sum(demo d,demo1 d1,demo2 d2);
     void show();
    };
    void demo2::getdata()
     {
      cout<<"enter the elements for third array"<<endl;
      for(int i=0;i<5;i++)
      cin>>c[i];
     }
    void demo2::show()
     {
      cout<<"sum is"<<endl;
      for(int i=0;i<5;i++)
       cout<<s[i]<<endl;
     }
    demo2 sum(demo d,demo1 d1,demo2 d2)
    {
     for(int i=0;i<5;i++)
      d2.s[i]=d.a[i]+d1.b[i]+d2.c[i];
      return d2;
    }
    void main()
    {
     clrscr();
     demo d;
     demo1 d1;
     demo2 d2;
     d.getdata();
     d1.getdata();
     d2.getdata();
     d2=sum(d,d1,d2);
     d2.show();
     getch();
    }
    

    thanking u for the valuable comments. have a good day.
     
    Last edited by a moderator: Aug 23, 2009
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    (1) Please post your code inside [noparse]
    Code:
    ...
    [/noparse].
    (2) Post such tutorials in the "Articles" section and not "Queries .." section.
    (3) You seem to be using Turbo C++ which is out-dated. Switch to ANSI/ISO C++.
     
  3. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    817
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    Its not his fault that he's using TC. Its our education systems fault. Even i am stuck with TC thanks to my college. But yes, since i started using Code Blocks (which is ANSI C standard) i realized how low TC is...
    Even i would recommend you start switching over to Code Blocks.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    I would not suggest you to do the switching till you know how to handle both because compiling in TC is not easy. I remember my old days where I had hard time seeing the output. Knowing TC is your task and doing better things should be your hobby.
     
  5. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    817
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    Not Easy? What makes you say that? :O
     
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Yeah, why is compiling in TC not easy ???
    I don't think the compilation process in TC is very much different than ANSI C.

    > Knowing TC is your task and doing better things should be your hobby.
    Yeah, I perfectly agree. :)
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Seeing the output and how to handle the vanishing screens to start with.
     
  8. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    817
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    Huh? I use TC almost everyday in college, and seeing output in it is damn easy shabbir. What vanishing screens are you talking about?
     
  9. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Nope, shabbir is right.

    After the execution, the output window "vanishes".
    So, you have to insert a getch() / getchar() or whatever before return 0; which was an extra pain, apart from writing the main program. :p
     
  10. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    817
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    Shabbir, trust me if TC was confusing, Teachers will be the first one to drop it. I asked one of my teachers why we still use TC, she said just coz teachers want to be comfortable. They don't want to learn something new, something they don't know already.
    And that vanishing screen is known by people. Using Code Blocks can be confusing for a newbie who jumps on to it.

    I just hope TC gets completely obsolete even from schools/colleges...
     
  11. rajeev_kumar

    rajeev_kumar New Member

    Joined:
    Aug 25, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    thank u it is a gud one...
     

Share This Page