In: Computer Science
I need the code for following in C++ working for Visual studio please. Thanks
Use a Struct to create a structure for a Player.
The Player will have the following data that it needs
maintain:
Struct Player
Create the 2 functions that will do the following:
1) initialize(string aPlayerName) which takes in a playername
string and creates a Player struct
then, and will return the Player Struct.
2) printStat(Player p) will output the individual elements of the
struct passed in.
From main, call the functions initialize and printStat in that
order.
Example:
Player p = initialize("Hulk");
printStat(p);
#include<iostream>
using namespace std;
struct Player{
int health;
int level;
string playerName;
double gameComplete;
bool isGodMode;
};
// initializing with default data
Player initialize(string name){
Player p;
p.health= 100;
p.level= 1;
p.playerName = name;
p.gameComplete = 0;
p.isGodMode = false;
return p;
}
//printing given struct data
void printStat(Player &p){
cout<<"Name : "<<p.playerName<<endl;
cout<<"Health : "<<p.health<<endl;
cout<<"Level : "<<p.level<<endl;
cout<<"Game Complete : "<<p.gameComplete<<endl;
cout<<"isGodMode : "<<p.isGodMode<<endl;
}
int main(){
Player p = initialize("Hulk");
printStat(p);
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
Please Like and Support me as it helps me a lot