Created
February 20, 2019 04:16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Fighters { | |
public: | |
string model; | |
int Health; | |
int Strength; | |
void add_stealth(); | |
Fighters() { | |
model = "Default Model"; | |
Health = 50; | |
Strength = 50; | |
Stealth = 0; | |
} | |
void printinfo(); | |
private: | |
int Stealth; | |
}; | |
int main() | |
{ | |
Fighters Default; | |
Fighters* pDefault = &Default; | |
pDefault->printinfo(); | |
//Default.printinfo(); less perferred way to access to functions in class | |
Fighters F16; | |
Fighters* pF16 = &F16; | |
pF16->model = "F16_TG"; | |
pF16->Health = 100;//Heath is updated but Strength is default | |
pF16->printinfo(); | |
Fighters F35; | |
Fighters* pF35 = &F35; | |
pF35->model = "F35_NG"; | |
pF35->Health = 100; | |
pF35->Strength = 80; | |
//pF35->Stealth = 100;//Stealth is a private variable in the Fighters class | |
pF35->add_stealth();//public function that have access to private variable Stealth | |
pF35->printinfo(); | |
getchar(); | |
return 0; | |
} | |
void Fighters::printinfo() { | |
cout << "\nFighter: " << model << endl; | |
cout << "Health is " << Health << endl; | |
cout << "Strength is " << Strength << endl; | |
cout << "Stealth is " << Stealth << endl; | |
} | |
void Fighters::add_stealth() { | |
Stealth = Stealth + 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment