Something With Enum and Structures
Code::
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
enum class MonsterType
{
Ogre,
Dragon,
Orc,
Giant_Spider,
Slime,
};
struct Minfo
{
MonsterType type;
string name;
int health;
};
string gMTS(Minfo m)
{
if(m.type==MonsterType::Dragon)
{
return "Dragon";
}
if(m.type==MonsterType::Giant_Spider)
{
return "Giant Spider";
}
if(m.type==MonsterType::Ogre)
{
return "Ogre";
}
if(m.type==MonsterType::Orc)
{
return "Orc";
}
if(m.type==MonsterType::Slime)
{
return "Slime";
}
return "Unknown";
}
void pM(Minfo m)
{
cout<<"This "<<gMTS(m)<<" is named "<<m.name<<" and has "<<m.health<<" health"<<endl;
}
int main()
{
Minfo o={MonsterType::Ogre,"Torgo",189};
Minfo d={MonsterType::Dragon,"sabertooth",1200};
Minfo gs={MonsterType::Giant_Spider,"Disting",789};
Minfo s={MonsterType::Slime,"jelly",245};
pM(o);
pM(d);
pM(s);
pM(gs);
}
Output::
This Ogre is named Torgo and has 189 health
This Dragon is named sabertooth and has 1200 health
This Slime is named jelly and has 245 health
This Giant Spider is named Disting and has 789 health
Process returned 0 (0x0) execution time : 0.036 s
Press any key to continue.
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন