Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Addition of 3 array using c++ (http://www.go4expert.com/forums/addition-3-array-using-cpp-t19133/)

c_user 23Aug2009 12:20

Addition of 3 array using c++
 
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.

SaswatPadhi 23Aug2009 14:23

Re: Addition of 3 array using c++
 
(1) Please post your code inside [code]...[/code].
(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++.

mayjune 23Aug2009 14:56

Re: Addition of 3 array using 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.

shabbir 23Aug2009 16:01

Re: Addition of 3 array using c++
 
Quote:

Originally Posted by mayjune (Post 55806)
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.

mayjune 23Aug2009 16:18

Re: Addition of 3 array using c++
 
Quote:

because compiling in TC is not easy
Not Easy? What makes you say that? :O

SaswatPadhi 23Aug2009 19:55

Re: Addition of 3 array using c++
 
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. :)

shabbir 24Aug2009 09:03

Re: Addition of 3 array using c++
 
Seeing the output and how to handle the vanishing screens to start with.

mayjune 24Aug2009 16:12

Re: Addition of 3 array using c++
 
Quote:

Seeing the output and how to handle the vanishing screens to start with.
Huh? I use TC almost everyday in college, and seeing output in it is damn easy shabbir. What vanishing screens are you talking about?

SaswatPadhi 24Aug2009 19:24

Re: Addition of 3 array using c++
 
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

mayjune 24Aug2009 19:29

Re: Addition of 3 array using c++
 
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...


All times are GMT +5.5. The time now is 19:32.