C++ Godzilla Class Fight
#include<iostream> #include <stdlib.h> #include <time.h> using namespace std; class Godzilla { string name; double power,health; public: //default constructor Godzilla() { name=" Godzilla"; /* initialize random seed: */ srand (time(NULL)); //health to a random value between [50, 100] health=rand()%51+50; //power to a random value between [10, 25]. power=rand()%16+10; } // parameterized constructor Godzilla(string x,double h,double p) { name=x; /* initialize random seed: */ srand (time(NULL)); if(h>0) health=h; else //health to a random value between [50, 100] health=rand()%51+50; if(p>0) power=p; else //power to a random value between [10, 25]. power=rand()%16+10; } void dispaly() { cout<<"Name is "<<name<<endl; cout<<"Health: "<<health<<endl; cout<<"Power: "<<power<<endl; } }; int main() { double p,h; //prompt the user to provide the health and power of Mechagodzilla cout<<"Enter health of Mechagodzilla: "; cin>>h; cout<<"Enter power of Mechagodzilla: "; cin>>p; //create two Godzilla objects - one named Godzilla and the other named Mechagodzilla. Godzilla Godzilla,Mechagodzilla("Mechagodzilla",h,p); //output the health & power of Godzilla and Mechagodzilla. Godzilla.dispaly(); Mechagodzilla.dispaly(); return 0; }