0% found this document useful (0 votes)
30 views

Assignment v5.0 EN

nmlt1

Uploaded by

hoangdats2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Assignment v5.0 EN

nmlt1

Uploaded by

hoangdats2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

VIETNAM NATIONAL UNIVERSITY - HO CHI MINH CITY

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY


FACULTY OF COMPUTER SCIENCE AND ENGINEERING

INTRODUCTION TO PROGRAMMING - CO1003

ASSIGNMENT

JOB FAIR

HO CHI MINH CITY, OCTOBER 2024


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

ASSIGNMENT SPECIFICATIONS
Version 5.0 (Updated 10/11/2024)

1 Output Standards

Upon completing this project, students will review and become proficient in using:

• Conditional branching structures


• Loop structures
• One-dimensional and two-dimensional arrays
• String processing
• Functions and function calls
• User-defined structures (structs)

2 Introduction

The Job Fair is an event that connects students with companies through various booths, en-
abling companies to introduce job positions while students and applicants can participate if they
feel suited. This is also an opportunity for students to explore real demands in the recruitment
market.

Furthermore, when registering, companies also need to know the current number of avail-
able booths and the list of vacant booths.

Each company registering must have a full name and an abbreviation. In this exercise, we
define each company’s abbreviation as the initial letter of each word in the company’s name.

The booths are arranged into two rows facing each other. In this project, each row will
have 15 booths.

In this project, we will develop the core features of an application to assist the organizing
committee in managing booths and organizing the event.

3 Application Requirements

Booth Status Array: This is a two-dimensional integer array, with each dimension containing
15 elements. The index of each booth in the first row ranges from 0 to 14. For the second row,

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 1/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

the booth index is calculated by adding 15 to the first row index, so it starts at 15 and increases
incrementally (the first booth is 15, the second booth is 16, etc.). The booth status includes:

• Vacant booth: 0
• Registered booth: 1

Enterprise Array: This is a one-dimensional array of type struct Enterprise with 30


elements, where each entry represents the information of a successfully registered enterprise.
The information is sequentially added based on successful registrations, unaffected by the booth
index order.

In this exercise, to simplify the layout and booth status diagram, this array is stored sep-
arately from the booth status array. Therefore, when performing data modifications, students
need to update both arrays to ensure data synchronization. At a minimum, achieving 50% of
the exercise score requires students to update at least the booth status array, disregarding the
enterprise array.

3.1 Abbreviation Registration

As described above, each enterprise requires an abbreviation. The abbreviation for an enterprise
is defined as the initial letters of each word in the enterprise’s name. Below is an example:

Example 1: Examples of enterprise abbreviations:

• Trường Minh Thịnh: TMT


• VNG: V
• FPT Software: FS

For this exercise, assume that the input data will not contain enterprises with duplicate
abbreviations.

Requirement 1 : Define the function getAbbreviation(char* name, char* abbre)

• Function Name: getAbbreviation


• Input Parameters:
– name (type char*): The name of the enterprise, passed in as input, which must
remain unchanged during processing.
– abbre (type char*): The string that will store the enterprise’s abbreviation.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 2/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• Return: The abbreviation of the enterprise, assigned to the abbre parameter.


• Requirement: Generate the abbreviation for the enterprise name.

3.2 Command Types

Since the application operates via the command line, the program needs to determine the type
of command issued in order to call the appropriate function.

Details of each command will be described in subsequent sections. The Enum Command-
Type is used to represent the command type, including values REGISTER, ALTER, SHOW,
DELETE, QUIT, and INVALID, corresponding to the command types Register, Alter, Show,
Delete, Quit, and an invalid command, respectively.

Requirement 2 (0.5 points): Implement the function getCommandType that re-


turns the command type of a given input command. The function specifications are as follows:

• Function Name: getCommandType


• Input Parameter:
– command (type char*): a string containing a command
• Return: The return value is of type CommandType, corresponding to the type of the
input command.
• Function Requirement: Let w be the first word in the user’s command string. If w matches
one of the command types listed above, the function should return the corresponding enum
value of CommandType. Otherwise, if w is an invalid word, the function should return
the value INVALID.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 3/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Example 2: Examples of getCommandType:

• Function call

getCommandType("Show [:10]")

Return value:

SHOW

• Function call

getCommandType("Quit")

Return value:

QUIT

• Function call

