Assignment Help Please

Hi I have an assignment, probably easy for a lot of you but im new to this programming and trying to understand little by little.

Assignment
You are to create and fully test a class soldier which has the following attributes:

int id
char type
int speed
int initiative
int atk
int def
double Loc[2]
the Loc is the x,y location of a soldier, so Loc[0]=x location from -100 to 100
Loc[1]=y location from -100 to 100

Im at a lost for the location part. I dont even know how to start it. Im not very good at programming but love to learn it. If anyone can tell me if im going in the right direction and give me inputs would greatly be appriciated.

Im not asking to do my assignment but if you so wish give a line of codes please explain it so I can better understand. I dont have 30 year of experience so I wont understand if you go too deep into it


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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class soldier
{
public:
    soldier()   ///default constructor

        {
        cout<<"Please Enter Your Information" <<endl <<endl;
        cout<<"ID Number:  "; cin>>idNumber;
        cout<<"Type (i=infantry or c=cavalry): "; cin>>type;
        cout<<"Speed (0-5): "; cin>>speed;
        cout<<"Initiative (0-5): "; cin>>in;
        cout<<"Attack (0-5): "; cin>>atk;
        cout<<"Defense (0-5): "; cin>>def;
        cout<<"Location (-100 to 100): "; cin>>loc;


        cout<<endl <<endl <<endl;

        }



    int getidNumber(){return idNumber;}
    char gettype() {return type;}
    int getspeed() {return speed;}
    int getin() {return in;}
    int getatk() {return atk;}
    int getdef() {return def;}
    double getloc() {return loc;}

    void setidNumber(int i){idNumber=i;}
    void setype(char c) {type=c;}
    void setspeed(int s) {speed=s;}
    void setin(int v) {in=v;}
    void setatk(int a) {atk=a;}




    void display()

    {
        cout<<"Soldier ID Number:  "<<idNumber <<endl;
        cout<<"Unit Type: ";
                if(type == 'i') {cout<<"Infantry" <<endl;}
                else if(type == 'c') {cout<<"Cavalry" <<endl;}
                else{cout<<"Desk Duty" <<endl;}
        cout<<"Speed: " <<speed <<endl;
        cout<<"Initiative: " <<in <<endl;
        cout<<"Attack: "<<atk <<endl;
        cout<<"Defense: "<<def <<endl;





        cout<<endl <<endl <<endl;
         }










private:

    int idNumber;
    char type;
    char i;
    char c;
    int speed;
    int in;
    int atk;
    int def;
    double loc;

};


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
#include <iostream> /// contains everything needed for input output
#include <string>
using namespace std;
#include "soldier.h"



int main ()
{



    soldier testSoldier;







    testSoldier.display();


}

Your location need to be an array.
 
double Loc[2];


To get get/set the x-location you need to use Loc[0].
To get get/set the y-location you need to use Loc[1].

Have a look at here to learn more about arrays:
http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.