辅导RBE104TC程序、C/C++编程设计调试、Programming语言辅导 解析C/C++编程|辅导Web开发
- 首页 >> Python编程 RBE104TC C/C++ Programming Language
Assignment 2
Assignment Overview:
This assignment aims at testing some basic concepts of the C++ programming and
initiates the routine of code development using the software development process
(SDP) presented in the relevant lectures. It focuses on the following five steps of
the SDP.
1. Problem statement: formulate the problem;
2. Analysis: determine the inputs, outputs, variables, etc.;
3. Design: define the list of steps (the algorithm) needed to solve the
problem;
4. Implementation: the C code has to be submitted as a separate file, just
indicate here the name of the file;
5. Testing: explain how you have tested and verified your C program.
You will need to apply this methodology to each one of the following simple
exercises.
Things to note:
1. Include clear comments in your code to make it easy to understand.
2. Explain your testing procedure and what you have observed during the
testing. The testing should be demonstrated by screenshot pictures to
present the actual implementation output.
3. How you solved any problems.
Contribution to the Overall Marks 60%
Issue Date
Submission Deadline Dec. 23rd, 2020
1 / 5
Exercise 1:
Design a new class to represent a fraction (a
nation of two integer values).
The data members of the class Fraction are two
integers, top and down, denoting the numerator
and denominator, respectively.
class Fraction
{
private:
int top; // Numerator
int bottom; // Denominator
public:
. . . . . .
};
Part 1: Fundamental requirements for the class Fraction.
1. Fractional numbers can be declared with both a numerator and denominator,
or simple numerator:
Fraction a; // represents 0/1
Fraction b(3,4); // represents 3/4
Fraction c(5); // represents 5/1
2. Fractions should be able to act just like other numbers.
Add, subtract, multiple and divide;
Compare based on values;
Input and output.
Part 2: Advanced requirements
3. Fractional number is normalized to ensure that only the numerator can be
negative and the value is in the least common denominator form:
• 2/-3 would be converted into -2/3 automatically;
• 15/21 would be converted into 5/7 automatically.
4. Write methods to convert between decimals and fractions.
Exercise 2:
Derive a sub-class iFraction from the base class Fraction, which was designed by
you in Exercise 2 of Assessment 2. The iFraction class represents the mixed
fractions like ;
Part 1: Design the sub-class iFraction:
• It should have a constructor for initialisation;
• It should contain a method to display the mixed fraction on screen;
Part 2: Design an external function convertF (not function member of class Fraction
and iFraction) to convert the improper fractions to mixed fractions.
Hint: convertF can be the friend function of those two classes.
Exercise 3:
Design a composite class that represents complex numbers whose real and
imaginary parts are Fractions.
• Write appropriate constructors for this class;
• Complex numbers should be able to add, subtract and multiple.
3 / 5
Exercise 4:
This is a computer game with different types of players. Take the code provided for
the container class (container.h), player class (player.h), and the swordsman class
(swordsman.h), and the main function (main.cpp).
Part 1:
1. Read the source codes, understand the meaning and fill the blank (shown
as) to make it work;
2. Generate the CRC cards of the classes: clarify the responsibilities of each
class, illustrate the collaboration with others, and label all the members’ as
public, protected, and private. Then draw the hierarchy chart of them;
Part 2:
3. Design another two classes, archer and mage. Generate their CRC card
and put them in the hierarchy chart drew above. Write the code for these two
classes and make them work (cooperate with the main function);
4. Modify the main function, to have enemies with all three professions (could
be randomly chosen).
Part 3 (Optional):
Can you involve another attribute – luck, in this game?
Notes: The factors are imperfect, make the fight too hard or too easy. Change
whatever you want, but leave hints for reviewers to know what you have done.
4 / 5
What should be submitted?
You should submit the followings:
1). A short report (up to a few pages of text plus C source codes) detailing for each
question:
a). SDP steps 1 to 3 in the report (Report + Specification + Analysis +
Algorithm Design) (40%);
b). SDP step 4 (Implementation + Robustness): your C source code including
the comments. (40%);
c). SDP step 5 (testing): you will explain how you have tested the correctness
of your C program and will include some sample runs of your C Programs.
(20%);
Please refer to the file Marking Guidelines for RBE104TC.pdf on the Learning Mall
system for a detailed marking scheme.
2). The report in Microsoft Word or pdf format and C source code of your
implementation zipped into a single file, i.e. the zip file will contain 2 files. (It is good
practice to include comments in your code see the example provided.)
The naming of Report (.doc, .docx or .pdf only), Source Code (.c) and Compressed
file (.zip, or .rar only)
StudentID_LastName_FirstName_AssignmentNumber.doc
StudentID_ AssignmentNumber.c
StudentID_LastName_FirstName_AssignmentNumber.zip
For example:
Report and c source file named:
1234567_Albert_Einstein_1.doc
1234567_1.c
Contained within the zip file:
1234567_Albert_Einstein_1.zip
How the work should be submitted?
Should be submitted electronically through the Learning Mall system so that the
marker can run your programs during marking. Feedback and your grade will also
be given through the Learning Mall system.
5 / 5
Assignment 2
Assignment Overview:
This assignment aims at testing some basic concepts of the C++ programming and
initiates the routine of code development using the software development process
(SDP) presented in the relevant lectures. It focuses on the following five steps of
the SDP.
1. Problem statement: formulate the problem;
2. Analysis: determine the inputs, outputs, variables, etc.;
3. Design: define the list of steps (the algorithm) needed to solve the
problem;
4. Implementation: the C code has to be submitted as a separate file, just
indicate here the name of the file;
5. Testing: explain how you have tested and verified your C program.
You will need to apply this methodology to each one of the following simple
exercises.
Things to note:
1. Include clear comments in your code to make it easy to understand.
2. Explain your testing procedure and what you have observed during the
testing. The testing should be demonstrated by screenshot pictures to
present the actual implementation output.
3. How you solved any problems.
Contribution to the Overall Marks 60%
Issue Date
Submission Deadline Dec. 23rd, 2020
1 / 5
Exercise 1:
Design a new class to represent a fraction (a
nation of two integer values).
The data members of the class Fraction are two
integers, top and down, denoting the numerator
and denominator, respectively.
class Fraction
{
private:
int top; // Numerator
int bottom; // Denominator
public:
. . . . . .
};
Part 1: Fundamental requirements for the class Fraction.
1. Fractional numbers can be declared with both a numerator and denominator,
or simple numerator:
Fraction a; // represents 0/1
Fraction b(3,4); // represents 3/4
Fraction c(5); // represents 5/1
2. Fractions should be able to act just like other numbers.
Add, subtract, multiple and divide;
Compare based on values;
Input and output.
Part 2: Advanced requirements
3. Fractional number is normalized to ensure that only the numerator can be
negative and the value is in the least common denominator form:
• 2/-3 would be converted into -2/3 automatically;
• 15/21 would be converted into 5/7 automatically.
4. Write methods to convert between decimals and fractions.
Exercise 2:
Derive a sub-class iFraction from the base class Fraction, which was designed by
you in Exercise 2 of Assessment 2. The iFraction class represents the mixed
fractions like ;
Part 1: Design the sub-class iFraction:
• It should have a constructor for initialisation;
• It should contain a method to display the mixed fraction on screen;
Part 2: Design an external function convertF (not function member of class Fraction
and iFraction) to convert the improper fractions to mixed fractions.
Hint: convertF can be the friend function of those two classes.
Exercise 3:
Design a composite class that represents complex numbers whose real and
imaginary parts are Fractions.
• Write appropriate constructors for this class;
• Complex numbers should be able to add, subtract and multiple.
3 / 5
Exercise 4:
This is a computer game with different types of players. Take the code provided for
the container class (container.h), player class (player.h), and the swordsman class
(swordsman.h), and the main function (main.cpp).
Part 1:
1. Read the source codes, understand the meaning and fill the blank (shown
as) to make it work;
2. Generate the CRC cards of the classes: clarify the responsibilities of each
class, illustrate the collaboration with others, and label all the members’ as
public, protected, and private. Then draw the hierarchy chart of them;
Part 2:
3. Design another two classes, archer and mage. Generate their CRC card
and put them in the hierarchy chart drew above. Write the code for these two
classes and make them work (cooperate with the main function);
4. Modify the main function, to have enemies with all three professions (could
be randomly chosen).
Part 3 (Optional):
Can you involve another attribute – luck, in this game?
Notes: The factors are imperfect, make the fight too hard or too easy. Change
whatever you want, but leave hints for reviewers to know what you have done.
4 / 5
What should be submitted?
You should submit the followings:
1). A short report (up to a few pages of text plus C source codes) detailing for each
question:
a). SDP steps 1 to 3 in the report (Report + Specification + Analysis +
Algorithm Design) (40%);
b). SDP step 4 (Implementation + Robustness): your C source code including
the comments. (40%);
c). SDP step 5 (testing): you will explain how you have tested the correctness
of your C program and will include some sample runs of your C Programs.
(20%);
Please refer to the file Marking Guidelines for RBE104TC.pdf on the Learning Mall
system for a detailed marking scheme.
2). The report in Microsoft Word or pdf format and C source code of your
implementation zipped into a single file, i.e. the zip file will contain 2 files. (It is good
practice to include comments in your code see the example provided.)
The naming of Report (.doc, .docx or .pdf only), Source Code (.c) and Compressed
file (.zip, or .rar only)
StudentID_LastName_FirstName_AssignmentNumber.doc
StudentID_ AssignmentNumber.c
StudentID_LastName_FirstName_AssignmentNumber.zip
For example:
Report and c source file named:
1234567_Albert_Einstein_1.doc
1234567_1.c
Contained within the zip file:
1234567_Albert_Einstein_1.zip
How the work should be submitted?
Should be submitted electronically through the Learning Mall system so that the
marker can run your programs during marking. Feedback and your grade will also
be given through the Learning Mall system.
5 / 5