程序代写案例-ENGG1340 /-Assignment 1

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
ENGG1340 / COMP2113, Assignment 1
Due Date: Mar 21, 2020 23:59
If you have any questions, please post to the Moodle discussion forum on Assignment 1. r>General Instructions
Problem 1: Interleaving Characters (10 marks)
Problem 2: A Divisor Matrix (10 marks)
Problem 3: Cosine Function Approximation (15 marks)
Problem 4: Caesar Shifting (15 marks)
Problem 5: Bounding Boxes (20 marks)
Problem 6: A 5-Card Hand (25 marks)
IMPORTANT NOTE: In this assignment, you can ONLY use the simple data types  char ,  bool ,
 int ,  double  and  string . In other words, you are not allowed the use other data types or
data structures such as arrays, vectors, etc.
Total marks: 100 marks
5 marks for proper code comments and indentation
95 marks for program correctness
A maximum of 5 marks will be deducted if you fail to follow the submission instructions strictly.
General Instructions
Read the instructions in this document carefully.
In this assignment you will solve 6 tasks and a tester would automatically test your submitted
program. So if your submitted files and program outputs do not conform to our instructions given
here, your programs cannot be evaluated and you will risk losing marks totally.
Sample test cases are provided with each task in this document. Note that the test cases may or
may not cover all boundary cases for the problem. It is also part of the assessment whether you are
able to design proper test cases to verify the correctness of your program. We will also use
additional test cases when marking your assignment submission.
Input and output format
Your C++ programs should read from the standard input. Also, your answer should be printed
through the standard output. If you failed to follow this guide, the tester may not able to give a
score for your program. Additionally, you should strictly follow the sample output format (including
space, line breaker, etc.), otherwise, your answer might be considered as wrong.
How to use the sample test cases
Sample test cases in text file formats are made available for you to check against your work. Here's
how you may use the sample test cases. Take Problem 2 test case 3 as an example. The sample
input and the expected output are given in the files  input2_3.txt  and  output2_3.txt ,
respectively. Suppose that your program is named "2", do the followings at the command prompt of
the terminal to check if there is any difference between your output and the expected output.
./2 < input2_3.txt > myoutput.txt
diff myoutput.txt output2_3.txt
Testing against the sample test cases is important to avoid making formatting mistakes. The
additional test cases for grading your work will be of the same formats as the sample test cases.
Coding environment
You must make sure that your program can compile, execute and generate the required outputs on
our standard environment, namely, the gcc C++11 environment we have on the CS Linux servers
(academy*). Make sure the following compilation command is used to compile your programs:
g++ -pedantic-errors -std=c++11 [yourprogram].cpp
As a programmer/developer, you should always ensure that your code can work perfectly as
expected on a target (e.g., your client's) environment, not only on yours.
While you may develop your work on your own environment, you should always try your program
(compile & execute & check results) on our standard environment before submission.
Submission
Name your C++ programs as the following table shows and put them together into one directory.
Make sure that the folder contains only these source files ( *.cpp ) and no other files. Compress this
directory as a  [uid].zip  file where [uid] is your university number and check carefully that the
correct file have been submitted. We suggest you to download your submitted file from Moodle,
extract them, and check for correctness. You will risk receiving 0 marks for this assignment if
you submit incorrect files. Resubmission after the deadline is not allowed.
Filename Description
 1.cpp  Problem 1
 2.cpp  Problem 2
 3.cpp  Problem 3
 4.cpp  Problem 4
 5.cpp  Problem 5
 6.cpp  Problem 6
Late submission
If submit within 3 days after the deadline, 50% deduction. After that, no mark.
Evaluation
Your code will be auto-graded for technical correctness. In principle, we use test cases to
benchmark your solution, and you may get zero marks for not being able to pass any of the test
cases. Normally partial credits will not be given for incomplete solution, as in many cases the logic of
the programs are not complete and an objective assessment could be difficult. However, your work
may still be considered on a case-by-case basis during the rebuttal stage.
Academic dishonesty
We will be checking your code against other submissions in the class and from the Internet for
logical redundancy. Please be reminded that no matter whether it is providing your work to others,
assisting others to copy, or copying others will all be considered as committing plagiarism and we
will follow the departmental policy to handle such cases. Please refer to the course information
notes for details.
Getting help
You are not alone! If you find yourself stuck on something, post your question to the course forum.
We want this assignment to be rewarding and instructional, not frustrating and demoralizing. But we
don’t know when or how to help unless you ask.
Discussion forum
Please be careful not to post spoilers. Please don’t post any code that is directly related to the
assignments. However you are welcome and encouraged to discuss general ideas on the discussion
forums. If you have any questions about this assignment you should post them in the discussion
forums.
Problem 1: Interleaving Characters
Write a C++ program that will read two integers  m  and  n  supplied by the user. Output the
character  y  m times followed by  z  n times. You may assume that the user only enters values in
 {0, 1, 2, ..., 10} . Interleave the output starting with  y .
Sample Test Cases
User inputs are shown in blue.
1_1
3
3
yzyzyz
1_2
3
4
yzyzyzz
1_3
5
3
yzyzyzyy
1_4
0
7
zzzzzzz
Problem 2: A Divisor Matrix
Write a C++ program that will prompt the user for two positive integers  a , b . You may assume that
the user will always input positive integers such that the following holds,  0 <= a < b < 1000 . The
user will then be prompted for two divisors. You may assume that divisors entered by the user are
valid, for which the following holds,  1 <= divisor < 1000 .
The program will then output a matrix with the following elements.
The first row will start with an  M  followed by the two divisors in input order.
The first column, beneath the  M , will contain the integers between  a  and  b  (including  a  and
excluding  b ), in increasing order.
For the remaining two elements of each row, there will be a  1  if the integer in that row is
divisible by the divisor at the head of that column, otherwise  0 .
Matrix elements should be separated by a space. Note that there is no trailing space after the
last element of a row.
Sample Test Cases
User inputs are shown in blue.
2_1:
a: 1
b: 10
Divisor 1: 2
Divisor 2: 3
M 2 3
1 0 0
2 1 0
3 0 1
4 1 0
5 0 0
6 1 1
7 0 0
8 1 0
9 0 1
2_2:
a: 134
b: 141
Divisor 1: 4
Divisor 2: 5
M 4 5
134 0 0
135 0 1
136 1 0
137 0 0
138 0 0
139 0 0
140 1 1
2_3:
a: 2
b: 21
Divisor 1: 2
Divisor 2: 5
M 2 5
2 1 0
3 0 0
4 1 0
5 0 1
6 1 0
7 0 0
8 1 0
9 0 0
10 1 1
11 0 0
12 1 0
13 0 0
14 1 0
15 0 1
16 1 0
17 0 0
18 1 0
19 0 0
20 1 1
Problem 3: Cosine Function
Approximation
Write a C++ program which takes two user input integers ( ) and ( ),
and calculate an estimation of using Taylor series approximation with the formula:
where denote the factorial of , and is defined as . You may assume
that ranges from 0 to 100 inclusively in this question.
Your program should output the estimations of as increases. Specifically, your program
should
On the first line, print the result of as returned by the predefined function  cos()  in
   as a fixed floating number with 15 decimal places.
Output the values of and on the subsequent lines as increases. The values and
on each line are separated by a space. The value is printed as a fixed floating
number with 15 decimal places.
Use the  double  data type for floating point calculations.
Note:
Check carefully your results against the same test outputs. Divisions involving some large
numbers can easily run into numerical inaccuracy issues (you will learn more about this in the
machine organization course). It means that you should do divisions before multiplications (if
possible) to keep the intermediate values small. Try to implement the given formula in different
ways to test out.
You may use  setprecision(n)  defined in the header    to set the precision
parameter of the output stream.
Sample Test Cases
User inputs are shown in blue.
3-1
0 0
cos(x) by cmath: 1.000000000000000
Taylor series approximation:
0 1.000000000000000
3_2
x 0 ≤ x ≤ 20 n 0 ≤ n ≤ 100
cosx
cosx = x ,
i=0

n
(2i)!
(−1)i 2i
i! = 1 × 2 × 3 × ⋯ × i i 00 1
n
cosx n
cosx
n cosx n n
cosx cosx
1 10
cos(x) by cmath: 0.540302305868140
Taylor series approximation:
0 1.000000000000000
1 0.500000000000000
2 0.541666666666667
3 0.540277777777778
4 0.540302579365079
5 0.540302303791887
6 0.540302305879563
7 0.540302305868092
8 0.540302305868140
9 0.540302305868140
10 0.540302305868140
3_3
3 20
cos(x) by cmath: -0.989992496600445
Taylor series approximation:
0 1.000000000000000
1 -3.500000000000000
2 -0.125000000000000
3 -1.137500000000000
4 -0.974776785714286
5 -0.991049107142857
6 -0.989939630681818
7 -0.989994494902419
8 -0.989992437494146
9 -0.989992498006155
10 -0.989992496572975
11 -0.989992496600895
12 -0.989992496600439
13 -0.989992496600446
14 -0.989992496600446
15 -0.989992496600446
16 -0.989992496600446
17 -0.989992496600446
18 -0.989992496600446
19 -0.989992496600446
20 -0.989992496600446
Problem 4: Caesar Shifting
Write a C++ program which encrypts and decrypts some input characters. Specifically, your program
should read in a line of input , wheres k c1 c2 c3 …
is either the character  e  for encryption, or the character  d  for decryption
is an integer for the number of shifts used in the Caesar shift algorithm
is a sequence of space separated characters, ended by  ! , to be encrypted or
decrypted
To encrypt (decrypt) a letter (within the alphabet A-Z or a-z) with a shift of positions:
1. Let be 's position in the alphabet (0 based), e.g., position of  B  is 1 and position of  g  is 6.
2. For encryption, calculate modulo 26;
for decryption, calculate modulo 26.
3. Let be the letter corresponding to position in the alphabet. If is in uppercase, the
encrypted (decrypted) letter is in lowercase; otherwise, the encrypted (decrypted) letter is
in uppercase.
A character which is not within the alphabet A-Z or a-z will remain unchanged under
encryption or decryption.
Example. Given letter  B  and = 3, we have = 1, = 1 + 3 mod 26 = 4, and =  E . As  B  is in
uppercase, the encrypted letter is  e .
Sample Test Cases
User inputs are shown in blue.
4_1
e 1 !
!
4_2
e 3 a B c D e !
DeFgH!
4_3
d 3 D e F g H !
aBcDe!
4_4
e -1 H e l l o E N G G 1 3 4 0 / C O M P 2 1 1 3 !
gDKKNdmff1340/bnlo2113!
s
k
c1 c2 c3…
c k
x c
y = x+ k
y = x− k
w y c
w w
k x y w
4_5
d 10 n 3 V 3 D 3 N _ M Y N 3 _ S C _ N 3 L E Q Q 3 N _ M Y N 3 !
D3l3t3d_cod3_is_d3bugg3d_cod3!
Problem 5: Bounding Boxes
Write a C++ program to compute a minimum-sized axis-aligned bounding box (AABB) for a set of
input 2D geometries. An AABB is a rectangle with sides parallel to the x-, y-axes which encloses
some given geometries. The input and output of your program are as follows:
Input. Each line of the user input begins with a character indicating the type of geometry, followed
by some parameters of the geometric object. The input line can be one of the followings:
 R 
where  R  represents an input rectangle, , are floating-point numbers for the x-, y-
coordinates of the rectangle center, and are floating-point numbers for the
rectangle size along the x- and y-axes, respectively.
 C 
where  C  represents an input circle, , are floating-point numbers for the x-, y-coordinates of
the circle center, and is a floating-point number for the radius of the center
 P 
where  P  represents an input point set, is an integer indicating the number of points in the
set, and , , are floating point numbers for the x-, y-coordinates of the points
 # 
indicates end of input
Output. A single line
    
where and are floating-point numbers for the x-, y-coordinates of the center of the minimum-
sized AABB, and are floating-point numbers giving the sizes of the AABB along the x-,
y-axes, respectively.
Use the  double  data type for floating point calculations.
Note: The questions assume no bound for the floating-point parameters ( , , , ,
) of the input geometries and therefore they can be any values that a double data type
can hold. You may use  std::numeric_limits::lowest()  and
 std::numeric_limits::max()  defined in the header    in your program to obtain
the smallest and the largest possible values, respectively, for the double data type.
x y width height
x y
width height
x y radius
x y
radius
n x1 y1 x2 y2 … xn yn
n
xi yi i = 1,… ,n n
x y width height
x y
width height
x y width height
radius
Sample Test Cases
User inputs are shown in blue.
5_1
R 0 0 3 2
#
0 0 3 2
5_2
C -0.5 3.2 1.6
#
-0.5 3.2 3.2 3.2
5_3
P 2 3 -2 -1 4
#
1 1 4 6
5_4
P 3 -1.5 3 3 3 5 3
#
1.75 3 6.5 0
5_5
P 2 3 -2 -1 4
C -0.5 3.2 1.6
P 3 -1.5 3 3 3 5 3
R 0 5.75 3 2
#
1.45 2.375 7.1 8.75
Problem 6: A 5-Card Hand
Write a C++ program to generate a random hand of FIVE poker cards from a deck of 52 poker cards,
and determine the type of poker hand it is. The input and output of your program as are follows:
Input. An integer that you would use as input parameter to  srand()  for initializing the random
number generator (RNG).
Output.
the first line displays the five cards in the hand.
the second line tells the type of the 5-card hand, in the following categories:
four of a kind (e.g., A♠ A♥ A♣ A♦ 2♣)
full house (e.g., 8♠ 8♥ 8♦ 4♥ 4♣)
flush (e.g., K♠ 10♠ Q♠ 5♠ 3♠ )
three of a kind (e.g., 10♥ 10♦ 10♣ 5♥ J♠ )
two pair (e.g., 9♦ 9♣ 2♥ 2♣ 3♥)
one pair (e.g., 7♠ 7♦ A♠ Q♠ 6♠)
others
(Check the wiki page "list of poker hands" for the detailed definition of each type.)
Note:
In your program, each card of the deck should be represented by an integer from 0 to 51 in the
following ways:
A♠, 2♠, 3♠, ..., 10♠, J♠, Q♠, K♠ are represented by 0, 1, 2, ..., 12, respectively
A♥, 2♥, 3♥, ..., 10♥, J♥, Q♥, K♥ are represented by 13, 14, 15, ..., 25, respectively
A♣, 2♣, 3♣, ..., 10♣, J♣, Q♣, K♣ are represented by 26, 27, 28, ..., 38, respectively
A♦, 2♦, 3♦, ..., 10♦, J♦, Q♦, K♦ are represented by 39, 40, 41, ..., 51, respectively
You will use the  rand()  function in    to generate random numbers. However, the
RNG ONLY guarantees to generate the same sequence of random numbers given the same
seed on the same OS & platform only. The sample test data are generated on the academy*
servers, so you have to run the program there in order to generate the same results.
You may assume that the first 5 random numbers generated by  rand()  are all different.
You program must contain the following 8 functions:
void DealHand(int &c1, int &c2, int &c3, int &c4, int &c5)
The function  DealHand() should generate five random numbers, each representing a card in
a 52-card deck, using the user-input seed . The first five numbers generated by the RNG
should be stored in the pass-by-reference variables  c1 ,  c2 ,  c3 ,  c4 ,  c5  in order.
void PrintHand(int c1, int c2, int c3, int c4, int c5)
The function  PrintHand()  should print a hand represented by  c1 ,  c2 ,  c3 ,  c4 ,  c5 . For
example, if  c1 == 0 ,  c2 == 25 ,  c3 == 14 ,  c4 == 50 ,  c5 == 36 , the line  A♠ K♥ 2♥ Q♦ J♣  
should be output to the screen.
x
x
You may refer to the following program on how to display the suit symbols in UTF-8 encoding
(on Linux/MacOS):
#include

// include the following 4 lines in your program
// these define the UTF-8 encoding of the suit symbols
#define SPADE "\xE2\x99\xA0"
#define CLUB "\xE2\x99\xA3"
#define HEART "\xE2\x99\xA5"
#define DIAMOND "\xE2\x99\xA6"

using namespace std;

int main()
{
cout << SPADE << CLUB << HEART << DIAMOND << endl;
return 0;
}
The other 6 functions that you must have in your program are:
IsFourOfAKind() // return if the hand is a four of a kind
IsFullHouse() // return if the hand is a full house
IsFlush() // return if the hand is a flush
IsThreeOfAKind() // return if the hand is a three of a kind
IsTwoPair() // return if the hand is a two pair
IsOnePair() // return if the hand is a one pair
These 6 functions should take 5 cards as input and return whether the hand represented by the 5
cards is of a certain type. Note that you will need to complete the function protoypes with
appropriate input data types and return types.
Sample Test Cases
User inputs are shown in blue.
6_1
0
A♦ 10♥ Q♣ 5♦ 2♠
others
6_2
3
7♠ 9♥ 10♦ 4♥ 7♦
one pair
6_3
3
7♠ 9♥ 10♦ 4♥ 7♦
one pair
6_4
540
10♣ 6♠ 10♥ 3♠ 10♦
three of a kind
6_5
13
8♦ 8♣ 9♦ J♥ J♣
two pair

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468