#include <iostream>
#include <string>
using namespace std;
class User {
private:
int id;
string password;
public:
string username;
User(int id) {
this->id = id; // current is being stored to parameter id (right side is parameter) and left side is an object.
}
// getter
string getPassword() {
return password;
}
//setter
void setPassword(string password) {
this-> password = password;
}
};
int main() {
// Object
User user1(101);
user1.username = "apnacollege";
user1.setPassword("abcd"); // always getting this wrong
// correct is user1.setPassword("abcd");
// not user.setPassword = "abcd"; for strings , mistake noted for next time!
cout << "username : " << user1.username << endl;
cout << "password : " << user1.getPassword() << endl;
return 0;
}
No comments:
Post a Comment