Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
546 views
in Object Oriented Programming with C++ by (49.3k points)
closed by

Write the output of the following program.

#include

using namespace std;

class simple

{

private:

int a, b;

public:

simple() //default constructor

{

a = 0; b = 0;

cout << “\n default constructor” << endl;

}

int getdata();

};

int simple :: getdata()

{int tot;

cout << “\n Enter two values”; cin >> a >> b;

tot = a + b; return tot;

}

int main()

{

int sum=0; simple s1[3];

cout << “\n\t\tObject 1 with both values \n”;

for (int i=0;i<3;i++)

sum+=s 1 [i]. getdata();

cout << “\nsum of all object values is” << sum;

return 0;

}

1 Answer

+1 vote
by (54.9k points)
selected by
 
Best answer

Output:

default constructor

default constructor

default constructor

Object 1 with both values

Enter two values 10 20

Enter two values 30 40

Enter two values 50 50

sum of all object values is 200

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...