I'm writing a program that will simulate simplified rovers that can move in one direction (north, east, west, or south) at constant speeds. I'm supposed to write a Rover class, and specify the following member instance variables:
• name (String)
• x position on a grid (integer)
• y position on a grid (integer)
• direction by compass – N, S, E, or W (String)
• speed (0 – 5 meters per second, integer)
And then I'm supposed to specify the following methods:
• No-arg constructor – set the rover’s position to (0,0), its speed to 0, its direction to North, and its name to Default
• Constructor that receives parameters to initialize all five instance variables described above
• Setter methods for each instance variable
• Getter methods for each instance variable
• Add error trapping to the code that gathers the user inputs. Do not allow someone to set the speed of the rover beyond the limits specified and do not allow someone to set the direction to anything but the four specified values; if the user enters an incorrect value, redisplay the input with instructions on what constitutes a legal value. (HINT: use a loop and a Boolean variable that becomes true when the user enters a valid input).
• Create a method named displayAllRoverData that displays values for all instance variables for all rovers in a tabular format after data for all rovers is entered:
Rover | X-Position | Y-Position | Direction | Speed
A 0 0 E 1
B 4 0 W 1
(except right underneith each variable)
Then I'm supposed to create a class client (main) that prompts the user for how many rovers s/he wants to create, then creates an array of the rovers and gets the initial values for all N rovers from the user. After the user specifies values for each rover, display a summary of the rover’s values as shown above.
So far I have this:
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
|
#include <iostream>
using namespace std;
class Rover
{
private:
char *name;
int position1;
int position2;
char *direction;
bool limit;
int vel;
public:
void printRov();
Rover inputRov();
};
void displayAllRoverData (Rover a, Rover b);
int main()
{
Rover r1, r2;
r1.inputRov();
r2.inputRov();
displayAllRoverData(r1, r2);
return 0;
}
void Rover::printRov()
{
cout << "Rover name: " << name << endl;
cout << "X-Position: " << position1 << endl;
cout << "Y-Position: " << position2 << endl;
cout << "Direction: " << direction << endl;
cout << "Velocity: " << vel << endl;
}
void displayAllRoverData (Rover a, Rover b)
{
a.printRov();
b.printRov();
}
Rover Rover::inputRov()
{
Rover a;
char d;
cout << "Input the name of the Rover: ";
cin >> name;
cout << "Input the integer of the X-Position: ";
cin >> position1;
cout << "Input the integer of the Y-Position: ";
cin >> position2;
cout << "Choose the direction the Rover will travel N, S, E, or W: ";
cin >> d;
if(d='n' || d='N')
direction = "North";
else
if(d='s' || d='S')
direction = "South";
else
if(d='e' || d='E')
direction = "East";
else
if(d='w' || d='W')
direction = "West";
cout << "What is the velocity of " << name << "? (0-5): ";
cin >> vel;
do
{
if(vel<0 || vel>5)
{
limit=false;
cout << "velocity entered isn't within the set limit.";
cout << "Please enter again. This time 0-5.";
cin >> vel;
}
else
{
limit=true;
}
}
while(!limit);
return a;
}
|
In lines 64, 67, 70, and 73 I get "non-lvalue in assignment" as an error message.
Can anyone help me with stuff I know I'm missing?
I know I have yet to add more code but I can't find anywhere that can help me with my programming inquiries and confusion.