classes and member functions

Hello , I have made a simple program.Can any one please tell me how to make the same program using class and member functions ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
int main()
{
 int r1,r2,r3,r4,r5,r6,r7,r8,r9;
 int m1,m2,m3,m4,m5,m6,m7,m8,m9;
 cout<<"enter the matrix elements ";
 cin>>r1>>r2>>r3>>r4>>r5>>r6>>r7>>r8>>r9;
 cout<<"enter the elements of second matrix ";
 cin>>m1>>m2>>m3>>m4>>m5>>m6>>m7>>m8>>m9;
 
 
  int matrix1[3][3] = {
    {r1,r2,r3},
    {r4,r5,r6},
    {r7,r8,r9}
  };
  int a,b;
  for(b = 0; b < 3; ++b)
  {
    for(a = 0; a < 3; ++a)
      cout << matrix1[b][a];
 
    cout<<endl;
  }
  cout<<endl;
 int matrix2[3][3] = {
    {m1,m2,m3},
    {m4,m5,m6},
    {m7,m8,m9}
  };
  int c,d;
  for(d = 0; d < 3; ++d)
  {
    for(c = 0; c < 3; ++c)
      cout << matrix1[d][c];
 cout<<endl;
 
 
   
  }
 
cout<<endl;
int matrix[3][3] = {
    {r1+m1,r2+m2,r3+m3},
    {r4+m4,r5+m5,r6+m6},
    {r7+m7,r8+m8,r9+m9}
  };
  int x,y;
  for(y = 0; y < 3; ++y)
  {
    for(x = 0; x < 3; ++x)
      cout <<matrix[y][x]<<"|";
    cout << endl;
  }
  return 0;
}
Ok... What you basically want to make its a sum of matrices that the user inputs them..., right.

Well you should make a .h with the prototypes of the class, .cpp defining the prototypes of the class and App.h with the functions of the App.cpp and App.cpp with the main, object and variables to use.

You need 2 data members, lets say matrix1 and matrix2 both long(so the range its larger)
then set and get for each one. One function that sum both matrices.

How Can I make it as an actual program ?
Last edited on
lol I didn't meant .app files, I meant App.h and App.cpp where App its the avrebation of Application, where the main goes...

Example:

AppMatrixMain.cpp = Where main goes.

AppMatrix.h = funtions prototypes of AppMatrix.cpp goes, (funtions that prints Welcome and Goodbye messages, Input and output messages , any function related to the main rather than the class goes here.)

AppMatrix.cpp = were Function Prototypes of the AppMatrix.h are defined.

matrix.h = Functions Prototypes of the Class. Data Members goes here.

matrix.cpp = Definition of the functions Prototypes of the Class and some other Functions that are related to the class rather than the main. Member Functions goes here.

If you built a program as this, it would be really easy to read and to implement, since everything its separated, you can read it more clearly.

Last edited on
Topic archived. No new replies allowed.