Addition of 3 array using c++

c_user's Avatar, Join Date: Aug 2009
Contributor
Good morning Seniors and hi to all frds..


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

please specify your valuable comments

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 shabbir; 23Aug2009 at 14:17.. Reason: Code blocks
rajeev_kumar like this
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
(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++.
0
mayjune's Avatar, Join Date: Jun 2009
Invasive contributor
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by mayjune View Post
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.
0
mayjune's Avatar, Join Date: Jun 2009
Invasive contributor
Quote:
because compiling in TC is not easy
Not Easy? What makes you say that? :O
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Seeing the output and how to handle the vanishing screens to start with.
0
mayjune's Avatar, Join Date: Jun 2009
Invasive contributor
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?
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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.
0
mayjune's Avatar, Join Date: Jun 2009
Invasive contributor
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...