getCommandType("Showall")

Return value:

INVALID

3.3 Enterprise

Requirement 3 : Define the body of the struct Enterprise

Requirement: Define the body of the initialized struct Enterprise with the following
attributes:

• booth_index: Integer type, stores the index of the booth registered by the enterprise.
• name: Character array type, stores the full name of the enterprise.
• abbre: Character array type, stores the abbreviation of the enterprise.
• itemValue: Value of the item at the booth (details in section 3.9)
• itemWeight: Weight of the item at the booth (details in section 3.9)

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 4/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Requirement 4 : Define the function printEnterpriseDetails(Enterprise e)

• Function Name: printEnterpriseDetails


• Input Parameter:
– Enterprise e: The enterprise whose information is to be printed
• Requirement: Print the enterprise information in the following format:

||booth_index||name||abbre||itemValue||itemWeight||

To create an enterprise, we need to implement a function named createEnterprise.

Requirement 5 : Define the function createEnterprise(Enterprise* e, int booth_index,


int itemValue, int itemWeight, char* name, char* abbre)

• Function Name: createEnterprise


• Input Parameters:
– Enterprise* e: The enterprise to be created. If the input value of e is nullptr, memory
should be allocated for e before proceeding.
– booth_index, name, abbre, itemValue, itemWeight: Values assigned to the corre-
sponding attributes of e
• Requirement: Assign values to the booth, name, and abbre attributes.

3.4 Components of the Registration Command

Before the event, the organizing committee will send a booth layout to all relevant enterprises.

The syntax to register a booth is

Register [<name>] [itemValue] [itemWeight] [booth_index]

Where:

• name: Full name of the enterprise


• booth_index: Index of the booth being registered
• itemValue: Value of the item at the booth (See section 3.9)
• itemWeight: Weight of the item at the booth (See section 3.9)

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 5/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

If the booth_index field is left blank, the default booth assigned to the enterprise is
calculated based on the formula:

index = (num_abbre ∗ 30)%26

where: num_abbre is the number of characters in the enterprise’s abbreviation.

In the specific case where booth_number is left blank, if the calculated index corresponds
to an invalid state (i.e., a booth that is already registered), increment the index by one until
an empty booth is found. If no empty booth is found upon reaching the upper limit, decrement
the index by one until an empty booth is located. Once a suitable booth is identified, change
its status to registered and return a successful registration.

In other cases, if the booth being registered is empty, set its status to registered and return
a successful registration. Otherwise, return an unsuccessful registration.

Upon successful registration, update the corresponding values in the enterprise array.

Assume that all Register commands entered are valid and fall under one of the two scenarios
above.

Requirement 6 : Implement the function registerEnterprise(int map[2][15], Enterprise


enterpriseArray[30], char* name, int booth, int itemValue, int itemWeight, int* out_booth,
char* out_abbre )

• Function Name: registerEnterprise


• Input Parameters:
– map[2][15]: Array representing the booth status.
– enterpriseArray[30]: Array of enterprises.
– name: Full name of the enterprise.
– booth: The booth index the enterprise wishes to register. If the booth parameter in
the Register command is omitted, booth is set to -1.
– itemValue: The item value at the booth.
– itemWeight: The item weight at the booth.
– out_booth: The booth index where the enterprise is registered.
– out_abbre: The abbreviation of the enterprise name.
• Return: Returns booth_index+200 and assigns it to out_booth if registration is successful;
otherwise, returns booth_index + 100 and assigns it to out_booth. The abbreviation is
assigned to out_abbre.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 6/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• Requirement: Assist the enterprise in registering an abbreviation and booth. Return the
corresponding values in out_booth and out_abbre, and update both the status and enter-
prise arrays accordingly.

Example 3: A complete Register command: Register [VNG] [1] [2] [2]


Assume that all booths are currently empty (i.e., all states are 0).
Execution includes:

• Generate an abbreviation for the enterprise -> Call getAbbreviation to return the
string "V". Assign this value to out_abbre.
• Check and update map[0][1] = 1. Assign the value 1 to out_booth.
• Create an enterprise with abbre as "V", itemValue =2, itemWeight=2 and booth as
1, then add it to the array at enterpriseArray[0].

Example 4: An incomplete Register command: Register [FPT Software] [] [2]


[2]
Assume the current booth statuses show booths 7, 8, 9,...,30 are registered.
Execution includes:

