0% found this document useful (0 votes)
10 views8 pages

Mzansi Music Festival Programming Test

The document outlines a formal semester test for programming, focusing on two main problems: managing a festival line-up of artists and ticket sales for the Mzansi Music Festival. It provides detailed instructions for setting up projects, coding requirements, and function implementations, emphasizing best practices such as code comments, descriptive naming, and input validation. Additionally, it includes an assessment rubric for grading based on the implementation of structures, functions, and integration with provided code.

Uploaded by

Nkosi
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)
10 views8 pages

Mzansi Music Festival Programming Test

The document outlines a formal semester test for programming, focusing on two main problems: managing a festival line-up of artists and ticket sales for the Mzansi Music Festival. It provides detailed instructions for setting up projects, coding requirements, and function implementations, emphasizing best practices such as code comments, descriptive naming, and input validation. Additionally, it includes an assessment rubric for grading based on the implementation of structures, functions, and integration with provided code.

Uploaded by

Nkosi
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

Formal/Semester test – Programming problems

Code comments
Include clear and relevant comments explaining your logic, especially for string manipulation, file
operations, and pointers
Begin each program with a comment stating your name, surname, and student number.

Programming best practices


Descriptive naming – opt for meaningful names for variables and functions.
Use of constants – prefer named constants over magic numbers or hardcoded values.
User input – ensure you validate inputs to prevent errors and handle unexpected values.

Code structure & readability


Indentations – Keep indentation consistent across your code.
Spacing – Use spaces between unrelated section to boost readability.

Scenario

Every year, the Mzansi Music Festival showcases South Africa’s diverse musical tapestry, with
representative beats from every province and culture. The event not only entertains with a rich array
of rhythms, including Gqom, Maskandi, Motswako and Amapiano, but also unites, echoing the
harmonious heritage of the Rainbow Nation.

Problem: Question 1 - Festival Line-Up

Your task is to create a program to manage the list of performing artists. Each artist has several
attributes, and the program should allow a user to calculate the total performance fees for all available
artists, and display artists based on specified filtering criteria.

Q1 - Getting Started

1. Project Setup:
o Create a new project in Code::Blocks and name it as ‘Q1_FormalTest_studentNumber’
where ‘studentNumber’ is your unique student ID.
2. Incorporating the main() function:
o Download the provided text file named ‘[Link]’ and open the file in a text editor.
o Copy the entire content of the file.
o Replace the default content of the main method of your project with the copied
‘mainFunctionQ1’ code.

# 1 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
Q1 - Instructions

NOTE: All the variables must be declared in the main() function. NO global variables are
allowed to be declared and used. Parameters must be used to transfer information to the functions
– no marks for the functions if parameter-transfer is not implemented.

1 Declare a struct named ‘Artist’ with the following data members:


 ‘name’ – A string to hold the artist’s name.
 ‘genre’ – A string to represent the music genre (e.g., Hip-hop, House, etc.)
 ‘performanceFee’ – A double to represent the artist’s performance fee.
 ‘available’ – A Boolean to indicate whether the artist is available for the festival (true) or
not (false).

2 Write code for the following functions:


