answersLogoWhite

0


Best Answer

Rather than use 'r', 'g', 'b' and 'w' (characters) to represent colours, it would be better to use an enum instead. You can always provide a getter to return a char if that is required.

enum car_colour{ red, green, blue, white, silver };

The following class provides the bare-bones of your car class. Note that the default constructor sets the coordinates at 0,0 and then calls the x and y mutators to set the actual coordinates. Note also that all mutators return false to indicate that no mutation has occurred (whenever the argument is the same as the current attribute value). This is more important with regards to the x and y mutators since the arguments must also be checked to ensure they are in range (0 to 19 for a 20x20 grid) before any mutation can occur. If any mutator returns true, this indicates a mutation has occurred. Other than that the class is fairly straightforward.

class car

{

public: // construction, destruction and assignment car(const car_colour colour=red, const bool ignition=false,const unsigned int x=0, const unsigned int y=0);car(const car& rhs):

m_colour(rhs.m_colour),

m_ignition(rhs.m_ignition),

m_x(rhs.m_x), m_y(rhs.m_y) {} ~car() {}car& operator=(const car& rhs);

public: // mutators (setters) bool set_colour(const car_colour colour);bool set_ignition(const bool ignition);bool set_x(const unsigned int x);bool set_y(const unsigned int y);

public: // accessors (getters)

car_colour get_colour(){ return(m_colour); }

bool get_ignition() const { return(m_ignition); }

unsigned int get_x() const { return(m_x); }

unsigned int get_y() const { return(m_y); }

char get_colour_as_char() const;

private: // attributes

car_colour m_colour;

bool m_ignition;

unsigned int m_x;

unsigned int m_y;

};

// default constructor

car::car(const car_colour colour=red, const bool ignition=false,

const unsigned int x=0, const unsigned int y=0):

m_colour(colour),

m_ignition(ignition),

m_x(0), m_y(0)

{

set_x(x);

set_y(y);

}

// assignment operator overload

car& car::operator=(const car& rhs)

{

m_colour=rhs.m_colour;

m_ignition=rhs.m_ignition;

m_x=rhs.m_x;

m_y=rhs.m_y;

}

// set the colour

bool car::set_colour(const car_colour colour)

{

if (m_colour!=colour)

{

m_colour=colour;

return(true);

}

return(false);

}

// set the ignition

bool car::set_ignition(const bool ignition)

{

if (m_ignition!=ignition)

{ m_ignition=ignition;return(true);

}

return(false);

}

// set the x coordinate

bool car::set_x(const unsigned int x)

{

if (x<20 && m_x!=x)

{

m_x=x;

return(true);

}

return(false);

}

// set y coordinate

bool car::set_y(const unsigned int y)

{ if (y<20 && m_y!=y)

{ m_y=y;

return(true); }

return(false);

}

// return the colour as a char

char car::get_colour_as_char() const

{

switch(m_colour)

{

case( green): return('g');

case( blue ): return('b');

case( white ): return('w');

case( silver ): return('s');

}

return('r'); // default colour.

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you make the car class with attrbutes private color 'r'red 'g'green 'b'blue 'w'white 's'silver ignition falseoff trueon position any x y coordinate in a 20 x 20 grid?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you determine mouse position in visual basic?

I have provided the answer in link form. Please click the Microsoft Support link listed below.to create an integer for each coordinate that is auto-updatedPrivate Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles_ Me.MouseMoveDim x As IntegerDim y As Integerx = e.Xy = e.YEnd Sub


How do you program a Mazda 6 remote?

Step 1: Open drivers door and leave open. Step 2: Lock and unlock the drivers door using the power door lock switch on the door. Step 3: Insert key into the ignition. Step 4: Turn key to on position and return to off position. (IMPORTANT - use ON position NOT ACC position). Do this 3 times within 10 seconds. Leave key in the ignition. Step 5: Open and close the drivers door 3 times. (Door should be left open after this step). *Instead of opening/closing door 3 times, you can press the button in door jam. The car will think you're opening and closing door but much easier! Step 6: ECU should respond by locking and unlocking the doors. Step 7: Press any button on remote #1 twice. ECU responds by locking and unlocking the car doors. Step 8: Press any button on remote #2 twice (etc.) Each time the ECU will respond by locking &amp; unlocking the doors. Step 9: Remove the key from the ignition and the ECU will respond a final time with a series of door locks and unlocks. You're done!


What is the position of buet in Bangladesh?

1st position


Levers can be divided into classes depending on the position of the?

on the position of the fulcrum


The potentiometer is which type of tranducer?

The potentiometer is a position tranducer. It forms a resistance divider, proportional to position.

Related questions

When was Position Ignition created?

Position Ignition was created in 2009.


what is y-coordinate in rectangular coordinate system?

A point's y coordinate is its vertical position, or how high or low it is.


What is a geographic coordinate?

A position fix


What is the number that represents the position of a point on a line?

Its coordinate.


WHY DO POSITION IS A VECTOR QUANTITY?

To describe position, you need more than one number - for instance, an x-coordinate, a y-coordinate, and (if it is in three dimensions) a z-coordinate. That's the very essence of a vector - the fact that it is made up of several components.


One of the numbers that describe the position of a point on a plane?

coordinate


What is a pair of numbers that indicate the position of a point on the plane?

Coordinate


An application of coordinate geometry?

by using coordinate geometry you can find the position of a place in earth by using the pictures taken by satellites.


Do you have to turn on the switch to reset the tire pressure light?

Yes, the ignition switch must be in the ignition position -not- the accessory position.


How do you fix the position of a point on a sheet of map?

You can do this by using a two coordinate designation of that position: horizontal and vertical.


What is an abscissa?

An abscissa is the coordinate representing the position of a point along a line perpendicular to the y-axis in a plane Cartesian coordinate system.


What is The Wiring position for the ignition module on a 1990 Buick park avenue?

what is the wiring position for the ignition module on a 1990 Buick Park Avenue?