Bubble sorting help

i have this program as an assignment for a class, and i need help with the bubble sorting, and the double attackspeed constructor, thanks :)

--these are the instructions--

There will be a file called "Weapons.txt" which contains 3 pieces of information about weapons.
There will be the following data:
string name; // contains the name of the weapon
int hands; // contains how many hands required to use the weapon
int attackpower; //contains the attack power the weapon has per hit.

**this next variable is not in the file and will be generated by constructor**
double attackspeed; //this requires a bit of explaining:
//lets say the attack power of the weapon is 10. IF the weapon has an attackspeed
//of 2, that means he does 2 attacks per second, so his damage per second is 20.
//if his attackspeed was .5, he attacks once every 2 seconds so his damage per second is 5 (average).
The attackspeed will be generated randomly in the constructor from 0.1 to 2.5


This means the class Weapon will have 4 variables (name, hands, attackpower, attackspeed);

There will also be a class called Hero with only three variables:
int str; // the strength of the hero
string lefthand; //name of weapon on left hand
string righthand; //name of weapon on right hand
This str will also be generated randomly by the constructor using rand()%10+1;

The hero has the obvious... two hands! You should determine the best weapon combination
for the hero for him to deal the highest damage per second (dps).

**There is a restriction though... You can only equipt weapons you are strong enough to equipt.
This means that if your str is 5, the combined attackpower of your weapons equipt should be 5 or less.
This really makes things tougher.


To begin, you need to infile all the weapons into the array of size 10 correctly.
Once all the weapons are set up, you should use bubble sort to sort the weapons by your choice of
either attackspeed, attackpower, or maybe even dps; (use a function named sortWeapons)

Display all the weapons information.
*At this point you should have found the weapon(s) to equipt*
Display the Hero's information (his attack strength and the name of the weapon on each hand).
IF the hero is using a two handed weapon, then the same name of the weapon is on both the left and right hand.
IF he is using two one handed weapons, then there should be two different names.
Display these names along with the combined attack damage per second.


**be aware that the two handed weapons are stronger than one handed, but you can
equit two one handed weapons.
***You cannot equipt two of the same weapon
** The classes should have all set and get functions, constructor, variables should be private **
**The main should have an array of 10 weapons and a hero. it should have functions as you find needed.

this is my code, what i have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <fstream>
#include <string>
#include <cmath>
#include <time.h>
using namespace std;

class Weapon
{
private:
string name; 
int hands; 
int attackpower;
double attackspeed; 
public:
	string getname(){return name;}
	void setname(string n){name=n}
	int gethands(){}
	void sethands(){}
	int attackpower(){}
	void setattackpower(){}
	double attackspeed(){}
};

class Hero
{
private:
int str; 
string lefthand; 
string righthand;  
public:
	int getstr(){return str;}
	void setstr()
	{
		srand (time(0));
		str=rand()%10+0;
	}
	string getlefthand(){}
	void setlefthand(){}
	string getrighthand(){}
	void setrighthand(){}
};

int sortWeapons()
{
	string name[10];
	int hands[10];
	int attackpower[10];

	ifstream inFile;
	inFile.open("Weapons.txt");

	for(int x=0; x<10; x++)
	{
		inFile>>name[x];
		inFile>>hands[x];
		inFile>>attackpower[x];
	}
}

int main()
{
	int weapons[10];

	system("Pause");
	return 0;
}
Last edited on
closed account (10X9216C)
Should make your question more precise, no one is going to want to read your entire assignment to help you out. Give us only the relevant information.

Bubble sort: http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/bubble-sort/
Topic archived. No new replies allowed.