• Generate an abbreviation for the enterprise -> Call getAbbreviation to return the
string "FS". Assign this value to out_abbre.
• Calculate the booth index using the formula:

index = (2 ∗ 30)%26 = 8

At map[0][8], the status is 1, so increment the index. Since subsequent booths are
also occupied, decrement the index.
At map[0][7], the status remains 1, so continue decrementing until reaching index =
6, where the status is 0. Thus, index = 6 is suitable.
• With index = 6, itemV alue = 2, itemW eight = 2 and abbre = ”F S”, proceed
with registration as in the example above.

3.5 Show Command Components

The Show command displays information for one or more booths. Show commands can include:

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 7/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Show map
Show &0
Show &1
Show #0
Show #1
Show [num]
Show [from_index:to_index]

Details:

• Show map: Displays the layout of the booth map. The print format is as follows:

|0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|
–-
|status_0|...|
–-
|status_15|...|

• Show &0: Displays the indices of all booths currently unregistered. The print format is:

Index[index_0, index_1,...]

• Show &1: Displays the indices of all booths currently registered. The print format is:

Index[index_0, index_1,...]

• Show #0: Displays the total count of booths currently unregistered. The print format is:

Total: total_0

• Show #1: Displays the total count of booths currently registered. The print format is:

Total: total_1

• Show [num]: Displays detailed information of the booth at the specified index num. If
the booth at num is empty, displays "NONE". The print format follows the printEnter-
priseDetails function.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 8/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• Show [from_index:to_index]: Displays detailed information for booths from index from_index
to to_index. If a booth at a given index is empty, displays "NONE". The print format is:

Index index_0: [enterprise_at_index_0]


Index index_1: [enterprise_at_index_1]
...

Requirement 7 : Implement the function showMap(int map[2][15], Enterprise enter-


priseArray[30])

• Function name: showMap


• Input parameters:
– map[2][15]: Array representing the booth status
– enterpriseArray[30]: Array containing information about registered enterprises.
• Requirement: Display the booth status layout on the screen according to the "Show map"
command format. Each booth should be printed in the exact index order.

Requirement 8 : Implement the function showIndexOfStatus(int map[2][15], int status)

• Function name: showIndexOfStatus


• Input parameters:
– map[2][15]: Array representing the booth status
– status: The booth status to be displayed.
• Requirement: Display the indices of booths with the corresponding status on the screen
according to the "Show &0" or "Show &1" command format.

Requirement 9 : Implement the function showTotalOfStatus(Enterprise enterpriseAr-


ray[30], int status)

• Function name: showTotalOfStatus


• Input parameters:
– enterpriseArray[30]: Array containing information about enterprises.
– status: The booth status to be counted (0: vacant, 1: registered).
• Requirement: Display the total number of booths with the corresponding status on the
screen according to the "Show #0" or "Show #1" command format.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 9/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Requirement 10 : Implement the function showIndexBracket(int map[2][15], Enterprise


enterpriseArray[30], int start, int end)

• Function name: showIndexBracket


• Input parameters:
– map[2][15]: Array representing the booth status
– enterpriseArray[30]: Array containing information about registered enterprises.
– start: Starting booth index to be displayed.
– end: Ending booth index to be displayed. If end is -1, display only the booth
information at start.
• Requirement: Display the information of booths from index start to end on the screen
according to the format of the "Show [num]" or "Show [from_index:to_index]" command.

Requirement 11 : Implement the function handleShowCommand(int map[2][15], En-


terprise enterpriseArray[30], char *command)

• Function name: handleShowCommand


• Input parameters:
– map[2][15]: Array representing the status of each booth (0: vacant, 1: registered).
– enterpriseArray[30]: Array containing information about registered enterprises.
– command: String containing the "Show" command to be parsed.
• Requirement: Parse the "Show" command in command to call the corresponding func-
tion. For example, if the command is "Show map," call the showMap function; if it is
"Show &0," call the showIndexOfStatus function.

3.6 Command Elements for Modifying Information (Alter)

The Alter command is used to change the booth that an enterprise has registered. The item-
Value and itemWeight fields are specified as non-modifiable using the Alter command.

The syntax for the command is as follows:

Alter [<abbre>] [register_booth] [new_booth]

Where:

• abbre: Abbreviation of the enterprise name

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 10/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• register_booth: The index of the booth currently registered


