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.
(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++.
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.
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.
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.
Huh? I use TC almost everyday in college, and seeing output in it is damn easy shabbir. What vanishing screens are you talking about?
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
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...