For my class I'm doing a project which is creating a game. We're spliting it into different parts, one of which is a weapons class.
Assignment 10, basic Weapon class
For this assignment you will write a simple Weapon class and a test program.
The Weapon class should have three private data members: two integers (hit_chance and stamina_required) and a string for the weapon type.
There should be two public member functions: a constructor (which takes 3 arguments to initialize the private data) and a display function which prints out the private data members.
Split the Weapon class into Weapon.h and Weapon.cpp.
Put the main() function in a file named: assignment10.cpp
Write a Makefile to build the application.
You can use this sample code for your main() function:
1 2 3 4 5 6 7 8
|
#include<iostream>
#include"Weapon.h"
int main()
{
Weapon w1("Lance", 13, 5); //type, hit_chance, stamina_required
w1.display();
return 0;
}
|
This is what I have for my Weapon.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
1 #include<iostream>
2 using namespace std;
3
4 void Weapon::display(void)
5 {
6 cout << "hit chance=" << hit_chance << endl;
7 cout << "stamina required=" << stamina_required << endl;
8
9 }
10
11 Weapon::Weapon (int stamina_required, int hit_chance)
12 {
13
14 }
15
|
This is what I have for my Weapon.h:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Weapon {
2 private: int hit_chance;
3 int stamina_required;
4 string weapon_type;
5
6 public: void display(void);
7 Weapon()
8
9 }
10
~
~
~
|
and this is what I have as my assignment10:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
1 #include<iostream>
2 #include"Weapon.h"
3 using namespace std;
4
5 int main()
6 {
7 Weapon w1("Lance", 13, 5); // type, hit_chance, stamina_required
8 w1.display();
9 return 0;
10 }
~
~
~
~
~
~
|
How would I split up my weapon class in weapon.h and weapon.cpp?