Skip to content

Instantly share code, notes, and snippets.

@peta909
Created February 20, 2019 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peta909/be3d7045255a77007c957023255e54d8 to your computer and use it in GitHub Desktop.
Save peta909/be3d7045255a77007c957023255e54d8 to your computer and use it in GitHub Desktop.
#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