2.1 An int function named ‘loadArtistsFromFile’ to receive an array of ‘Artist’ structs.
The function should populate the array with the data from the provided text file ‘[Link]’.
Each line of text in the text file contains the data of an artist. The data is delimited by the
hash (‘#’) character. The structure of each line:

<Name>#<Genre>#<PerformanceFee>#<Availability(1=available,0!=available)>

An example of three lines of text in the text file:

AKA#Hip-hop#10000.50#1
Ladysmith Black Mambazo#Isicathamiya#5500.25#0
Black Coffee#House#15000.00#1

Apply string-handling techniques to extract data for each artist from the file and populate
the array with Artist structs.
Return the number of structs stored in the array.

2.2 A void function named ‘displayArtistInfo’ to receive an array of ‘Artist’ structs, the
number of elements in the array, an optional flag, and an optional string as parameters.
The optional flag indicates if only available artists should be displayed. The default value
for this parameter must be set to false. The string parameter specifies a genre filter. The

# 2 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
default must be an empty string. Display the details of artists based on the provided
filtering criteria in the following format:

Name Genre Performance Fee Availability


--------------------------------------------------------------------
Lira R&B 15000.00 Available
Die Antwoord Alternative 20000.00 Not Available
AKA Hip Hop 18000.00 Available
Mi Casa House 15500.00 Available
Black Coffee Electronic 21000.00 Not Available
Yvonne Chaka Chaka Afro-pop Gauteng 15000.00
2.3 A double function named ‘calcPerformanceTotal’ to receive an array of ‘Artist’ structs
and the number of elements in the array as parameters. Calculate and return the total
performance fees of all the available artists. The output must NOT be displayed from the
function. Example of the output:

********************************************************
Total performance fees for available artists: R 144000.00
********************************************************

3 In the ‘main()’ function:


Write code to declare an array of Artist structs and other required variables. Provide for the
array to hold 50 elements. Call the functions correctly from the ‘main()’ function. Display the total
performance fees of the available artists.

# 3 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
Example program execution

Menu:
1. Display Artist Info
2. Calculate Total Performance Fees for Available Artists
3. Exit
Enter your choice: 1

Filter Options for Displaying Artists:


1. Display All Artists
2. Display Only Available Artists
3. Display Artists by Genre
Enter your filter choice: 2

Name Genre Performance Fee Availability


---------------------------------------------------------------------
Lira R&B 15000.00 Available
AKA Hip Hop 18000.00 Available
Mi Casa House 15500.00 Available
Yvonne Chaka Chaka Afro-pop 15000.00 Available
GoldFish Electronic 17500.00 Available
Freshlyground Afro-fusion 16500.00 Available
. . . .

Menu:
1. Display Artist Info
2. Calculate Total Performance Fees for Available Artists
3. Exit
Enter your choice: 1

Filter Options for Displaying Artists:


1. Display All Artists
2. Display Only Available Artists
3. Display Artists by Genre
Enter your filter choice: 3
Enter genre to filter by (e.g., R&B, Alternative, Hip Hop, Electronic, Folk, etc.): R&B

Name Genre Performance Fee Availability


----------------------------------------------------------------------
Lira R&B 15000.00 Available

Menu:
1. Display Artist Info
2. Calculate Total Performance Fees for Available Artists
3. Exit
Enter your choice: 2

********************************************************
Total performance fees for available artists: R 144000.00
********************************************************

<Menu Display>
Enter your choice: 3
Exiting...

# 4 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
Problem: Question 2 – Ticket Management Program

Your task is to create a program to manage the Mzansi Music Festival’s ticket sales. The program
should allow organisers to sell tickets and record the sales data to a text file.

Q2 - Getting Started

1. Project Setup:
o Create a new project in Code::Blocks and name it as ‘Q2_FormalTest_studentNumber’
where ‘studentNumber’ is your unique student ID.
2. Incorporating the main() function:
o Download the provided text file named ‘[Link]’ and open it in a text editor.
o Copy the entire content of the file.
o Replace the default content of the main function of your project for Question 2 with the
copied ‘mainFunctionQ2’ code.

Q2 - Instructions

NOTE: All operation on the arrays used in this question must be performed using pointers. Usage
of the ‘[ ]’ block bracket notation for array management will result in NO marks for this question,
regardless of functionality.

NOTE: All the variables must be declared in the main() function. NO global variables are allowed
to be declared and used. Parameters must be used to transfer information to the functions – no marks
for the functions if parameter-transfer is not implemented.

1 Declare the necessary parallel arrays to store ticket information, including details such as ticket
ID, category, and price:
1.1 Parallel Arrays – size of each array is 100:
 ‘arrTicketIDs’ – to store unique Ticket IDs.
 ‘arrTicketPrices’ – to store the associated ticket prices.

2 Write code for the following functions:


2.1 A void function named ‘captureTicketDetails’ to receive pointers to the arrays
‘arrTicketIDs’ and ‘arrTicketPrices, and a reference to the number of elements in the
arrays as parameters. Capture the ticket category from the user (VIP, Standard,
Economy) and generate a unique ticket ID. Validate the input of the user to be the letter
V, S or E. The ticket ID is composed of:
 A prefix based on the category (V for VIP, S for Standard, E for Economy,

# 5 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
 A number (incrementing for each ticket category sold),
 A hyphen (-),
 A 4-digit randomised number.
Example: VIP ticket: V1-1041, Standard ticket: S2-2357, Economy ticket: E3-8874.
Store the ticket ID in the ‘arrTicketIDs’ array.
Compute the ticket price based on the category obtained from the user, where VIP (V) is R
1000.00, Standard (S) is R 500.00, and Economy (E) is R 200.00. Store the computed ticket
prices in the ‘arrTicketPrices’ array at the appropriate index.

Ensure that the number of tickets (elements in the array) is updated accordingly.
Display a confirmation message which includes the ticket ID, for example:

Enter ticket category (V – VIP, S – Standard, E – Economy): VIP


INVALID category. Please enter V, S, or E!

Enter ticket category (V – VIP, S – Standard, E – Economy): B


INVALID category. Please enter V, S, or E!

Enter ticket category (V – VIP, S – Standard, E – Economy): V


Ticket ID: V1-1041 ADDED SUCCESSFULLY!

2.2 A void function named ‘computeTicketPrice’ to receive pointers to the array


‘arrTicketPrices’ and a reference to the number of elements in the array as parameters.
Compute the number of tickets sold in each category as well as the total amount
received per category. Use the information in the ‘arrTicketPrices’ array to compile the
report.

Summary of Ticket Sales


------------------------
2 VIP ticket(s): R 2000.00
1 Standard ticket(s): R 500.00
1 Economy ticket(s): R 200.00

Display the information as shown in the example below:


2.3 A void function named ‘writeToFile’ to receive pointers to the parallel arrays
‘arrTicketIDs’ and ‘arrTicketPrices’, and the number of elements in the arrays as
parameters. Write the ticket IDs and associated prices to a file named ‘[Link]’.
Each line in the file must have a format like: TicketID; TicketPrice.
For example: ‘V1-3291; R 1000.00’

# 6 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
Display a message stating that the data has been written to the file. Example of the
content of the text file (in Notepad):

3 In the ‘main()’ function:


To complete the code in the ‘main()’ function by declaring the arrays and other required
variables in the function. Uncomment the call statements as you complete the code for the
functions. Your functions must be able to communicate with the provided call statements. You
should NOT change the provided call statement.

Example program execution

Menu:
1. Capture Ticket Data
2. Compute Ticket Sales
3. Write to File
4. Exit
Enter your choice: 1

Enter ticket category (V – VIP, S – Standard, E – Economy): V

Ticket ID: V1-1041 ADDED SUCCESSFULLY!

<Menu Display>
Enter your choice: 1

Enter ticket category (V – VIP, S – Standard, E – Economy): E

Ticket ID: E2-1467 ADDED SUCCESSFULLY!

<Menu Display>
Enter your choice: 2

Summary of Ticket Sales


-------------------------------
1 VIP ticket(s): R 1000.00
1 Economy ticket(s): R 500.00

<Menu Display>
Enter your choice: 3

Ticket details WRITTEN to ‘[Link]’

# 7 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman
Assessment rubric

Mark
Item
allocation
Q Array and Struct Initialisation -
1 o proper initialisation and use of the ‘Artist’ struct /5
o Initialisation of the array of ‘Artist’ struct and keep track of number of items in the array /3
Function Implementations -
o ‘displayArtistInfo’ – Displaying all artist data /6
o ‘loadArtistsFromFile’ – Loading data from file, handling string manipulation /15
o ‘calculateTotalPerformanceFee’ – Calculate the total performance fee of available artists /6
Integration with Provided Code -
o successful incorporation of provided ‘main()’ function without any conflicts or issues /5
Sub-Total [40]
Q Array Initialisation using Pointers -
2 o proper initialisation of the three parallel arrays using pointers /4
Function Implementations -
o ‘captureTicketData’ – capturing ticket category and validating input, computing ticket price /4
based on category, and generating and storing unique ticket ID, array parameters as
pointers, reference parameters where applicable.
o ‘computeTicketSales’ – using data from the arrTicketPrices array to compile a summary of /4
number of tickets sold per category and income per category.
o ‘writeToFile’ – properly formatting and writing ticket details to ‘[Link]’, array
/4
parameters as pointers, reference parameters where applicable.
Integration with Provided Code -
o successful incorporation of provided ‘main()’ function without any conflicts or issues, /4
proper declarations of arrays, calling functions where appropriate.
Sub-Total [20]
Comments included in program (penalty 2), file name according to the
specification (penalty 2), correct file extension (project zipped) (penalty – not
marked), Logical flow and readability of the code (penalty range from 1 to 5,
depending on severity)
TOTAL 0 60

# 8 of 8

// CMPG 121 – Structured Programming Formal/Semester test SU 1 – SU 5


// Examinator: L Coetzee; Moderator: MJ Zeeman

Common questions

Powered by AI

The 'loadArtistsFromFile' function reads artist data from a text file, where each line contains artist information delimited by a hash character. It uses string-handling techniques to parse each line, extract data, and populate an array of 'Artist' structs. The function returns the number of structs stored, thereby playing a critical role in initializing the artist data set for further operations like display and fee calculations .

The programming best practices emphasized include using descriptive naming for variables and functions, the use of constants over magic numbers or hardcoded values, and validating user input to prevent errors and handle unexpected values . Indentation should be consistent, and spaces should be used between unrelated sections to enhance readability .

An artist record is structured as a struct with data members including 'name', 'genre', 'performanceFee', and 'available'. This design allows for organized and efficient storage of relevant artist information, enabling easy access and manipulation for tasks such as fee calculation and status checking .

The 'computeTicketSales' function analyzes data from the 'arrTicketPrices' array to calculate the number of tickets sold per category and the total revenue per category. This summary enables organizers to assess sales performance across different ticket types, aiding in financial analysis and strategic planning .

The unique ID for tickets is formulated by combining a category-based prefix (V for VIP, S for Standard, E for Economy), an incrementing number for each ticket category, and a 4-digit randomized number, connected by hyphens. This process ensures that each ticket ID is unique and easily identifiable by its category .

During ticket capture, the program validates user input to ensure it matches one of the designated categories (V, S, E). If the input is invalid, the program prompts for correct input, thus preventing erroneous data entry into the system and ensuring data integrity .

Using parameters ensures that functions operate independently without relying on global variables, which enhances modularity and reusability. In the Mzansi Music Festival program, if parameter-transfer is not implemented, no marks are awarded for the functions, emphasizing the importance of this practice in achieving a well-structured and graded program design .

The program achieves coordination by adhering strictly to the provided functional call statements and parameter structures. Functions are designed to match expected inputs and outputs, facilitating compatibility with the 'main' function. This ensures seamless integration and prevents rework of the functional calls .

Strict coding conventions enhance code readability and maintainability, making it easier for others to understand and modify. Commenting guidelines ensure that logic and complex operations are documented, aiding debugging and collaborative development by clarifying programmer intent .

The 'displayArtistInfo' function uses a flag and an optional genre string to filter the list of artists. If the flag is true, only available artists are displayed. The genre string allows the user to narrow down the list further by displaying only artists who belong to a specified genre. This filtering supports users in focusing on relevant artists based on availability and musical preferences .

You might also like