Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views2 pages

OOP Assignment

The document outlines a programming task involving Object Oriented Programming with two classes: Card and Hand. It includes specific instructions for writing code for class attributes, methods, and game logic to calculate scores based on card colors. The task also requires declaring player objects and determining the winner based on calculated scores.

Uploaded by

Calvin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

OOP Assignment

The document outlines a programming task involving Object Oriented Programming with two classes: Card and Hand. It includes specific instructions for writing code for class attributes, methods, and game logic to calculate scores based on card colors. The task also requires declaring player objects and determining the winner based on calculated scores.

Uploaded by

Calvin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Wednesday 11 June 2025

Introduction Object Oriented Programming

Question: A program has two classes:


• Card and
• Hand.
The methods and attributes of these
classes are shown:

a. Write program
code to declare the
class Card, its
attributes and
constructor.
Do not write program
code for the get methods. All attributes must be private. Include attribute
declarations using comments. Copy the code. [5]
b. Write program code for the class methods GetNumber() and GetColour().
Copy the code. [3]
c. The program is tested with the following cards: Write
program code to declare each of these cards as a variable
of type Card in the main program. Copy the code [2]
d. Write program code to declare the class Hand, its
attributes and constructor. Do not write the get methods.
All attributes must be private. Include attribute
declarations using comments. Copy the code. [6]
e. The get method GetCard() takes an index as a parameter
and returns the card stored at that index in the array.
Write program code for the method GetCard(). [2]
f. Two players are declared with 5 cards each. Player 1 has
the cards: 1 red, 2 red, 3 red, 4 red, 1 yellow. Player 2 has
the cards: 2 yellow, 3 yellow, 4 yellow, 5 yellow, 1 blue. [2]
Write program code to declare player 1 and player 2 as
objects of type Hand, with the cards indicated. [2]
g. The function CalculateValue() takes a player’s hand as a
parameter and returns a score calculated using the
following rules:
• If a card is red, 5 points are added to the player’s score.
• If a card is blue, 10 points are added to the player’s score.

Page |1
• If a card is yellow, 15 points are added to the player’s score.
• The number of each card in the hand is added to the player’s score.
i. Write program code for the function CalculateValue(). Assume that there are
only 5 cards in the player’s hand in this function. [6]
ii. Amend the main program by writing program code to use the function
CalculateValue() for each of the two players. The player with the highest score
wins. Output an appropriate message to identify the winning player, or if the
game was a draw (both players have the same number of points). [4]
iii. Test your program. Take a screenshot to show the output. [1]

Page |2

You might also like