CityU CS2311 2020/21 Sem B
Assignment 2
due on 30 April 2021
CS2311 Computer Programming 2020/21 Semester B Department of Computer Science City University of Hong Kong Assignment Two
Due Date: 30 April 2021 (Friday) 23:59
All questions should be submitted in Canvas. Note that all solutions will be assessed by (1) correctness, (2) programming styles (including comments), (3) non-redundancy in expressing solutions, and (4) efficiency, if applicable. In particular, Question 4 will consider the efficiency aspect in marking.
This assignment contains 5 questions named as Q1 to Q5. Q5 has 10% bonus.
Your solutions are forbidden to INCLUDE any library other than
Solution Submission Instruction:
• You only need to submit the content of .cpp files of your solutions for the five questions.
• In Canvas, there are 5 submission links, one for each question.
o Submit your C++ code for Question 1 to the submission link for Question 1, o Submit your C++ code for Question 2 to the submission link for Question 2, o Submit your C++ code for Question 3 to the submission link for Question 3, o Submit your C++ code for Question 4 to the submission link for Question 4, o Submit your C++ code for Question 5 to the submission link for Question 5.
Copy and Paste Your Code developed for Question 1 into “Submission for Q1” and then press [submit assignment]. Repeat the procedure for each question. Remember to submit through different submission links.
Submission Example.
1
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Question
mark
Context
TA responsible for inquiry
Eamil Address
Q1
20
Array
Hao Zhang
hzhang339-c@my.cityu.edu.hk
Q2
20
File I/O, String
Alan Nguyen
tnguyenhu2-c@my.cityu.edu.hk
Q3
20
Pointer
Andrew Zhu
binzhu4@gapps.cityu.edu.hk
Q4
20
Recursion
Jankin Wei
zywei4-c@my.cityu.edu.hk
Q5
20
Class and Object
Imran Ashraf
iashraf3-c@my.cityu.edu.hk
Bonus
10
Extension of Q5
Imran Ashraf
iashraf3-c@my.cityu.edu.hk
2
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Q1. Sum Matrix Game [20%]
Sum Matrix is a number placement game.
In this game, an n x n matrix is filled with numbers such that (1) the sum of the numbers in each row or each column is all same, and (2) all the numbers from 1 to n*n should be placed in the matrix. The program should develop the matrix based on the following given rules.
1. The program should ensure the input value n as an odd number in the range of 1 to 11. Otherwise, the program should display the following message and terminate: Please enter an odd positive number in the range of [1-11]. Bye.
2. The possible range of values in each cell of the matrix should be a product of the input odd number.
• E.g., For sum matrix of order 3*3, the cell values should be in the range of (1-9)
• E.g., For sum matrix of order 5*5, the cell values should be in the range of (1-25)
3. In the output, set the width of each column of the matrix to 4 characters and there is one space to separate two columns.
4. Note that the cells in your matrix may have different values. (There are multiple solutions, and you only need to generate one possible solution.)
Hints:
• Observe where to place “1” in a particular matrix and the pattern to place “2”, “3”, “4”, and so
on. You will observe a general pattern. Example 1
Example 2
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
2
Please enter an odd positive number in the range of [1-11]. Bye.
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
3
The Sum Matrix for 3 * 3 Order is
8 1
3 5
4 9
6 ——-> 15
7 ——-> 15
2 ——-> 15
—- —- —-
15 15 15
Example 3
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
5
The Sum Matrix for 5 * 5 Order is
17 24
23 5
4 6
10 12
11 18
1 8
7 14
13 20
19 21
25 2
15 ——-> 65
16 ——-> 65
22 ——-> 65
3 ——-> 65
9 ——-> 65
—- —- —- —- —-
65 65 65 65 65
3
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021 Example 4
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
7
The Sum Matrix for 7 * 7 Order is
30 39 38 47 46 6
5 14 13 15
21 23
22 31
48 1 7 9 8 17
16 25
24 33
32 41
40 49
10 19
18 27
26 35
34 36
42 44
43 3
28 ——-> 175 29——->175 37——->175 45 ——-> 175
4 ——-> 175
12 ——-> 175
20 ——-> 175
2 11
—- —- —- —- —- —- —-
175 175 175 175 175 175 175
Example 5
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
9
The Sum Matrix for 9 * 9 Order is
47 58 69 80 1 12 23 34 45——->369 57 68 79 9 11 22 33 44 46——->369 67 78 8 10 21 32 43 54 56——->369 77 7 18 20 31 42 53 55 66——->369
6 17 19 30 41 52 63 65 76——->369 16 27 29 40 51 62 64 75 5——->369 26 28 39 50 61 72 74 4 15——->369 36 38 49 60 71 73 3 14 25——->369 37 48 59 70 81 2 13 24 35——->369
—- —- —- —- —- —- —- —- —-
369 369 369 369 369 369 369 369 369
Example 6
Enter an odd number (n) for (n*n) matrix [Max Matrix Size: 11*11]
11
The Sum Matrix for 11 * 11 Order is
68 81 94 107 120 1 14
80 93 106 119 11 13 26
92 105 118 10 12 25 38
104 117 9 22 24 37 50
116 8 21 23 36 49 62
7 20 33 35 48 61 74
19 32 34 47 60 73 86
31 44 46 59 72 85 98
43 45 58 71 84 97 110
55 57 70 83 96 109 111
56 69 82 95 108 121 2
—- —- —- —- —- —- —-
27 40 53 66——->671 39 52 65 67——->671 51 64 77 79——->671 63 76 78 91——->671 75 88 90 103——->671 87 89 102 115——->671 99 101 114 6——->671
100 113 5 18——->671 112 4 17 30——->671 3 16 29 42——->671 15 28 41 54——->671
—- —- —- —-
671 671 671 671 671 671 671 671 671 671 671
4
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Q2. Document Correction and Alignment Problem [20%]
Nowadays, the natural language processing technology is increasingly more mature. Recently the Beetles Phone Technology company released their latest smart phone, Beetles Resolver 66. The most eye-catching part of their release conference is not their new smart phone, but rather, a speech recognition input method Taxman input method.
Now suppose we have a document, and the content of which is generated by a speech recognition input method. Due to the error of the speech recognition input method, some continuously duplicated words appear in the content. Also, the format of the content is messy because of different length of each line (see the content of D1.txt in example).
You are required to write a program to remove the word duplication and align the content based on the following instructions:
1) Your program can assume that every word in the input document consist of at most 20 characters, the input document may be jammed with empty line, but the whole input document represents one single paragraph with at most 1000 words. Similarly, your output document should contain one paragraph with at most 1000 words.
2) The given document is a text file, named as document.txt, and the output text file is called output.txt. Your program should place it in the project directory of your VS C++ project.
3) Your program only needs to handle the duplication for a single word, like “The the the world”. The duplication for multiple words, like “The world the world”, will not appear in the given document read by your program. That is, if there is a consecutive sequence of same word (irrespective to the use of capital letters and lowercase letters), then it is a duplication of that single word.
4) Your program can assume that the following characters consider as punctuations in an English sentence: comma and full stop. All other characters are treated as a part of a word. In Example 2 on next page, “(Friday)” is a word. In this case, “(Friday) Friday” has no word duplication and your program needs not to correct this sequence of characters.
5) The number of the duplication is indefinite.
6) Each duplication of a single word should be replaced by a single occurrence of that word after your
correction. For example, “The the the world” should become “The world” after your correction.
7) After the alignment, each line should contain exactly 60 characters (contain the space and
punctuations), with the exception of the last line.
8) Your program can align the content by adjusting the number of words per line and the space
between the words. The space number between the words should be determined by the total space available and the total words number in this line. There is no space between words and punctuations.
a) E.g., if a line can contain 4 words and 3 spaces, then the amounts of space characters in
between two consecutive words on this line should be 1, 1, and 1.
b) E.g., if one line can contain 4 words and 5 spaces, then the amounts of space characters in
between two consecutive words should be 2, 2, 1.
9) After the alignment, each line should start with the word and end with the word or punctuations.
10) No word can be spited during the alignment process.
11) The result is required to be stored in a text file named as output.txt.
5
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Hints:
1. Your program may consider using a two-dimensional array to keep 1000 text strings, each
with a length sufficient to keep your required characters (including the end-of-string character
‘\0’)).
2. Your program may consider the logics outlined below.
a. It read the lines from the given text file line by line.
b. For each line, identify each word together with a possible ending punctuation
appending to it and keep that string into an entry in the above-mentioned two-
dimensional array.
c. Now you keep the whole text document as a sequence of words in an array.
d. Your program should then compare whether two consecutive words in the array refer
to the same word. If you find a duplicated word, then you can use your strategy to either remove that duplicated work from the array or mark the corresponding entry in the array as “duplicated”.
e. Now, you can scan the array from the first entry and decide the length of each entry. While your scanning, you can determine which words to be placed in the same line in the output text file together with the number of space characters you needed to separate the words in that output line.
f. You should then output that line to the text file.
g. Of course, before your program ends, it should close all files opened by it.
3. Your program may use strlen() and strcmp(), strcpy(). Note that in Visual Studio 2019, the functions strcmp() and strcpy() are not allowed by default. See Slide 28 of the Lecture note L08a to observe how to bypass the limitations. You may use strcmp_s() instead of strcmp()
and strcpy_s() instead of strcpy(), which are directly supported by VS 2019 by default.
4. Since duplicated occurrences of the same words (e.g., The the the) may be in different combinations of uppercase and lowercase characters. Your program may firstly convert them into all lowercases and then do a comparison. You may just assume that the first occurrence
is the one you wish to put into the text file output.txt.
5. A word in the given document may be appended with a full stop or a comma. Since it is a text
file, a line also ends with the end-of-line character (‘\0’). To identify a word, your program should consider whether a word is ended with a full stop, a comma, or the end-of-line character.
6
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Example 1:
Input document:
Output Content of Output.txt is as follows
Example 2:
Input document:
The the the town revolved around the river river. In summer,
when the blazing sun sun sun sun beat beat down, it dozed under the weight of of sultry days. On Main Street a sow and her litter litter
litter of pigs might root along the wooden side walks, sharing the
deeply deeply rutted rutted roadway with foraging hens and
and and and a hound languidly scratching his fleas fleas.
The town revolved around the river. In summer, when the blazing sun beat down, it dozed under the weight of sultry days. On Main Street a sow and her litter of pigs might root along the wooden side walks, sharing the deeply rutted roadway with foraging hens and a hound languidly scratching his fleas.
CS2311 Computer Programming
2020/21 Semester B
Department of Computer Science
City University of Hong Kong
Assignment Two
Due Date: 30 April 2021 (Friday) 23:59
All questions should be submitted in Canvas. Note that all solutions will be assessed by (1) correctness, (2) programming styles (including comments), and (3) non-redundancy in expressing solutions, if applicable.
This assignment contains 5 questions named as Q1 to Q5. Q5 has 10% bonus.
Your solutions are forbidden to INCLUDE any library other than
Output: Content of Output.txt is as follows
CS2311 Computer Programming 2020/21 Semester B Department of Computer Science City University of Hong Kong Assignment Two Due Date: 30 April 2021 (Friday) 23:59 All questions should be submitted in Canvas. Note that all solutions will be assessed by (1) correctness, (2) programming styles (including comments), and (3) non-redundancy in expressing solutions, if applicable. This assignment contains 5 questions named as Q1 to Q5. Q5 has 10% bonus. Your solutions are forbidden to INCLUDE any library other than
7
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Q3. Pointer and Dynamic Array [20%]
The code on the next page is an executable solution for Exercise 5 of Tutorial 7 on Array.
Your task is to (1) rewrite the program to perform the same computation that meets the following requirements. Note that you can use your own array-version programs as long as your program meets the following requirements.
• Every array in the program is a dynamic array.
• Except the statement in which it uses of the “new” operator (e.g., int* faces = new int[12];),
there is no any use of any array construct in the program. (hint: Use Pointers!)
o Forexample,allofthefollowingarrayconstructsinthecodetorefertotheelementsin
the corresponding dynamic arrays are forbidden to be used. sum[i+j-1]
sum[k]
sum[index]
sorted[index][0] sorted[index][1] sorted[k][0]
sorted[k – 1][0] sorted[k][1]
sorted[k – 1][1]
sorted[i][0]
sorted[i-1][0]
faces[sorted[0][1] – 1] faces[sorted[i][1] – 1] faces[k]
• Every dynamic array must be deleted before the program terminates.
o Hint:whendeletingthe1Darrayfaces,usedelete:delete[]faces;
o Hint:whendeletinga2Darray,youneedtodeletealltherowsofthe2Darrayfirst,and
then the 2D array.
8
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
#include
using namespace std;
int main() {
char faces[12] = { 0 };
int sum[12] = { 0 }; // max 12 values of occurrence counts int sorted[12][2]; // a 2D array
// sorted[i][0] = sum of face values kept in sum[index] // sorted[i][1] = index of sum[index]
for(inti=1;i<=6;i++) //iisdice1
for (int j = 1; j <= 6; j++) // j is dice 2
sum[i + j - 1] = sum[i + j - 1] + 1;
for (int k = 0; k < 12; k++)
if (sum[k] != 0)
cout << sum[k]
<< " occurrence(s) of the sum "
<< k + 1 << endl;
// we firstly copy sum to rank
for (int index = 0; index < 12; index++)
{
sorted[index][0] = sum[index];
sorted[index][1] = index + 1;
}
// then we sort the array sorted[] using bubble sort
// check out the lecture note slide 31 of Lec07
// we want sorted[0] as the LARGEST after the sorting process int tmp;
for(intj=0;j<12-1;j++) //outerloop
for (int k = 12 - 1; k > j; k–) // bubbling
if (sorted[k][0] > sorted[k – 1][0]) { // check against col 0
// note that the condition is “>” rather than “<". tmp = sorted[k][0]; // swap neighbors for col 0 sorted[k][0] = sorted[k - 1][0];
sorted[k - 1][0] = tmp;
tmp = sorted[k][1]; // swap neighbors for col 1
sorted[k][1] = sorted[k - 1][1]; } sorted[k - 1][1] = tmp;
for (int i = 0; i < 12; i++)
if (sorted[i][0] != 0)
cout << sorted[i][0] << ' ' << sorted[i][1] << endl;
char c = 'A'; // the 1st character to be shown faces[sorted[0][1] - 1] = c;
for (int i = 1; i < 12; i++) {
if (sorted[i][0] != sorted[i - 1][0]) c++;
if (sorted[i][0] != 0)
faces[sorted[i][1] - 1] = c;
}
// print out the letter rank
for (int k = 0; k < 12; k++)
if (faces[k] != 0)
return 0; }
cout << faces[k] << " occurrence(s) of the sum " << k + 1 << endl;
9
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021 Example:
1 occurrence(s) of the sum 2 2 occurrence(s) of the sum 3 3 occurrence(s) of the sum 4 4 occurrence(s) of the sum 5 5 occurrence(s) of the sum 6 6 occurrence(s) of the sum 7 5 occurrence(s) of the sum 8 4 occurrence(s) of the sum 9 3 occurrence(s) of the sum 10 2 occurrence(s) of the sum 11 1 occurrence(s) of the sum 12 67
56
58
45
49
34
3 10
23
2 11
12
1 12
F occurrence(s) of the sum 2 E occurrence(s) of the sum 3 D occurrence(s) of the sum 4 C occurrence(s) of the sum 5 B occurrence(s) of the sum 6 A occurrence(s) of the sum 7 B occurrence(s) of the sum 8 C occurrence(s) of the sum 9 D occurrence(s) of the sum 10 E occurrence(s) of the sum 11 F occurrence(s) of the sum 12
10
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Q4. Recursion
In tutorial T04, Exercise 4 asks students to develop a program using four nested loops. The tutorial exercise is reproduced below.
Exercise 4: 1729 is Interesting
Examples of Console for Ex4
There was an Indian mathematician who was famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him in
the hospital one day, Hardy mentioned that the number of his taxi was1729,
a rather dull number. To which the Indian mathematician replied, "No! It is a very interesting number. 1729 is the smallest positive integer expressible as the sum of two cubes in two different ways".
Verify this claim by writing a program twoCubric.cpp that takes an integer N and prints out all positive integers less than or equal to N that can be expressed as the sum of two cubes in two different ways: i.e., find distinct positive integers a, b, c, anddsuchthat N=a3 +b3 =c3 +d3.
hint: Use four nested for loops, one for each of a, b, c, d.
Let’s assume that N is not a very large number.
Read the next slide 20
Input: 1728
Input: 1729
1729 = 1^3 + 12^3 = 9^3 + 10^3
Input: 100000
1729 = 1^3 + 12^3 = 9^3 + 10^3 4104 = 2^3 + 16^3 = 9^3 + 15^3
1729=13 +123 =93 +103
4104=23 +163 =93 +153
Check whether or not our solution contains duplicated entries.
21
13832 = 2^3 +
39312 = 2^3 +
46683 = 3^3 +
32832 = 4^3 +
40033 = 9^3 +
20683 = 10^3 + 27^3 = 19^3 + 24^3 65728 = 12^3 + 40^3 = 31^3 + 33^3 64232 = 17^3 + 39^3 = 26^3 + 36^3
24^3 = 18^3 + 20^3 34^3 = 15^3 + 33^3 36^3 = 27^3 + 30^3 32^3 = 18^3 + 30^3 34^3 = 16^3 + 33^3
Input: 10000
1729 = 1^3 + 12^3 = 9^3 + 10^3 4104 = 2^3 + 16^3 = 9^3 + 15^3
Write a program without using any loop (i.e., without any while-loop, for-loop, or do-while loop) to solve the same program. I.e., the program should accept a positive integer number N and outputs a sequence of lines in the format of p = a^3 + b^3 = c^3 + d^3 where p, a, b, c, d are all distinct positive integers such thatp<=Nandp =a3 +b3 =c3 +d3 andnotwolinescontainsthesamesetof{a,b,c,d}(inthesenseof values).
Your program only needs to handle 0 ≤ N ≤ 1000000.
Your program should be efficient. For instance, when a user inputs a large number, your program should output the correct list and terminates within a reasonable time (e.g., 1 minute). FYI, a correct program can produce the output within a few seconds.
Important Hints:
• The solution of this question does not require to use any arrays.
• Students are advised to work on Exercise 4 in Tutorial 4, particularly following the slides 22-27
to resolve the subproblems stated on the slides. Or else your program will easily incur bugs.
• Your program will be at least four recursions, one on each of the four variables “a”, “b”, “c”, and “d” to enumerate their combinations. The recursion on “d” is nested in the recursion on “c”,
which in turn is nested in the recursion on “b”, and which is also in turn nested on “a”.
• Students are advised to study the patterns in the reference solution of Exercise 4 in Tutorial 4. In
that reference solution, when looping on variable “b”, it needs the information of the current value of the variable “a” within the loop body of this loop. Similarly, when looping on variable “c”, it needs the information of the current value of variable “a”, and when looping on variable “d”, it needs the information of the current values of variables “a”, “b”, and “c”.
11
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Q5. Ash and Pikachu [20% + 10% Bonus]
In the Pokemon series of manga, Ash is the main character who joins force with Pikachu, a Pokémon, for various adventure. We now have the Pokemon Go. In this question, we are going to implement some of the concepts involved through C++ classes.
In this question, your program should allow a user to input: (1) a Pokemon world, (2) a list of Pokemons and (3) [For Bonus] the information about a trainer called Ash.
Ensure that the output follows the format presented in Examples given at the end of this question.
Important note: Your program can assume the following: (1) the number of Pokemons is at least 1 and at most 1000, (2) the name of any object is a cstring consisting of at most 10 characters (including ‘\0’), and (3) all user inputs are valid.
• The concept of PokemonWorld is implemented as a C++ class.
o Each PokemonWorld object owns two PokemonStation objects. We simply refer to each
PokemonStation object of this class as a station.
o EachPokemonWorldobjectisresponsibletoinitializethetwo(2)stations.
(Note: The use of an array to keep two stations will make your program significantly more complex than keeping them as two separate variables. The reason is due to our limited known-how introduced in CS2311 to use object pointers rather than the limitation of C++.)
o When a Pokemon enters a PokemonWorld, the PokemonWorld is responsible to assign this Pokemon to one of the two stations on its own. The assignment of each Pokemon will be done to the PokemonStation in a round-robin manner (i.e., the first Pokemon is assigned to PokmonStation1, the second Pokemon is assigned to PokmonStation2, the third Pokemon is assigned to PokmonStation1 again, the fourth Pokemon is assigned to PokmonStation2 and so on).
o The‘name’variableofthePokemonWorldobjectcanbeaccessedbytheobjectitself.
o Hint: study http://stackoverflow.com/questions/12927169/how-can-i-initialize-c-object-
member-variables-in-the-constructor
• The concept of PokemonStation is also implemented as a C++ class.
o Each object of this class represents a station which has a station identifier. We simply refer to
each object of this class as a station. The station identifiers are s1 and s2, respectively.
o The identifier of each station is provided by the PokemonWorld object that owns the station through the class constructor of PokemonStation. (Hint: You may wish to initialize each
PokemonStation when the constructor of PokemonWorld object is being called.)
o EachstationmaintainsitsownlistofPokemonsassignedbythePokemonWorldobject.
o Both the identifier of a PokemonStation and the list of Pokemons (i.e., each Pokemon that
belongs to a particular PokemonStation) should not be accessible by any other object nor be
returned via a function.
o OnlyPokemonWorldandthePokemonStationitselfcaninvokethefunctionsofthatstation.
• The concept of Pokemon is also implemented as a C++ class. 12
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
o EachPokemonisanobjectofthisclass.
o EachPokemonobjecthasitsownname(acstring)andhpvalue(aninteger).
o Alldatamembers(name,hp)ofeachPokemonobjectonceinitializedcanonlybeaccessedby
that Pokemon object.
• The main() function is responsible for the following:
o Toacceptalltheinputsfromtheuser.
o TocreateaPokemonWorldandallthePokemons.
o ToseteachPokemontoenterthePokemonWorld.
o To call the method print() of Pokemon, which in turn calls the method print() of each
PokemonStation, which in turn calls the method print() of each Pokemon to print out the information of the PokemonWorld, the PokemonStation, and the Pokemon, respectively.
Bonus Part [Extra 10%]
• The requirements stated above should remain intact.
• A Trainer needs to be implemented as a C++ class.
o Each trainer (e.g. Ash) is an object of this class.
o Each trainer has his/her own name (cstring), identifier (integer), and strength (integer). All this
information is taken from the user as input from console.
o All data members of each trainer object cannot be accessed outside the trainer object. That is, the value of each data member should not be returned via a function nor be retrieved via call- by-reference.
• The main() function is responsible to create a trainer called Ash and let Ash enter the PokemonWorld.
• PokemonWorld is responsible to guide Ash to visit its two stations one by one once Ash enters this
world.
• Each station is responsible to determine whether a trainer can capture each Pokemon kept by the
station. Specifically, if the hp of the Pokemon is strictly less than (<) the strength of the trainer, then the Pokemon is marked as captured by the trainer.
o Note that following the above requirements, both the hp of the Pokemon and the strength of
the trainer should not be returned via any function.
• The print() method of each captured Pokemon calls the print() method of the trainer object that
captures it to print the information of Ash.
More description about the above three classes
Ideas on the data members of the
Pokeworld class.
[The class may contain other data members]
Ideas on the data members of the
PokeStation class.
[The class may contain other data members]
Ideas on the data members of the
Pokemon class.
[The class may contain other data members
Name
The name of this Pokeworld object
ID
The identifier of this station, such as 1 and 2.
Name
The name of this Pokemon object
s1
1st station owned by the Pokeworld
list
An array of Pokemon
hp
The HP of the Pokemon object
s2
2nd station owned by the Pokeworld
13
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Example 1: (without Bonus)
What is the World Name?
Please input the number of Pokemon in the Macau world
7
Macau
Please input the characteristics of all Pokemon: Name HP
Pikachu 50
Regice 100
Articuno 100
Charizard 150
Blastoise 240
Mew 340
Gengar 101
World is Macau
Pokemon in Station #1:
Pikachu HP 50
Articuno HP 100
Blastoise HP 240
Gengar HP 101
Pokemon in Station #2:
Regice HP 100
Charizard HP 150
Mew HP 340
Example 2: (without Bonus)
What is the World Name?
Hongkong
Please input the number of Pokemon in the Hongkong world
1
Please input the characteristics of all Pokemon: Name HP
World is Hongkong
Pokemon in Station #1:
Pikachu HP 50
No Pokemon in Station #2
Pikachu 50
14
CityU CS2311 2020/21 Sem B Assignment 2 due on 30 April 2021
Example 3: (with Bonus)
What is the World Name?
Please input the number of Pokemon in the Macau world
7
Macau
Please input the characteristics of all Pokemon: Name HP
Pikachu 50
Regice 100
Articuno 100
Charizard 150
Blastoise 240
Mew 340
Gengar 101
Enter Trainer information: ID NAME HP
1 Ash 101
World is Macau
Pokemon in Station #1:
Pikachu HP 50
Articuno HP 100
Blastoise HP 240
Gengar HP 101
Pokemon in Station #2:
Regice HP 100
Charizard HP 150
Mew HP 340
Ash is its master
Ash is its master
Ash is its master
*** END OF ASSIGNMENT TWO ***
15