need help

Write your question here.

Can someone just give me a guideline on how it is supposed to look like and ill go from their my main problem is using the .txt in my file if you could show me how to do that and just a guideline on what goes from first to last please thank you

this is what I have so far
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <conio.h>
#include <Windows.h>
#include <fstream>
#include <ifstream>
using namespace std;


[code]class Weapon
[code]{
[code]private:
[code]string name;
[code]int hands;
[code]int attackpower;
[code]double attackspeed;




[code]public:
[code]Weapon()
[code]{

[code]}
[code]double (){ ; }


[code]};
[code]class Hero
[code]{
[code]private:
[code]int str; // the strength of the hero
[code]string lefthand; //name of weapon on left hand
[code]string righthand; //name of weapon on right hand


[code]int str = rand() % 10 + 1;

[code]public:
[code]Hero()
[code]{

[code]}
[code]double(){ ; }


[code]};



[code]int main()
[code]{

[code]ifstream inFile;
[code]const int SIZE = 10;
[code]char name[SIZE];
[code]char hands[SIZE];
[code]char attackpower[SIZE];



[code]fstream textfile;
[code]textfile.open("weapons.txt");
[code]if (!textfile)
[code]cout << "Error opening text file\n";

[code]inFile >> name;
[code]cout << name << endl;

[code]inFile >> hands;
[code]cout << hands << endl;

[code]inFile >> attackpower;
[code]cout << attackpower << endl;

[code]double getname = name;



[code]srand(time(0));
[code]Weapon S[10];
[code]for (int x = 0; x<10; x++)
[code]cout << S[x].getname() << " ";




[code]cout << endl << endl;
[code]for (int x = 0; x<10; x++)
[code]{
[code]for (int y = 0; y<10 - x - 1; y++)
[code]{
[code]if (S[y].getname()>S[y + 1].getname())
[code]swap(S[y], S[y + 1]);
[code]

[code]

[code]for (int x = 0; x<50; x++)
[code]cout << S[x].getname() << " ";
[code]return 0;
[code]}

This is the text he wants us to input
Weapons.txt
Pencil 1 1
Dagger 1 3
Sword 1 5
BownArrow 2 6
Shotgun 2 9
GreatSword 2 8
Whip 1 4
Axe 1 6
BattleAxe 2 7
Excalibur 2 10

Here is the assignment he wants us to do
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.
Last edited on
@hero7k. There is too much information in your post. Just follow the format for posting the question. Post code between code format and state your question clearly. Help us to help you.
is that better I don't know how to put less info because he made the question really long and my code is already pretty long too if I can make it easier let me know please
Put the entire code between one sigle code tag. Code tag is in the box on the right side(this: <>)
Last edited on
Topic archived. No new replies allowed.