pgrm_003.cpp
Problem Statement
pgrm_003.cpp
class - object
Source Code
cpp
#include<iostream>
using namespace std;
class person {
public:
int age;
string name;
void setName(string n) {
name = n;
}
void setAge(int a) {
age = a;
}
};
int main() {
person p;
p.setName("Amit Dutta");
p.setAge(19);
cout << "Name: " << p.name << endl;
cout << "Age: " << p.age;
return 0;
}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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
● Author - Amit Dutta · Updated - 29 Jun 2026