Question

In: Computer Science

I need the code for following in C++ working for Visual studio please. Thanks Use a...

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

  • int health
  • int level
  • string playerName
  • double gameComplete
  • bool isGodMode

Create the 2 functions that will do the following:
1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct

  • health= 100
  • level= 1
  • playerName = aPlayerName
  • gameComplete = 0
  • isGodMode = false

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);

Solutions

Expert Solution

#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


Related Solutions

Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
C# I need working code please Write a console application that accepts the following JSON as...
C# I need working code please Write a console application that accepts the following JSON as input: {"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "ZoomIn", "label": "Zoom In"}, {"id": "ZoomOut", "label": "Zoom Out"}, {"id": "OriginalView", "label": "Original View"}, null, {"id": "Quality"}, {"id": "Pause"}, {"id": "Mute"}, null, {"id": "Find", "label": "Find..."}, {"id": "FindAgain", "label": "Find Again"}, {"id": "Copy"}, {"id": "CopyAgain", "label": "Copy Again"}, {"id": "CopySVG", "label": "Copy SVG"}, {"id": "ViewSVG", "label": "View...
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following three arrays: int array1 [] = { 3, 4, 2, 1, 7}; float array2 [] = {0.3, 0.1, 5.5, 4.3, 7.8}; char array3 [] = {‘c’, ‘d’, ‘a’, ‘b’, ‘f’};                                     Develop a driver function to print out the sorted results and put the screenshot into the word document. Note that you have to use qsort( ) provided by Visual Studio. What is the...
How do I run javscript console on Visual Studio code? Please give exact detail for thumbs...
How do I run javscript console on Visual Studio code? Please give exact detail for thumbs up. I just downloaded VS code.
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
I need a working MATLAB CODE for the Gram Schimdt process Please give the code fast...
I need a working MATLAB CODE for the Gram Schimdt process Please give the code fast Its urgent The code must run on any matrix given It should be a generic code Dont answer any wrong code or else i will badly dislike
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT