-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethod function (types of function).cpp
More file actions
49 lines (40 loc) · 1.17 KB
/
Copy pathMethod function (types of function).cpp
File metadata and controls
49 lines (40 loc) · 1.17 KB
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
#include <iostream>
#include <string>
using namespace std;
class Person { //person---------class name
private:
int age;
string name;
string country;
public:
void setAge(int a) { // Setter function for the age
age = a;
}
int getAge() { // Getter function for retrieving the age
return age;
}
void setName(const string & n) { // Setter function for the name
name = n;
}
string getName() { // Getter function for retrieving the name
return name;
}
void setCountry(const string & c) { // Setter function for the country
country = c;
}
string getCountry() { // Getter function for retrieving the country
return country;
}
};
int main() {
Person p; //p---------object name
// Set the person's details using setter functions
p.setName("LAIBA");
p.setAge(25);
p.setCountry("PAKISTAN");
// Get and display the person's details using getter functions
std::cout << "Name: " << p.getName() <<endl;
std::cout << "Age: " << p.getAge() <<endl;
std::cout << "Country: " << p.getCountry() <<endl;
return 0;
}