Professional Documents
Culture Documents
20 Objetos
20 Objetos
INTRODUCCION
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
QUE ES LA POO
Atributos
QUE ES LA POO
Atributos
QUE ES LA POO
Atributos
HERENCIA
HERENCIA
HERENCIA
HERENCIA
ENCAPSULACION
Atributos
ENCAPSULACION
ENCAPSULACION
ENCAPSULACION
POLIMORFISMO
POLIMORFISMO
Objects created from the class
// Declare Classes and Objects
#include <iostream>
#include <string>
#include <vector>
return 0;
}
Antes del main
using namespace std;
class Player {
// attributes
string name {"Player"};
int health {100};
int xp {3};
// methods
void talk(string);
bool is_dead();
};
int main()
Player object
{
Player frank;
Player hero;
return 0;
}
Player frank;
Player hero;
delete enemy;
return 0;
}
Debug again
int main()
Player frank;
Player hero;
array
Player players[] {frank, hero};
vector<Player> player_vec{ frank }; Vector
player_vec.push_back(hero);
delete enemy;
return 0;
}
Debug again
class Player {
// attributes
string name{ "Player" };
int health{ 100 };
int xp{ 3 };
// methods
void talk(string);
bool is_dead();
};
class Account {
// attributes
string name{ "Account" };
double balance{ 0.0 };
// methods
bool deposit(double);
bool withdraw(double);
};
int main() {
int main() {
Account frank_account;
Account jim_account;
Player frank;
Player hero;
Debugging again
// Declare Classes and Objects
#include <iostream>
#include <string>
#include <vector>
class Player {
// attributes
string name{ "Player" };
int health{ 100 };
int xp{ 3 };
// methods
void talk(string);
bool is_dead();
};
class Account {
// attributes
string name{ "Account" };
double balance{ 0.0 };
// methods
bool deposit(double);
bool withdraw(double);
};
int main() {
Account frank_account;
Account jim_account;
Player frank;
Player hero;
delete enemy;
return 0;
}
#include <iostream>
#include <string>
class Player {
public:
// attributes
string name;
int health;
int xp;
// methods
void talk(string text_to_say);
bool is_dead();
};
class Account {
public:
// attributes
string name;
double balance;
// methods
bool deposit(double bal);
bool withdraw(double bal);
};
int main() {
return 0;
}
int main() {
Player frank;
frank.name = "Frank"; Atributos
frank.health = 100;
frank.xp = 12;
frank.talk("Hi there"); Métodos
class Player {
public:
// attributes
string name;
int health;
int xp;
// methods
void talk(string text_to_say) { cout << name << " says " << text_to_say << endl;
}
bool is_dead();
};
Debug…
Player frank;
frank.name = "Frank";
frank.health = 100;
frank.xp = 12;
frank.talk("Hi there");
return 0;
Debug….
class Account {
public:
// attributes
string name;
double balance;
// methods
bool deposit(double bal) {return balance += bal; cout << "In deposit" << endl; }
bool withdraw(double bal) {return balance -= bal; cout << "In withdraw" << endl;
}
};
int main() {
Account frank_account;
frank_account.name = "Frank's account";
frank_account.balance = 5000.0;
frank_account.deposit(1000.0);
frank_account.withdraw(500.0);
// Accessing Class Members
#include <iostream>
#include <string>
class Player {
public:
// attributes
string name;
int health;
int xp;
// methods
void talk(string text_to_say) { cout << name << " says " << text_to_say << endl; }
bool is_dead();
};
class Account {
public:
// attributes
string name;
double balance;
// methods
bool deposit(double bal) {return balance += bal; cout << "In deposit" << endl; }
bool withdraw(double bal) {return balance -= bal; cout << "In withdraw" << endl; }
};
int main() {
Account frank_account;
frank_account.name = "Frank's account";
frank_account.balance = 5000.0;
frank_account.deposit(1000.0);
frank_account.withdraw(500.0);
Player frank;
frank.name = "Frank";
frank.health = 100;
frank.xp = 12;
frank.talk("Hi there");
return 0;
}
// Access Modifers
#include <iostream>
#include <string>
class Player {
private:
// attributes
string name {"Player"};
int health = 100;
int xp;
public:
// methods
void talk(string text_to_say) { cout << name << " says " << text_to_say << endl; }
bool is_dead();
};
int main() {
Player frank;
// frank.name = "Frank";
// cout << frank.health << endl;
frank.talk("Hello there"); Compilar…
return 0;
}