C++ - Gorg vs Boov Battle – Part 1 – Meet the Boov
The Gorg can no longer be reasoned with! Negotiations cannot go well if you have no idea what the other side wants! They are so strong and vicious that ignoring them only means Earth is indirectly conquered somehow? It’s not my movie plot, but my retelling is totally butchering it for sure.
The Boov are friends of all peoples across the galaxy. Or so we are told. These beloved creatures want nothing more than peace and harmony, as long as it is their version of peace and harmony. It turns out okay for everyone in the end I suppose.
Maybe you can tell from the descriptions, but the Boov are quite the underdogs here! Captain Smek will need to simulate a Gorg battle many times over to see what their odds of victory would be.
For the first part of this simulation, let’s create the Boov class. Here are their specifications.
Boov
Requirements
1) Create a Boov class type
2) Create a main() function which creates a Boov object using this class
Thanks for the question.
Below is the code you will be needing Let me know if you have
any doubts or if you need anything to change.
Thank You !!
==============================================================================================
#ifndef BOOV_H
#define BOOV_H
#include<string>
using std::string;
class Boov
{
public:
Boov(string,int);
string getName() const;
int getHealth() const;
bool isDefeated() const;
void print() const;
void getAttacked() ;
private:
string name;
int health;
};
#endif
====================================================================================
#include "Boov.h"
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
Boov::Boov(string name,int health):
name(name),health(health){
}
string Boov::getName() const{
return name;
}
int Boov::getHealth() const{
return health;
}
bool Boov::isDefeated() const{
return health<=0;
}
void Boov::print() const{
cout<<"Boov Name: "<<name<<" current
health: "<<health<<endl;
}
void Boov::getAttacked(){
int randNumber = 1+rand()%10;
if(1<=randNumber &&
randNumber<=3){
//cout<<"Its a
miss"<<endl;
}else{
int damage = 2+rand()%4;
health-=damage;
//cout<<"Damage amount:
"<<damage<<endl;
if(health<0) health=0;
}
}
====================================================================================
#include <iostream>
#include "Boov.h"
using namespace std;
int main(int argc, char** argv) {
Boov ghost = Boov("Oh Off",11);
while(!ghost.isDefeated()){
ghost.getAttacked();
ghost.print();
}
const int MAX_SIMULATIONS=1000000;
double takeDamageCount=0;
for(int sim=1;sim<=MAX_SIMULATIONS;sim++){
Boov experiment =
Boov("Sample",11);
while(!experiment.isDefeated()){
experiment.getAttacked();
takeDamageCount+=1;
}
}
// cout<<takeDamageCount<<endl;
cout<<endl<<"Average life:
"<<takeDamageCount/MAX_SIMULATIONS<<endl;
}
====================================================================================
C++ Trek Wars Project: 100% code coverage unit testing is required for this project. once a ship has reached 0 health it is considered blown up -throw an exception if the move method is called on it. -repair ships cannot repair ships at 0 health There will be no chaotic corvette ships Trek Wars Purpose: classes, inheritance, class diagrams, virtual, testing Description Universal Merriment Development (UMD) is creating an online space battle game called (Trek Wars) You are tasked with...
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: " ;...
C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private: string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){ return name; } }; class Circle : public...
C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...
Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function? A. Only x can alter the private member variables of the object that activates the function. B. Only y can alter the private member variables...
1. Write TWO different but equivalent statements to do the same thing: use a for statement to print the elements of array numbers by using pointer ptr. 2. Write an expression that uses ptr to copy element 1 (zero-based) of the array to element 3. Do not use numbers in the array in Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... 3. Which of...
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...
HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators...
This program has an array of floating point numbers as a private data member of a class. The data file contains floating point temperatures which are read by a member function of the class and stored in the array. Exercise 1: Why does the member function printList have a const after its name but getList does not? Exercise 2: Fill in the code so that the program reads in the data values from the temperature file and prints them to...
About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...