C++ Programming

Object Array

C plus plus example for sum of object array

11/19/2019
0 views
object-array.cppCPP
#include<iostream>
using namespace std;

class array {
	int x, y;
	
	public:
		array(int a, int b) {
			x = a;	y = b;
		}

		inline int getX() {
			return x;
		}

		inline int getY() {
			return y;
		}
};


int main() {

	/* Declearation and initialization of two dimentional array objects */
	array a[2][2] = {array(1,2), array(3,4), array(5,6), array(7,8)};
	array b[2][2] = {array(4,4), array(4,4), array(4,4), array(4,4)};
	cout << "After Sum:" << endl;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++)
			cout << a[i][j].getX() + b[i][j].getX() << "\t" << a[i][j].getY() + b[i][j].getY() << endl;

	return 0;
}


/* Output */
After Sum:
56
78
910
1112
cppobject arraysum of object arrayc plus plus

Related Examples