• new_booth: The index of the booth to be changed to

Detailed Description

1. Case when new_booth is unspecified:


• By default, if the parameter new_booth is not provided, the system will attempt to
find an available booth starting from the current booth index (register_booth),
incrementing the index by 1 unit.
• If the new index points to an occupied booth (not available for registration), the
system will continue to increment the index until a vacant booth is found.
• If the index reaches the limit without finding an empty booth, the system will begin
decrementing the index by 1 unit (starting from the registered booth) until it locates
an available booth.
• If no vacant booth is found, the system will return an unsuccessful alteration result.
2. Case when new_booth is specified:
• If the index new_booth is specified and the booth at this index is vacant, the system
will move the enterprise’s booth to the new index and return a success result.
• If the new_booth index is already registered to another enterprise (booth is occu-
pied), the system will return an unsuccessful result.

Assume that all Alter commands received are valid and belong to one of the two cases
above.

Additional Requirement:

After a successful change, the system must update both the booth status array and the
enterprise information array to ensure data consistency.

Requirement 12 : Implement the alterEnterprise function:

• Function Name: alterEnterprise


• Input Parameters:
– map[2][15]: Array representing the status of each booth (0: vacant, 1: registered).
– enterpriseArray[30]: Array holding information on registered enterprises.
– abbre: Abbreviation of the enterprise that wishes to change booths.
– registerBooth: The currently registered booth index of the enterprise.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 11/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

– newBooth: The new booth index to switch to. If this value is -1, the system will
automatically find the nearest vacant booth.
– out_booth: Pointer containing the registered booth after alteration.
– out_abbre: Pointer containing the enterprise’s abbreviation.
• Return Value: Return booth_index + 200 and assign this to out_booth if the adjustment
is successful. If unsuccessful, return booth_index + 100 and assign it to out_booth.
• Requirement: Help the enterprise switch booths, updating the values in out_booth and
out_abbre, and adjust both the booth status array and the enterprise information array
for data consistency. If newBooth is unspecified, the system will automatically locate and
register the nearest vacant booth.

3.7 Delete Command Components

A registered booth can be deleted using the Delete command. The command syntax is:

Delete [<abbre>] [registerBooth]

Where:

• abbre: The abbreviation of the enterprise.


• registerBooth: The registered booth index.

Assume that the booth being deleted belongs to the corresponding enterprise, with no
exceptions. Deletion is an action that updates the booth status array at that position to vacant
and removes the enterprise from the enterprise array.

Requirement 13 : Implement the deleteEnterprise function

• Function Name: deleteEnterprise


• Input Parameters:
– map[2][15]: Array representing the status of each booth (0: vacant, 1: registered).
– enterpriseArray[30]: Array holding information on registered enterprises.
– abbre: Abbreviation of the enterprise that wishes to delete its booth.
– registerBooth: The currently registered booth index of the enterprise.
• Return Value: The total number of vacant booths, assigned to totalEmpty.
• Requirement: Execute the booth deletion action as described.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 12/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

3.8 Input Command Processing

This is a general function to handle and call the corresponding command function based on the
user input.

Requirement 14 : Implement the handleCommand function

• Function Name: handleCommand


• Input Parameters:
– command: The command issued by the user.
– map[2][15]: Array representing the status of each booth (0: vacant, 1: registered).
– enterpriseArray[30]: Array holding information on registered enterprises.
– commandType: The command type, which will be determined and assigned.
• Return Value: The type of command issued by the user, assigned to commandType. Pro-
cess and return the corresponding map and enterpriseArray.
• Requirement: Parse the string to identify the command type and call the corresponding
function.

3.9 Student’s Knapsack

Assume each participating student has a knapsack to carry items received from each booth.
Each knapsack has a maximum capacity, with a total weight limit of 15. Each booth has one
item with a specific weight and value, where item weight is an integer in the range [1,10] and
item value is an integer in the range [-5,5].

The student needs to visit booths and collect the optimal set of items to achieve the highest
total value without exceeding the knapsack’s capacity.

Requirement 15 : Implement the knapsack function

• Function Name: knapsack


