this is a question for my assignment.

The requirements are related to a simple Robot game class. The robot is created with a name, a position (row and column) and the initial energy level of 60 units. The row and column is randomly generated using the rand() function. The valid values for row and column are in the range of 1 to 4.
There is a target row and column which is also generated using the rand() function and the valid value is in the range of 1 to 10. This target row and column is a global variable.
Robot class has the following methods:
Robot(string n, int r, int c)
Constructor for Robot class
void move(int direction)
The direction for the movement is North, South, East and West, represented by 1 to 4 respectively. If the direction is North, increase the row by 1, South, decrease the row by 1, East, increase the column by 1 and West, decrease the column by 1.
void calEnergy()
The energy level increases by 10 units when the row and column of the object is the same value of the target row and target column.
int getEnergy()
Returns the energy level.
string getName()
Returns the name of robot.
(i) Write code to implement the Robot class and its respective methods.
(ii) The following is an incomplete test driver. Write the code for the 6 missing parts. A sample run is as shown below. Include a screen output in your submission.
#pragma once
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
int tr, tc;
int main()
{
int r, c, d;
// r – row, c – column, d - direction
srand ( time(NULL) );
// Part (i) code to generate the value for target row and column. //These two are global variables.
// Part (ii) code to generate the row and column and instantiation of //first robot, with name “Betty”
// Part (iii) code to generate the row and column and instantiation //of second robot with name “Peter”
for (int k = 0; k < 10000; k++) // loop to move “Betty” & “Peter”
{
// Part (iv) code to generate the direction (East, West, North, /south) and move each instantiated robot.
// Part (v) code to calculate the energy level of the itwo //instantiated robots
}// for
// Part (vi) code to find out the winner. The winner is the robot //with the higher energy level.
}//main
any solutions?
are you asking us to make homework for you??
write a program, post it here adn use CODE TAG so people can read your code and find mistakes.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
using namespace std;

const int MAXROW = 10;
const int MAXCOLUMN = 10;

class Robot
{
private:
string name;
int targetrow;
int targetcolumn;
public:
Robot(string n, int r, int c);
void move(int direction);
void calenergy();
int getEnergy();
string getName();
};

Robot::Robot(string n,int r, int c)
{
n = name;
r = targetrow;
c = targetcolumn;
}

void Robot::move(int direction)
{


}








int main()
{

}
whats next?
Topic archived. No new replies allowed.