Question

The purpose of this assignment is to write a class Checker that can be used as...

The purpose of this assignment is to write a class Checker that can be used as a part of a checker game
program. Open an New Project in Qt Creator, and name it ChGame. Right click on the name of the class,
and add a new C++ class named Checker. This will create the new les Checker.h and Checker.cpp. You
will need to modify both Checker.h and Checker.cpp for this assignment. (The main function I used for
testing my functions is shown on the back of this page.)
The class Checker should have three private members:
• xposition is an integer between 0 and 7 which represents the x position of the piece.
• yposition is an integer between 0 and 7 which represents the y position of the piece.
• queen is an integer which starts at 0 but may be changed to 1 later on.
The class Checker should have two public constructors:
• The rst constructor takes no input. It sets xposition to zero, yposition to zero, and queen to zero.
• The second constructor takes two inputs. It sets xposition and yposition to the inputs and sets queen
to zero.
The class Checker should have ve public member functions:
• Checker should have a getter (accessor) for xposition named getX() that returns an integer.
• Checker should have a getter (accessor) for yposition named getY() that returns an integer.
• Checker should have a getter (accessor) for queen named getQueen() that returns an integer.
• Checker should have a setter (mutator) for queen that sets the member queen to 1.
• Checker should have function move that accepts an integer.
If the parameter is 0, it moves the piece to the northeast and returns 0. (Increases xposition by
one and decreases yposition by 1.)
If the parameter is 1, it moves the piece to the west and returns 0. (Decreases xposition by one
and decreases yposition by 1.)
If the parameter is 2, it moves the piece to the southeast and returns 0. (Increases xposition by
one and increases yposition by 1.)
If the parameter is 3, it moves the piece to the southwest and returns 0. (decreases xposition
by one and increases yposition by 1.)
If the parameter is not between 0 and 3 or if the resulting move would move the piece o the
board (so the position is no longer between 0 and 7), the function does nothing but returns 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


Checker.h
-----
#include <iostream>
#include <string>
using namespace std;
class Checker{
   private:
       int xposition, yposition, queen;
   public:
       Checker();
       Checker(int x, int y);
       int getX();
       int getY();
       int getQueen();
       void setQueen();
       int move(int dir);
};

Checker.cpp
======
#include <iostream>
#include "Checker.h"
using namespace std;


Checker::Checker(){
   xposition = 0;
   yposition = 0;
   queen = 0;
}
Checker::Checker(int x, int y){
   if(x >= 0 && x <= 7)
       xposition = x;
   else
       xposition = 0;
  
   if(y >= 0 && y <= 7)
       yposition = y;
   else
       yposition = 0;
}

int Checker::getX(){
   return xposition;
}

int Checker::getY(){
   return yposition;
}

int Checker::getQueen(){
   return queen;
}

void Checker::setQueen(){
   queen = 1;
}

int Checker::move(int dir){
   if(dir < 0 || dir > 3)
       return 1;
  
   int x , y;
   if(dir == 0){
       x = xposition +1;
       y = yposition -1;
   }
   else if(dir == 1){
       x = xposition - 1;
       y = yposition - 1;
   }
   else if(dir == 2){
       x = xposition + 1;
       y = yposition + 1;
   }
   else{
       x = xposition - 1;
       y = yposition + 1;
   }
  
   if(x >= 0 && x <= 7 && y >= 0 && y <= 7)
   {
       xposition = x;
       yposition = y;
       return 0;
   }
   else
       return 1;
}
      

Add a comment
Know the answer?
Add Answer to:
The purpose of this assignment is to write a class Checker that can be used as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create a java class with the name Brick class: For this part of the assignment, you...

    create a java class with the name Brick class: For this part of the assignment, you will create a class that allows you to specify a colored brick that is capable of drawing itself given a specified Graphics object. Note that this is a regular Java class and does not extend the JApplet class. Your class should a constructor with the following signature: Identifier: Brick(int xPosition, int yPosition, int width, int height, Color color) Parameters: xPosition – an int representing...

  • Pacman

    For this project, you will be working in on the Pacman game you created for Lab 6. See the solution to Lab 6 for starting files to this project. You should be working in a group of 3 or fewer students. Part 1: InheritanceCreate a new class called GameCharacter. Make GameCharacter a parent class of Pacman and Ghost. Make sure to move all common fields and methods from Pacman and Ghost to GameCharacter.   Part 2: GameplayBegin the game with the...

  • Problem 2 (36 pts): You are going to design a class named Computer. The class contains:...

    Problem 2 (36 pts): You are going to design a class named Computer. The class contains: A string field named manufacturer. A string field named serialNumber. A double field named speed (measured in Gigahertz). A constructor that has a parameter for each data field and sets the data fields with these values. A no-arg constructor that sets string fieldsto and numeric fields to 0. Mutator and Accessor methods for each data field. A method toString) that returns each field value...

  • Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one...

    Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...

  • Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification...

    Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification of the class is: A data member named amount of type  double . An data member named capacity of type  double . A constructor that accepts a parameter of type  double . The value of the parameter is used to initialize the value of capacity. The constructor also sets amount to zero. A function named addGas that accepts a parameter of type  double . The value of the...

  • java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named...

    java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named "MyRectangle3d" Your class must have the following attributes or variables · x (the x coordinate of the rectangle, an integer) * y (the y coordinate of the rectangle, an integer) * length (the length of the rectangle, an integer) * width (the width of the rectangle, an integer) * height (the height of the rectangle, an integer) * color( the color of the rectangle,...

  • Game Development: Uno For this assignment you will be creating the game of Uno (See the...

    Game Development: Uno For this assignment you will be creating the game of Uno (See the accompanying pdf for the instructions of the game). Your version will adhere to all the rules except that only the next player can issue a challenge against the previous player in regards to penalties, and your games must have at least three (3) players and at most nine (9) players. To begin, you must create the class Card which contains: Private string field named...

  • All files require Javadoc documentation comments at the top to include a description of the program...

    All files require Javadoc documentation comments at the top to include a description of the program and an @author tag with your name  only.    -------------------------------------- Develop an exception class named InvalidMonthException that extends the Exception class.   Instances of the class will be thrown based on the following conditions: The value for a month number is not between 1 and 12 The value for a month name is not January, February, March, … December -------------------------------------- Develop a class named Month.  The class should define an integer...

  • Problem 1 Write a program that outputs the lyrics for “Ninety-nine Bottles of Beer on the...

    Problem 1 Write a program that outputs the lyrics for “Ninety-nine Bottles of Beer on the Wall.” Your program should print the number of bottles in English, not as a number. For example: Ninety-nine bottles of beer on the wall, Ninety-nine bottles of beer, Take one down, pass it around, Ninety-eight bottles of beer on the wall. ... One bottle of beer on the wall, One bottle of beer, Take one down, pass it around, Zero bottles of beer on...

  • C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named month...

    C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT