array of object in c++

Arrays of the object: In c++, an array of the object is possible. Let’s see one example. #include<iostream>Using namespace std;Class display{Int i;Public:Void set(int j){i=j; //Constructor}Void get(){Return i;}};Int main(){Display ob[3];Int i;For(i=0;i<3;i++){Ob[i].set(i+1);}For(i=0;i<3;i++){Cout<<ob[i].get()<<”t”;}Return 0} Output 1 2 3 If a class defines a parameterized constructor, we initialize each object in an array by specifying an initialization list. The … Read more array of object in c++

addition of two numbers in c++ | Using Class

addition of two numbers in c++, Using Class: #include<iostream>using namespace std;class addition{int a,b,sum;public:void read(); // Read given datavoid calculate(); // Calculate the 2 numbersvoid print(); // print the number that have been clalculated}; void addition::read(){cout<<“enter the two numbersn”;cin>>a>>b;} void addition::calculate(){sum=a+b;} void addition::print(){cout<<“sum oft”<<a<<” andt “<<b<<“tist”<<sum;} int main(){addition ob1;ob1.read();ob1.calculate();ob1.print();} Output: Click below Link For Download Executable … Read more addition of two numbers in c++ | Using Class