University | Singapore University of Social Science (SUSS) |
Subject | MTD215: Application of C++ in Multimedia |
Question 1
Apply C++ language to program a Find My Key game. The scenario of Find My Key game is that players have lost their key in a field full of holes, and they need to navigate the field to get the key without failing into the holes or stepping outside of the field.
• The field consist of 8 rows by 8 columns
• The field consists of grid containing the “holes” (O), the “key” (K), the “player’s
character” (C). We will be using (X) to represent the rest of the field.
• Players will be interacting with the following 4 keyboard keys to navigate the fields.
o ‘u’ represents up key.
o ‘d’ represents down key.
o ‘l’ represents left key.
o ‘r’ represents right.
• You can declare any variable(s) that is required for the game to work.
Figure Q1-1 shows a sample initial screen of the game and the result after the player has selected ‘r’ to move one step to the right of the field
Listing Q1 shows a partial implementation of the Find My Key game.
#include <iostream>
using namespace std;
const int totalF = 8;
char fields[totalF][totalF];
void rebuildFields()
{
for (int row=0; row<totalF; row++) {
for (int col=0; col<totalF; col++) {
cout << fields[row][col] << ” “;
}
cout << “\n”;
}
}
//Edit this function
void initFields() {
for (int row=0; row<totalF; row++) {
for (int col=0; col<totalF; col++) {
char output = ‘X’;
fields[row][col] = output;
}
}
}
//Implement this function
void createPlayer() {
}
//Implement this function
void createKey(){
rebuildFields();
}
//Implement this function
bool checkMove(int row, int col) {
return 0;
}
//Implement this function
bool moveChar(char input) {
return 0;
}
//Implement this function
void getInput() {
bool initGame() {
initFields();
createPlayer();
createKey();
return true;
}
int main(int argc, const char * argv[]) {
bool nextStep = false;
std::cout << “Welcome to Find My Key Game\n\n”;
nextStep = initGame();
if (nextStep)
{ getInput(); }
return 0;
}
The rebuildFields() function updates the position of the player (C) when the player navigates through the field. You do not require to edit this function.
The initFields() function randomly assigns the field with grid containing the holes (O) or the fields (X). The partial implementation of this function populates all grid to the fields (X),
and Figure Q1-2 shows the output of the partial implementation of the game. You are required to edit this function to randomly populate the holes (O) in the field.
(a) Discuss how you can modify the initFields() function to randomly populate the holes (O) in the field every time the player starts the game. The number of holes (O) generated should be less than the fields (X). Implement your solution to populate the holes (O). Figure Q1-3 shows an example of the field with randomly generated holes (O).
(b) Implement the following functions:
(i) void createPlayer() – This function assigns the position of the player (C) by generating 2 random numbers (row and column) within the field.
(ii) void createKey() – This function assigns the position of the key (K) by generating 2 random numbers (row and column) within the field. You need to ensure that the key (K) do not replace the position of the player (C). Figure Q1- 4 shows an example of the random generated position of the player (C) and the key (K).
(iii) void getInput() – This function shows “Enter a direction (u,d,l,r):” in the output, and gets the input from the player and pass the input as an argument to moveChar(char input) function. Figure Q1-5 shows an example of the
output
(iv) bool moveChar(char input) – This function returns a boolean which indicates whether the player should continue the game or the game should end when the player drop into a hole or gets the key. This function will check if
input is valid. If input is valid, the function will pass in the next position of the player to checkMove(int row, int col). If the input is not valid, an error message will be shown in the output as “Invalid direction input. Please
enter again”. Figure Q1-6 shows an example of the output.
(v) void checkMove(int row, int col) — This function returns a boolean which indicates whether the player should continue the game or the game should end when the player drop into a hole or gets the key. The function will check the following conditions.
a. Player is out of field’s boundary – Display the message “Out of boundary! Please try again!” and the game will get the player to input again. Figure Q1-7 shows an example of the output.
b. Player fall into a hole – Display the message “You fell into the hole. Game Over” and end the game. Figure Q1-8 shows an example of the output.
c. Player gets the key – Display the message “Congratulations! You have gotten the Key. Game End” and end the game. Figure Q1-9 shows an example of the output.
Hire a Professional Essay & Assignment Writer for completing your Academic Assessments
Native Singapore Writers Team
- 100% Plagiarism-Free Essay
- Highest Satisfaction Rate
- Free Revision
- On-Time Delivery
Question 2
The WeeklyPay class calculates the weekly pay-out of an employee. The class consist three data members namely name, weekNum and dailyPay.
Identify suitable coding modules for the WeeklyPay class with the following specifications.
(a) Define the three data members:
(i) name as a string to store the employee name.
(ii) weekNum as an integer to store the weeks of the month (e.g., 1 represent the 1st week of the month, 2 represent the 2nd week of the month).
(iii) dailyPay as an integer array with the array size of 5 to store the pay per day from Monday to Friday.
(b) Implement a parameterised constructor that receives three arguments that represent the values of name, weekNum, and dailyPay respectively. The constructor will initialise the three data members with the arguments.
(c) Write a totalPayPerWeek function to calculate the total pay per week.
(3 marks)
(d) Write a getPay getter function to return the dailyPay data member.
(2 marks)
(e) Overload the << operator so that the statements
(f) Overload the + operator so that two instances of WeeklyPay can be added using the + operator. For example, the statements.
(g) Overload the > operator to check if an instance of WeeklyPay is greater (in terms of total pay per week) than another instance of WeeklyPay. Figure Q2(g) shows an example of the output. Figure Q2(g) shows an example of the output.
(h) Write the main function that will demonstrate how all the operators can be used.
Question 3
Implement a C++ program that helps to explain the syntax and use of data structures such as arrays and pointers. These data structures form part of the data members and constructors in a C++ class.
(a) Declare the data members of TaxResident class as follows:
(i) A char with size 30 representing the name of the resident e.g. “John
Lim”.
(ii) A double representing the total income of the resident per year e.g.
10000.50.
(iii) An integer representing the number of reliefs that the resident could apply to reduce their tax chargeable.
(iv) A dynamic location large enough to store all reliefs’ amount based on the number of reliefs that the resident applied. The location is reference by a pointer int* personalReliefs.
(v) A static double representing the tax interest for the tax chargeable of 15% of the resident’s total income.
(b) Implement an application using the C++ language in an object-oriented style. Constructors and destructor are used to initialise and remove objects in an object- oriented manner.
You are asked to write the following constructors to initialise a TaxResident object and a destructor to remove it from memory.
(i) A parameterised constructor.
(ii) A destructor.
(c) Write a calculateTax function that returns how much the resident needs to pay for the tax chargeable. The formula for the calculation of tax chargeable:
taxChargeable = (totalIncome – total amount of personalReliefs) * taxInterest
d) Write a displayTaxDetails function shows the details of the resident and tax chargeable. Figure Q3(d) shows an example of the output.
(e) Write a main() function to demonstrate how part (b), (c) and (d) are being used.
(d) Write a displayTaxDetails function shows the details of the resident and tax chargeable. Figure Q3(d) shows an example of the output.
Figure Q3(d): Example output of displayTaxDetails function
(e) Write a main() function to demonstrate how part (b), (c) and (d) are being used.
Question 4
Appraise the use of SDL for geometry rendering. SDL has primitive functions for drawing point, lines and rectangles. You are required to write a SDL program that produces the following graphical output that depends on the input from the keyboard.
(a) When the program first launch, the output will show a filled square at the top left of the screen (Figure Q4(a)).
(b) When user hit on the right key from the keyboard, the number of squares will increase (Figure Q4(b)). The total number of squares is limited to 20.
(c) When user hit on the left key from the keyboard, the number of squares will decrease (Figure Q4(c)). There will always be a square shown in the output
Replace the title of the window “Student Name and PI” with your name and id. The position and colour of each primitive should be as close as possible to the above figure.
Buy Custom Answer of This Assessment & Raise Your Grades
Facing difficulty to finish your MTD215: Application of C++ in Multimedia Assignment? then hire Assignment buddy service at Singapore Assignment Help. We have a team of extremely talented and skilled suss assignment experts who offer doubtless help on computer science assignment at a most reasonable price.
Looking for Plagiarism free Answers for your college/ university Assignments.
- PS300 Research Project Assignment: Emotional Intelligence Components Predict Happiness
- Electronics Engineering Circuit Assignment Questions: Theory & AC Analysis
- EAS425 Tutor-Marked Assignment Report: Arrow Airways Case in Flight Line Management
- Community Health Nurses in Singapore Assignment: Balancing Prevention and Treatment in Diabetes Management
- ACC08702 Flexible Budgeting Analysis with Variance Calculation: Selling Overheads & Consultancy Services Case Study
- GCE A-Level 8882 Project Work: How to Write a Winning Project Summary
- IT3662 SAFENET Network Security and Integration Assignment: Case Study on HQ and Branch Office Setup
- Vodafone Group Plc Annual Report Assignment: Financial Performance and Shareholder Insights (2024)
- Financial Literacy Lifespan Assignment: A Case Study on Gen Z & Millennials’ Financial Stability and Lifelong Learning
- PSB7008CL Organisational Behaviour Assignment: Case Study on Leadership, Diversity, and Change Initiatives