• Input Parameters:
– enterpriseArray[30]: Array holding information on registered enterprises.
– maxWeight: The maximum capacity of the student’s knapsack.
– numOfEnterprises: Number of enteprises in enterpriseArray
– index: The index to start traversing of the enterpriseArray array, by default it always
starts from 0 (used for recursion)

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 13/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• Return Value: The maximum total value the student can collect.
• Requirement: Implement the function to help the student find an optimal list of booths
to maximize the item value.

Example 5: Assume the following input data:

• Registered booths include: 0, 1, 3, 5, 7, 13, 14


• Item values at each booth are: 3, -2, 4, 5, -1, 2, 5
• Item weights at each booth are: 3, 1, 4, 7, 8, 2, 1
• Maximum knapsack weight is 10

The most suitable and optimal selection includes booths: 0, 3, and 14 with:

• Total value: 12
• Total weight: 8

The booth combination {5, 13, 14} also yields a maximum value of 12; however, the total
weight is 10. Although this does not exceed the knapsack’s maximum capacity, it is not
the most optimal solution.

Hint: Research the Knapsack problem.

4 Submission
Students should download the following files from the course website:

jobfair.c Initial source code


NMLT-JobFair-Assignment.pdf Assignment description file

The file jobfair.c is the initial source code. Students must use this source code and imple-
ment their solution between the following lines:

• // —— Begin: Student Answer ——


• // —— End: Student Answer ——

For submission, students should upload their assignment on the LMS of the course. Stu-
dents will enter their assignment code in the same manner as previous exercises. The code
submitted should be the implementation written between the lines above. Students are not
allowed to include any additional libraries other than those provided in the initial source code.
The submission platform provides the following options:

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 14/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

• Trial Submission Area: Students can submit their work and have it tested on 5 test
cases to identify syntax errors and basic logic errors. Submissions can be made an un-
limited number of times here.
• Official submission areas will be announced later.

In each area, except the Trial Submission Area, students can make up to 10 submis-
sions. For each submission, students have 10 minutes to submit and check their code. Only
the first "Check" click is counted for scoring; subsequent attempts will not count. Scores will
be displayed only after you click "Complete Submission." The highest score from all attempts
will be used as the final score.

The submission deadline is provided on the designated area on the site. The link will
automatically close at the deadline, preventing late submissions. To avoid potential submission
issues, students MUST submit their work at least one hour before the deadline.

Students must verify their program on MinGW and in the Trial Submission Area
before final submission.

5 Assignment Harmony
The final exam for this course will include some Harmony questions based on the content of
the assignment. Assume the assignment score achieved by a student is a (out of 10), and the
total score for the Harmony questions is b (out of 5). Let x be the final assignment score after
Harmony. The final score will be combined with 50% of the Harmony score as follows:

• If a = 0 or b = 0, then x = 0
• If both a and b are non-zero, then

a a
x= + HARM ( , b)
2 2

where:
2xy
HARM (x, y) =
x+y

Students must complete the assignment independently. If a student cheats on the assign-
ment, they will be unable to answer the Harmony questions and will receive a score of 0 for the
assignment.

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 15/16


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Students must answer the Harmony questions on the final exam. Failure to answer will
result in a score of 0 for the assignment and course failure. No explanations or exceptions
will be accepted.

6 Handling Cheating
The assignment must be completed independently. Cheating includes the following cases:
• Unusual similarities between code submissions. In this case, ALL submissions will be
considered cheating. Students must protect their assignment code.
• Students cannot explain the code they submitted, except for the pre-existing code pro-
vided in the initial program. Students may refer to any resource, but they must understand
every line of code they write. If a student does not fully understand the code from a source,
they are strongly advised NOT to use it; instead, rely on their learning.
• Submitting another student’s work under their account.

If cheating is confirmed, students will receive a 0 for the entire course (not just the assignment).

NO EXPLANATIONS
OR EXCEPTIONS WILL BE ACCEPTED!

After each assignment is submitted, some students will be randomly selected for an inter-
view to prove that the assignment submitted is their own work.

7 Changes Compared to the Previous Version


• Update function description of requirement 15 (01/11)
• Update the input parameters of requirements 06, 13, 15 (03/11)
• Update the input parameters of requirment 07 (08/11)
• Update the input parameters of requirement 08, 10 (9/11)
• Update the example of section 3.4 (10/11)

———–GOOD LUCK WITH YOUR ASSIGNMENT———–

Introduction to Programming’s assignment - Semester 1 (2023 - 2024) Page 16/16

You might also like