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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
class Rover{
private:
string name;
int xpos;
int ypos;
string direction; //Use Cardinal Directions (N,S,E,W)
int speed; //(0-5 m/sec)
public:
//Constructors
Rover();
Rover(string,int,int,string,int);
//Get functions
string getName()const;
int getXpos()const;
int getYpos()const;
string getDirect()const;
int getSpeed()const;
void getRoverData();
//Set functions
void setName(string);
void setXpos(int);
void setYpos(int);
void setDirect(string);
void setSpeed(int);
};
//Constructor function
Rover::Rover()
{
xpos=0;
ypos=0;
direction="N";
speed=0;
}
Rover::Rover(string nme,int xp, int yp, string dir, int sp) :
name(nme), xpos(xp), ypos(yp), direction(dir), speed(sp)
{
}
Rover readRover()
{
string nme;
int xp;
int yp;
string dir;
int sp;
cout<< "Please enter the Name of the Rover: ";
cin>> nme;
cout << "Please enter the starting X-position: ";
cin >> xp;
cout << "Please enter the starting Y-position: ";
cin >> yp;
cout << "Please enter the starting direction (N,S,E,W): ";
cin >> dir;
cout << "Please enter the starting speed (0-5): ";
cin >> sp;
// Construct an object with the user input data and return it.
return Rover(nme, xp, yp, dir, sp);
}
//Getter functions
string Rover::getName()const
{
return name;
}
int Rover::getXpos()const
{
return xpos;
}
int Rover::getYpos()const
{
return ypos;
}
string Rover::getDirect()const
{
return direction;
}
int Rover::getSpeed()const
{
return speed;
}
void Rover::getRoverData()
{
cout<<"Rover name: "<<name<<endl;
cout<<"X-Position: "<<xpos<<endl;
cout<<"Y-Position: "<<ypos<<endl;
cout<<"Direction: "<<direction<<endl;
cout<<"Speed: "<<speed<<endl;
}
//Setter functions
void Rover::setName(string nme)
{
cin>>nme;
name=nme;
}
void Rover::setXpos(int x)
{
cin>>x;
xpos=x;
}
void Rover::setYpos(int y)
{
cin>>y;
ypos=y;
}
void Rover::setDirect(string direct)
{
cin>>direct;
direction=direct;
}
void Rover::setSpeed(int spd)
{
cin>> spd;
speed=spd;
}
int main(int argc, char** argv) {
int MAX=5;
Rover r1=readRover();
Rover r2=readRover();
Rover r3=readRover();
Rover r4=readRover();
Rover r5=readRover();
r1.getRoverData();
int values[MAX];
values[0]=Rover r1;
values[1]=Rover r2;
values[2]=Rover r3;
values[3]=Rover r3;
values[4]=Rover r4;
for(int i=0;i<MAX;i++)
{
cout<<values[i];
}
return 0;
}
|