Godzilla Class Pt. 2 C++
I have to continue building off of this class and do the following
I got help with the code below but could use some guidance as to how to finish this out. Any help would be appreciated
This is the code for the main.cpp
#include <iostream> #include "Godzilla.h" using namespace std; int main() { double health; double power; //prompt the user to input the health and power for Godzilla cout<< "Enter the health: " ; cin >> health; cout <<"Enter the power: " ; cin >> power; //calls the class Godzilla Godzilla, Mechagodzilla("Mechagodzila" , health, power); //outputs the health and power for the OG Zilla and Mechagodzilla cout << "Godzilaa: Health = " << Godzilla.health << ", Power = " << Godzilla.power << endl; cout << "Mechagodzilla: Health =" << Mechagodzilla.health << ", Power = " << Mechagodzilla.power << endl; return 0; }
This is what is in the Godzilla.h file
#include "Godzilla.h" #include<string> #include<iostream> #include<cstdlib> #include<ctime> using namespace std; class Godzilla { public: //the variables string name; double health; double power; //default constructor Godzilla(); //parameterized constructor Godzilla(string name, double health, double power); }; #endif //SET8_GODZILLA_H
And this is the code for Godzilla.cpp
#
include "Godzilla.h" #include<string> #include<iostream> #include<cstdlib> #include<ctime> using namespace std; Godzilla::Godzilla() { srand(time(0)); name = "Godzilla"; health = (rand() % 100) + 50; power = (rand() % 25) + 10; } Godzilla::Godzilla(string name, double health, double power) { if (health <= 0 ) { health = rand() % 100 + 50; } if(power <= 0){ power = rand() % 25 + 10; } }
//Godzilla.h file
#include<string>
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class Godzilla {
public:
//the variables
string name;
double health;
double power;
//default constructor
Godzilla();
//parameterized constructor
Godzilla(string name, double health, double power);
//setter functions
void setName(string str);
void setHealth(double hth);
void setPower(double power);
//getter functions
string getname() const;
double getHealth() const;
double getPower() const;
void greet(Godzilla &obj);
int attack(Godzilla &obj);
};
======================
//Godzilla.cpp file
#include "Godzilla.h"
Godzilla::Godzilla() {
srand(time(0));
name = "Godzilla";
health = (rand() % 100) + 50;
power = (rand() % 25) + 10;
}
Godzilla::Godzilla(string name, double health, double power)
{
this->name=name;
if (health <= 0 ) {
health = rand() % 100 + 50;
}
if(power <= 0){
power = rand() % 25 + 10;
}
}
//setter functions
void Godzilla::setName(string str)
{
name=str;
}
void Godzilla::setHealth(double hth)
{
health=hth;
}
void Godzilla::setPower(double pwr)
{
power=pwr;
}
//getter functions
string Godzilla::getname() const
{
return name;
}
double Godzilla::getHealth() const
{
return health;
}
double Godzilla::getPower() const
{
return power;
}
void Godzilla::greet(Godzilla &obj)
{
cout<<name<<" bows to
"<<obj.getname()<<endl;
}
int Godzilla::attack(Godzilla &obj)
{
cout<<name<<" attacks
"<<obj.getname()<<endl;
double Targethealth=obj.getHealth();
Targethealth-=power;
if(Targethealth < 0)
{
cout<<obj.getname()<<" has been
vanquished"<<endl;
//when -1 is sent then health of target decreased below 0
return -1;
}
obj.setHealth(Targethealth);
return 0;
}
=========================
//Main.cpp file
#include "Godzilla.h"
int main()
{
double health;
double power;
//prompt the user to input the health and power for
Godzilla
cout<< "Enter the health: " ;
cin >> health;
cout <<"Enter the power: " ;
cin >> power;
//calls the class
Godzilla Godzilla, Mechagodzilla("Mechagodzila" , health,
power);
//outputs the health and power for the OG Zilla and
Mechagodzilla
cout << "Godzilaa: Health = " << Godzilla.health
<< ", Power = " << Godzilla.power << endl;
cout << "Mechagodzilla: Health =" <<
Mechagodzilla.health << ", Power = " <<
Mechagodzilla.power << endl;
//use setters
Godzilla.setHealth(80);
Godzilla.setPower(15);
Mechagodzilla.setHealth(60);
Mechagodzilla.setPower(17);
//call getter function and display new values
cout << "Godzilaa: Health = " << Godzilla.getHealth()
<< ", Power = " << Godzilla.getPower() <<
endl;
cout << "Mechagodzilla: Health =" <<
Mechagodzilla.getHealth() << ", Power = " <<
Mechagodzilla.getPower() << endl;
//greet Mechagodzilla
Godzilla.greet(Mechagodzilla);
//till we get return value less than 0 ,Godzilla attacks
Mechagodzilla,,0 means health of Mechagodzilla is still greater
than 0
while(Godzilla.attack(Mechagodzilla)==0);
return 0;
}
=========================================
//Output
Enter the health: Enter the power: Godzilaa: Health = 112, Power
= 34
Mechagodzilla: Health =2.34063e-310, Power = 2.34063e-310
Godzilaa: Health = 80, Power = 15
Mechagodzilla: Health =60, Power = 17
Godzilla bows to Mechagodzila
Godzilla attacks Mechagodzila
Godzilla attacks Mechagodzila
Godzilla attacks Mechagodzila
Godzilla attacks Mechagodzila
Godzilla attacks Mechagodzila
Mechagodzila has been vanquished
Godzilla Class Pt. 2 C++ I have to continue building off of this class and do...
Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...
Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...
C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...
c ++ Create a class Book with the data members listed below. title, which is a string (initialize to empty string) sales, which is a floating point value (as a double, initialize to 0.0) Include the following member functions: Include a default constructor, a constructor with parameters for each data member (in the order given above), getters and setter methods for each data member named in camel-case. For example, if a class had a data...
Base Class enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected: HeroType type; string name; double health; double attackStrength; public: Character(HeroType type, const string &name, double health, double attackStrength); HeroType getType() const; const string & getName() const; /* Returns the whole number of the health value (static_cast to int). */ int getHealth() const; void setHealth(double h); /* Returns true if getHealth() returns an integer greater than 0, otherwise false */ bool isAlive() const; virtual void...
c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...
QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...