242 CO1027 Assignment-2 v1.3 EN
242 CO1027 Assignment-2 v1.3 EN
ASSIGNMENT 2
ASSIGNMENT SPECIFICATION
Version 1.3
1 Learning outcomes
After completing this assignment, students review and make good use of:
2 Introduction
This major assignment (BTL) is inspired by the 50th anniversary of the success of the Spring
1975 General Offensive and Uprising by our military and people, which led to the complete
liberation of the South and the reunification of the country.
In Part 1, we reenacted the Central Highlands Campaign, the opening campaign of the
Spring 1975 General Offensive and Uprising. Immediately afterward (at the end of March 1975),
our military and people continued to achieve victory in the Hue-Da Nang liberation campaign,
completely changing the course of the war.
Amid the rapid developments—where “one day was worth twenty years”—on April 14, 1975,
the Politburo decided to launch the Saigon-Gia Dinh Liberation Campaign, officially named
the Ho Chi Minh Campaign. This decision once again demonstrated the strategic vision of the
Politburo, the Central Military Commission, and the General Command in leading, directing,
and orchestrating the conclusion of the revolutionary war.
In this assignment, you are required to implement classes to simulate the progression of
the campaign. The details of the classes that need to be implemented will be specified in the
tasks below.
This assignment utilizes Object-Oriented Programming to reenact the Ho Chi Minh Campaign.
The objects in this assignment are represented through classes and described as follows.
Note:
• Students must carefully read the requirements to identify the derivative classes (sub-
classes), as they will not be explicitly described.
• Students should propose additional attributes, methods, or other classes to support the
implementation of the classes in this assignment.
• Within the scope of this assignment, when referring to distance, students should under-
stand it as Euclidean distance.
• Within the scope of this assignment, when calculated values need to be rounded to an
integer, students must round up.
• Within the scope of this assignment, Any value that exceeds the threshold (if a range is
specified) should be rounded to the nearest threshold.
Each military force participating in the war consists of different military units. There are two
main types of military units: Combat Vehicles (Vehicle) and Infantry Forces (Infantry).
Requirement: Implement the abstract class Unit with the following specifications:
1. Protected attributes:
• quantity: an integer representing the number of this type of military unit in the
army.
• weight: an integer representing the contribution weight to different military capabil-
ity indices.
• pos: of type Position, representing the position of this unit type on the battlefield.
2. Public constructor:
The constructor (public) takes parameters quantity, weight, and pos, which correspond
to the attributes of the same name. It initializes the attributes with the given parameter
values.
1 Unit ( int quantity , int weight , const Position pos )
5. Method getCurrentPosition, which returns the current Position of the moving object.
1 Position get Cu rr ent Po si tio n () const ;
6. Pure virtual method str, which returns a string representation of the object’s information.
1 virtual string str () const = 0;
3.2 Vehicles
Each army possesses a number of different types of combat vehicles (Vehicle). A vehicle type
is considered a military unit (Unit).
Where:
1. Private attributes:
• vehicleType: of type VehicleType, representing the type of vehicle.
2. Public constructor, declared as shown below. In addition to the parameters already men-
tioned in Unit, it includes additional parameters specific to Vehicle, with names and
meanings corresponding to the attributes described above.
3. Method getAttackScore (public), which returns a value computed using the formula for
the contribution score of a specific vehicle type:
Vehicle[attr_name=<attr_value>]
Where attr_name and attr_value are the attribute names and values of the correspond-
ing vehicle. The order of attributes to be printed follows this sequence: vehicleType,
quantity, weight, pos and separated by comma (",").
Each military force consists of different types of infantry (Infantry) serving within the army.
An infantry type is considered a military unit (Unit).
Where:
• SNIPER – Sniper
• ANTIAIRCRAFTSQUAD – Anti-aircraft squad
• MORTARSQUAD – Mortar squad
• ENGINEER – Combat engineer
• SPECIALFORCES – Special forces
• REGULARINFANTRY – Regular infantry
1. Private attributes:
• infantryType: of type InfantryType, representing the type of infantry.
2. Public constructor, declared as shown below. In addition to the parameters already men-
tioned in Unit, it includes additional parameters specific to Infantry, with names and
meanings corresponding to the attributes described above.
1 Infantry ( int quantity , int weight , const Position pos , InfantryType
infantryType )
3. Method getAttackScore (public), which returns a value computed using the formula for
the contribution score of a specific infantry type:
Where:
• typeV alue is the corresponding enum value of the infantry type in InfantryType.
• quantity, weight are the respective values of quantity and weight for that infantry
unit.
Special conditions:
• If the infantry type is SPECIALFORCES and the weight is a perfect square
number, the unit is classified as commandos, and an additional 75 points are added
to the contribution score.
• We define: The personal number of a non-negative integer in the year Y is the
single-digit number obtained by summing the digits of that number and the digits
of Y, repeatedly summing the digits of the result until only a single-digit number
remains.
In this case, the combat year is 1975. After considering the commando case, if the
personal number of the unit’s score exceeds 7, the unit receives additional rein-
forcements of 20% of its current quantity. Conversely, if the personal number is less
than 3, 10% of the current quantity will desert immediately. Adjust the quantity
attribute accordingly and recalculate the score.
4. Method str (public): Returns a string representation of the infantry unit’s information
in the following format:
Infantry[attr_name=<attr_value>]
Where attr_name and attr_value are the attribute names and values of the corre-
sponding infantry unit. The order of attributes to be printed follows this sequence:
infantryType, quantity, weight, pos and separated by comma (",").
3.4 Army
1. Protected attributes:
• LF: of type int, with a value in the range [0, 1000]. This value is calculated as the
sum of the score from all combat vehicles (Vehicle) that this army possesses.
• EXP: of type int, with a value in the range [0, 500]. This value is calculated as the
sum of the score from all infantry forces (Infantry) that this army possesses.
• name: of type string, representing the name of the army.
• unitList: of type UnitList*, representing the list of military units this army pos-
sesses. Further details will be provided in later sections.
• battleField: of type BattleField*, representing the battlefield where this army
fights.
2. Public constructor that takes an array of military units, the size of this array, the army’s
name, and the battlefield where the army fights. The constructor’s task is to compute the
appropriate values for LF and EXP, and add the units to unitList accordingly.
1 Army ( const Unit ** unitArray , int size , string name , BattleField *
battleField )
3. The fight method (fight) is a pure virtual function that takes an Army* (enemy) as the
opponent of the current army and a boolean parameter defense, describing whether the
battle is defensive or offensive. The default value is false (indicating an offensive battle).
The return type is void.
1 virtual void fight ( Army * enemy , bool defense = false ) = 0;
4. Pure virtual method str, which returns a string representation of the object.
1 virtual string str () const = 0;
In this campaign, our forces include the People’s Army of Vietnam and the Liberation Army of
South Vietnam (established in 1961). In this assignment, these are collectively referred to as the
Liberation Army. To represent the Liberation Army, we define a class named LiberationArmy.
LiberationArmy[attr_name=<attr_value>]
The attributes should be printed in the following order: name, LF, EXP, unitList, and
battleField and separated by comma (",").
At this time, the Saigon government’s military no longer had direct American combat support.
However, the U.S. still provided financial aid, weapons, logistics, and military advisory support.
Requirement: Implement the class ARVN (Army of the Republic of Vietnam) with
the following specifications:
– When the ARVN attacks, meaning the Liberation Army is defending, the Liber-
ation Army will not be defeated even when defending. The ARVN will lose the
battle and must reduce the quantity (quantity) of each military unit by 20%.
The corresponding combat indices should be updated. If any military units have
a quantity (quantity) of 1, remove them from the list and update the indices.
• Case: Defense (defense = true)
– In this case, the Liberation Army is attacking. According to the previous de-
scriptions, the Liberation Army may engage in battle and achieve victory. In
this scenario, the ARVN’s military units will be confiscated and repurposed
(as described above), meaning these units should be removed from the ARVN’s
unit list. Since the ARVN has lost, the remaining military units will suffer a
20% reduction in weight (weight). If no battle occurs, the ARVN forces remain
intact.
ARVN[attr_name=<attr_value>]
The attributes should be printed in the following order: name, LF, EXP, unitList, and
battleField and separated by comma (",").
To manage a military force’s units, we represent them as a singly linked list. The operations
that can be performed on this list include:
• Adding a unit to the list (insert method): If the unit is a vehicle (Vehicle), it should
be added to the end of the list. If the unit is an infantry unit, it should be added to the
front. If the unit already exists in the list, its quantity (quantity) should be updated
accordingly.
• Checking whether a military unit exists in the list (isContain method). This method
takes a VehicleType or InfantryType as input and returns True if found; otherwise,
it returns False.
Each army has a maximum number of units it can store in the list. This number depends
on the total strength S = LF + EXP of the army:
• If S is a special number in at least one of the odd prime bases less than 10, then
the maximum list capacity is 12.
• In all other cases, the capacity is 8.
1. Attributes: Students should define the necessary attributes, with one mandatory attribute
being capacity (of type int, private). Implement a corresponding constructor to ini-
tialize this in the army classes. Ensure that:
• If the unit is a vehicle (Vehicle), it should be added to the end of the list.
• If the unit is an infantry unit, it should be added to the front of the list.
2. Methods as described above, including:
1 bool insert ( Unit * unit ) ; // Returns true if insertion is successful
2 bool isContain ( VehicleType vehicleType ) ; // Returns true if it exists
3 bool isContain ( InfantryType infantryType ) ; // Returns true if it exists
4 string str () const ;
UnitList[count_vehicle=<v_c>;count_infantry=<i_c>;<unit_list>]
Where:
• <v_c>, <i_c>: Represent the number of vehicle units and infantry units in the list,
respectively.
• <unit_list>: A string representation of the units from the start to the end of the
linked list. Each unit should be printed in the format of its corresponding Unit str()
method, separated by commas (,).
3.6 Position
The class Position represents a location in the program. Position can be used to store the
positions of military units.
1. Two private attributes, r and c, both of type int, representing the row and column
positions, respectively.
2. Public constructor with two parameters, r and c, which are assigned to the row and
column attributes. These parameters have default values of 0.
1 Position ( int r =0 , int c =0) ;
3. Public constructor with one parameter, str_pos, which represents a position in string
format. The format of str_pos is "(<r>,<c>)", where <r> and <c> are the respective
row and column values.
1 Position ( const string & str_pos ) ; // Example : str_pos = "(1 ,15) "
4. Four getter and setter methods for the row and column attributes, declared as follows:
1 int getRow () const ;
2 int getCol () const ;
3 void setRow ( int r ) ;
4 void setCol ( int c ) ;
5. The str method returns a string representation of the position. The return format matches
the format of str_pos in the constructor. For example, if r = 1, c = 15, then str returns
"(1,15)".
1 string str () const ;
Each battlefield has terrain elements that affect the combat capabilities of the armies.
• Road (ROAD)
• Forested Mountains (FOREST)
• Deep River (RIVER)
• Fortification (FORTIFICATION)
• Urban Area (URBAN)
• Demilitarized Zone (temples, churches, hospitals, etc.) (SPECIAL ZONE)
Each terrain element impacts the combat indices of the armies differently.
2. Pure virtual method getEffect, which determines the effect of the terrain element on the
combat indices of the army.
1 virtual void getEffect ( Army * army ) = 0;
Effect on Liberation
No. Terrain Effect on ARVN
Army
1 Road No effect No effect
While the infantry forces
are highly proficient in com- Since this is a base area for
bat in mountainous ter- ARVN, the influence range
rain, military vehicles are is wider, although the effect
not suited for movement in is lower.
these areas. Within a radius of 4 units
Within a radius of 2 units from the mountain terrain
from the mountain terrain position:
position: • EXP increases
Forested • EXP increases by 20% of each
2
Mountains by 30% of each attackScore for in-
attackScore for in- fantry forces within
fantry forces within the affected radius.
the affected radius. • LF decreases by 5%
• LF decreases by 10% of each attackScore
of each attackScore for combat vehicles
for combat vehicles within the affected ra-
within the affected ra- dius.
dius.
Effect on Liberation
No. Terrain Effect on ARVN
Army
Infantry movement speed is
restricted. attackScore of infantry
3 Deep River attackScore of infantry units within a radius of 2
units within a radius of 2 units is reduced by 10%.
units is reduced by 10%.
LARINFANTRY, and
• If REGULARINFANTRY
is within a radius
units are within a ra-
of 5 units, each
dius of 3 units, each
attackScore of these
attackScore is in-
infantry units is in-
creased by:
creased by:
3 ∗ attackScore
2 ∗ attackScore
2∗D
D
where D is the dis-
where D is the dis-
4 Urban Area tance between the
tance between the
urban area and the
urban area and the
corresponding in-
corresponding in-
fantry unit. Other
fantry unit. Other
infantry forces are not
infantry forces are not
affected.
affected.
• ARVN’s combat vehi-
• Combat vehicles of
cles are not affected in
type ARTILLERY
urban areas.
will have their
attackScore reduced
by 50% if within a
radius of 2 units.
Effect on Liberation
No. Terrain Effect on ARVN
Army
Creates difficulties for the
ARVN has a strategic ad-
Liberation Army in ad-
vantage in these locations,
vancing. All military units
gaining a 20% increase in
5 Fortification within a radius of 2 units
attackScore for each mili-
from the Liberation Army
tary unit within a radius of
are reduced by 20% in
2 units.
attackScore.
No battles may occur. All military units within a radius
Demilitarized
6 of 1 unit around this area will have their attackScore
Zone
reduced to 0.
3.8 Battlefield
The Ho Chi Minh Campaign took place across five battlefronts, each with different battles.
Therefore, the battlefield for each front should be defined as a class. Assume that each battlefield
is represented as a 2D array.
1. Private attributes:
• n_rows and n_cols (of type int), representing the number of rows and columns
of the battlefield map.
• terrain, a private attribute representing a 2D array where each element of the
array is a TerrainElement. Students should choose an appropriate data type for the
terrain attribute.
2. Method str: Returns the string information of the battlefield
BattleField[attr_name=<attr_value>]
␣␣␣␣
The attributes are ordered sequentially as n_rows, n_cols and separated by a comma
(",").
3. Constructor with the following signature:
1 BattleField ( int n_rows , int n_cols , vector < Position * > arrayForest ,
Where:
• n_rows, n_cols: The number of rows and columns of the battlefield map.
• Arrays with the naming format array<Element> represent the positions of terrain
elements on the map. Any positions not included in these arrays are considered roads
(ROAD).
4. Public destructor to release dynamically allocated memory.
5. Additional methods may be required in later sections.
3.9 Configuration
A configuration file is used to define the settings for the program. The file consists of lines,
each following one of the formats below. Note that the order of the lines may vary.
1. NUM_ROWS=<nr>
2. NUM_COLS=<nc>
3. ARRAY_FOREST=[<pos1>,<pos2>,..]
4. ARRAY_RIVER=[<pos1>,<pos2>,..]
5. ARRAY_FORTIFICATION=[<pos1>,<pos2>,..]
6. ARRAY_URBAN=[<pos1>,<pos2>,..]
7. ARRAY_SPECIAL_ZONE=[<pos1>,<pos2>,..]
8. UNIT_LIST=[<unit1>,<unit2>,...]
9. EVENT_CODE=<ec>
Where:
1. <nr> represents the number of rows in the battlefield map, for example:
NUM_ROWS=10
2. <nc> represents the number of columns in the battlefield map, for example:
NUM_COLS=10
3. [<pos1>,<pos2>,..] represents the positions of terrain elements on the battlefield. Ex-
ample:
ARRAY_FOREST=[(1,2),(2,3),(3,4)]
represents the positions of forest elements (FOREST) on the battlefield.
4. [<unit1>,<unit2>,...] represents the list of military units for both armies. Each unit
follows the format:
UNIT_NAME(quantity,weight,position,armyBelong)
where armyBelong=0 corresponds to the Liberation Army, and armyBelong=1 corresponds
to ARVN.
Example:
1 UNIT_LIST =[
2 TANK (5 ,2 ,(1 ,2) ,0) ,
3 TANK (5 ,2 ,(3 ,2) ,1) ,
4 REGULARINFANTRY (5 ,2 ,(1 ,1) ,0) ,
5 REGULARINFANTRY (5 ,2 ,(3 ,3) ,1)
6 ]
7
5. <ec> represents the event code used to determine which army is on the offensive or
defensive in the current battle.
1. Private attributes:
• num_rows, num_cols: Represent the number of rows and columns of the battle-
field map.
• arrayForest, arrayRiver, arrayFortification, arrayUrban, arraySpecialZone:
of type vector<Position*>, representing the positions of terrain elements on the bat-
tlefield.
• liberationUnits: of type Unit*, representing an array of military units belonging
to the Liberation Army.
• ARVNUnits: of type Unit*, representing an array of military units belonging to
ARVN.
• eventCode: of type int, representing the event code that determines which army is
in the offensive position. The event code is in the range [00,99]. If the input value
exceeds 99, the last two digits of the number will be used as the event code. If the
input value is below 00, the event code will default to 00.
2. Constructor Configuration is declared as follows. The constructor takes filepath, a
string representing the path to the configuration file, and initializes the attributes ac-
cording to the specifications above.
Configuration[
<attribute_name1>=<attribute_value1>...
]
Each attribute and its corresponding value will be printed in the order listed in the
"Private attributes" section of this class. For each military unit, the string representation
will be obtained by calling the corresponding str method of the unit.
The battle on a battlefield is conducted by calling the fight method of the corresponding armies.
After a battle between two military units, if a unit’s attackScore ≤ 5, it will be removed from
its army’s military unit list.
Specific rules:
• If the event code is less than 75: The Liberation Army is on the offensive, while ARVN
is defending.
• If the event code is 75 or greater: ARVN initiates the attack. Once ARVN’s attack
concludes, the Liberation Army will immediately counterattack.
Requirement: Students should propose and implement the HCMCampaign class ac-
cording to the following requirements:
1. Attributes:
• config (Type: Configuration*)
• battleField (Type: BattleField*)
• liberationArmy (Type: LiberationArmy*)
• ARVN (Type: ARVN*)
2. Constructor that takes one parameter: the file path to the program’s configuration file.
The constructor initializes all necessary class information.
3. Method run: No input parameters. This method executes the battle between the two
armies on the specified battlefield according to the described sequence. At the start of
the battle, terrain elements affect combat indices before engagement begins.
4. Method printResult (Return type: string): No input parameters. Outputs the combat
indices of both armies after the battle in the following format:
LIBERATIONARMY[LF=<LF>,EXP=<EXP>]-ARVN[LF=<LF>,EXP=<EXP>]
where <LF> and <EXP> represent the LF and EXP values of the corresponding army.
4 Requirements
grading environment. Students must test their program in the LMS submission system
and resolve any errors there to ensure correct results in the final grading.
5. Modify hcmcampaign.h and hcmcampaign.cpp to complete this assignment while ensuring
the following:
6. Students are encouraged to create additional classes and methods to complete the assign-
ment.
7. Students must implement all classes and methods listed in this assignment. Failure to do
so will result in a score of 0. If a method or class cannot be fully implemented, students
must at least provide an empty implementation using curly braces {}.
5 Submission
Students must submit only two files: hcmcampaign.h and hcmcampaign.cpp before the deadline
specified in "Assignment 2 - Submission". Some basic test cases will be used to check whether
the submission compiles and runs correctly. Students can submit multiple times, but only the
last submission will be graded.
Due to system constraints, a high volume of submissions near the deadline may cause
technical issues. Students should submit their work as early as possible. Submissions made in
the last hour before the deadline are at the student’s own risk. Once the deadline passes, the
system will close, and no further submissions will be accepted. Submissions through any other
method will not be considered.
6 Additional Rules
• Students must complete this assignment independently and prevent others from copying
their work. Any violations will be subject to the university’s academic integrity policies.
• All decisions made by the assignment instructor are final.
• Students will not receive test cases after grading. However, the assignment score break-
down will be provided.
• The content of this assignment is harmonized with a question in the final exam that
covers a similar topic.
Students must complete the assignment using their own knowledge. If a student cheats on
this assignment, they will be unable to answer the harmony question in the final exam and will
receive a score of 0 for this assignment.
Students must complete the harmony question in the final exam. Failure to do so will result
in a score of 0 for this assignment and failure in the course. No exceptions or explanations
will be accepted.
If a student is found guilty of cheating, they will receive a zero for the entire course
(not just the assignment).
After submission, some students may be randomly selected for an interview to verify that
their work was completed independently.
10 Conclusion
The Spring 1975 General Offensive and Uprising was a resounding success. On April 30, 1975,
the Saigon government declared unconditional surrender, leading to the liberation of the South
and the complete reunification of the country. This marked the beginning of a new era for the
nation—an era of independence, peace, self-reliance, and strength.
In celebration of the 50th anniversary of the liberation of South Vietnam and national
reunification (April 30, 1975 - April 30, 2025), we hope that through this assignment, students
will revisit the nation’s heroic history and cultivate a spirit of patriotism to contribute to the
country’s continued growth and development as it advances into a new era.