首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
C++编程设计调试、BASICS CS246编程讲解、C/C++程序语言辅导 调试Matlab程序|辅导Python编程
项目预算:
开发周期:
发布时间:
要求地区:
ASSIGNMENT #2: C++ BASICS CS246, WINTER 2021
Assignment #2: C++ Basics
Due Date 1: Friday, February 5, 2021, 5:00 pm EST
Due Date 2: Friday, February 12, 2021, 5:00 pm EST
Online Quiz: Wednesday, February 10, 2021, 5:00 pm EST
Topics that must have been completed before starting Due Date 1:
1. Software Testing
2. produceOutputs and runSuite from A1
Topics that must have been completed before starting Due Date 2:
1. C++: Introduction to C++
2. Preprocessing and Compilation
Learning objectives:
• C++ I/O (standard, file streams) and output formatting
• C++ Struct
• C++ strings and stringstreams
• C++ references, pointers, and dynamic memory allocation
• Questions 1, 2a, 3a 4a are due on Due Date 1; questions 2b, 3b, and 4b are due on Due Date 2. You
must submit the online quiz on Learn by the Quiz date.
• On this and subsequent assignments, you will take responsibility for your own testing. This assignment is
designed to get you into the habit of thinking about testing before you start writing your program. For each
question you will be given a compiled executable program which is a program representing a solution to
each question. You should use these provided executables to help you write your test cases, as they can
show you the resultant output for given inputs. If you look at the deliverables and their due dates, you will
notice that there is no C++ code due on Due Date 1. Instead, you will be asked to submit test suites for C++
programs that you will later submit by Due Date 2.
Test suites will be in a format compatible with that of the latter questions of Assignment 1, so if you did a
good job writing your runSuite script, that experience will serve you well here.
• Design your test suites with care; they are your primary tool for verifying the correctness of your code. Note
that test suite submission zip files are restricted to contain a maximum of 40 tests. The size of each input
(.in) file is also restricted to 300 bytes, and each output file (.out) is restricted to 1,000 bytes. This is
to encourage you not to combine all of your testing eggs in one basket.
• You must use the standard C++ I/O streaming and memory management (MM) facilities on this assignment;
you may not use C-style I/O or MM. More concretely, you may #include the following C++ libraries
(and no others!) for the current assignment: iostream, fstream, sstream, iomanip, and string.
Marmoset will be setup to reject submissions that use C-style I/O or MM, or libraries other than the ones
specified above.
• We will manually check that you follow a reasonable standard of documentation and style, and to verify
any assignment requirements that are not automatically enforced by Marmoset. Code to a standard
that you would expect from someone else if you had to maintain their code. Further comments on coding
guidelines can be found here: https://www.student.cs.uwaterloo.ca/˜cs246/W21/
codingguidelines.shtml
Page 1 of 5
ASSIGNMENT #2: C++ BASICS CS246, WINTER 2021
• We have provided some code and sample executables in the subdirectory codeForStudents under the
appropriate subdirectories. These executables have been compiled in the CS student environment and
will not run anywhere else.
• You may not ask public questions on Piazza about what the programs that make up the assignment
are supposed to do. A major part of this assignment involves designing test cases, and questions that ask
what the programs should do in one case or another will give away potential test cases to the rest of the
class. Questions found in violation of this rule will be marked private or deleted; repeat offences could be
subject to discipline.
Note: We suggest creating the directory ~/cs246/w21/a2 and creating all the assignment solutions in this directory.
Coding Assessment
Questions 2 to 4 are part of the coding assessment, and may be publicly discussed on Piazza so long as solutions are neither
discussed nor revealed.
Question 1
1. Note: there is no coding associated with this problem. Testing question.
You are given a non-empty array a[0..n − 1], containing n integers. The program maxSum determines the indices i and
j, i ≤ j, for which Pj
k=i
a[k] is maximized and reports the maximum value of Pj
k=i
a[k]. Note that since i ≤ j, the
sum always contains at least one array element. For example, if the input is
-3 4 5 -1 3 -9
then maxSum prints
11
(Output is printed on a single complete line with no padding.) Your task is not to write this program, but to design a
test suite for this program. Your test suite must be such that a correct implementation of this program passes all of your
tests, but a buggy implementation will fail at least one of your tests. Marmoset will use a correct implementation and
several buggy implementations to evaluate your test suite in the manner just described.
Your test suite should take the form described in A1: each test should provide its input in the file testname.in,
and its expected output in the file testname.out. The collection of all testnames should be contained in the file
suiteq1.txt.
Zip up all of the files that make up your test suite into the file a2q1.zip, and submit to Marmoset.
Question 2
2. In this problem, you will write a program called change that makes change for any country’s monetary system (real
or fictional). This program accepts, from standard input, the coin denominations that make up the monetary system,
and the total value. It then prints a report of the combination of coins needed to make up the total. For example if a
particular country has coins with values 1, 3, and 8, and you have 13 units of money, then the input would be as follows:
ASSIGNMENT #2: C++ BASICS CS246, WINTER 2021
The initial 3 means that there are 3 coin types. The next three values are the coin denominations, in some order. The
last value is the total. For this input, the output should be
1 x 8
1 x 3
2 x 1
Notes:
• Most coin systems have the property that you can make change by starting at the highest coin value, taking as
many of those as possible, and then moving on to the next coin value, and so on. Although not all combinations of
coin denominations have this property, you may assume that the input for change will always have this property.
• The Canadian government has recently abolished the penny. Consequently, once the remaining pennies work their
way out of circulation, it will be impossible to construct coin totals not divisible by 5. Similarly, in whatever
system of denominations you are given, it may not be possible to construct the given total. If that happens, output
Impossible (and nothing else) to standard output.
• You may assume that the number of denominations is at most 10.
• You may assume that no denomination will be listed twice.
• If a given coin is used 0 times for the given total, do not print it out; your output should contain only those
denominations that were actually used, in decreasing order of size.
(a) Due on Due Date 1: Design a test suite for this program. Call your suite file suiteq2.txt. Zip your suite file,
together with the associated .in and .out files, into the file a2q2.zip.
(b) Due on Due Date 2: Write the program in C++. Call your program a2q2.cc.
Question 3
3. A prettyprinter is a tool that takes program source code as input and outputs the same code, nicely formatted for
readability. In this problem, you will write a prettyprinter for a C-like language.
The input for your program will be a sequence of “words”, spanning one or more lines. The words denote tokens, the
“pieces” that make up a program. The words will be separated from each other by one or more whitespace characters
(space, tab, newline). Your program will take these tokens and arrange them nicely, according to the following rules:
• Initially, the code is flush to the left margin (i.e., not indented);
• If the word is ;, print the word and go to the next line;
• If the word is {, print the word, go to the next line, and the following lines will be indented by one more space
than previously;
• If the word is }, it should be printed on its own line, indented one character to the left of the lines between it and
its matching { (i.e., the indentation level will be the same as the indentation level of the line that contained the
matching {), and the following lines are indented to the same level as this word;
• If the word is //, then the rest of the current line of input is considered a comment, and must be printed exactly
as it is, including spacing;
• Except for comments, all of the tokens on a line should be separated from one another by exactly one space.
Sample input:
int f ( int x ) { // This is my function
int y = x ; y = y + 1 ; return y ; } // This is the END of my function
int main () { int n = 0 ; while ( n < 10 ) { n = f ( n ) ; } }
Page 3 of 5
ASSIGNMENT #2: C++ BASICS CS246, WINTER 2021
Corresponding output:
int f ( int x ) {
// This is my function
int y = x ;
y = y + 1 ;
return y ;
}
// This is the END of my function
int main () {
int n = 0 ;
while ( n < 10 ) {
n = f ( n ) ;
}
}
Your solution must not print any extra whitespace at the end of the line (exception: if a comment ends with spaces, then
you must keep those spaces in your output). However, if trailing space is the only thing wrong with your program, you
can receive partial credit.
You may assume: That all tokens are separated by whitespace. In particular, the special words {, }, ;, and // will not
be “attached” to other tokens, as they can be in C.
You may not assume: That the input language is actually C. All you are told is that the input language uses brace
brackets, semicolons, and // comments in a way similar to C, but subject to those constraints, the input could be
anything. So do not assume that any properties of the C language, beyond what you have been told, will be true for the
input.
(a) Due on Due Date 1: Design a test suite for this program. Call your suite file suiteq3.txt. Zip your suite file,
together with the associated .in and .out files, into the file a2q3.zip.
(b) Due on Due Date 2: Write the program in C++. Save your solution in a2q3.cc.
Question 4
4. We typically use arrays to store collections of items (say, integers). We can allow for limited growth of a collection
by allocating more space than typically needed, and then keeping track of how much space was actually used. We can
allow for unlimited growth of the array by allocating the array on the heap and resizing as necessary. The following
structure encapsulates a partially-filled array:
struct IntArray {
int size; // number of elements the array currently holds
int capacity; // number of elements the array could hold, given current
// memory allocation to contents
int *contents;
};
• Write the function readIntArray which returns an IntArray structure, and whose signature is as follows:
IntArray readIntArray();
Page 4 of 5
ASSIGNMENT #2: C++ BASICS CS246, WINTER 2021
The function readIntArray consumes as many integers from cin as are available, populates an IntArray
structure in order with these, and then returns the structure. If a token that cannot be parsed as an integer is
encountered before the structure is full, then readIntArray fills as much of the array as needed, leaving the
rest unfilled. If a non-integer is encountered, the first offending character should be removed from the input
stream (i.e., call cin.ignore once with no arguments). In all circumstances, the field size should accurately
represent the number of elements actually stored in the array and capacity should represent the amount of
storage currently allocated to the array.
• Write the function addToIntArray, which takes a reference to an intArray structure and adds as many
integers to the structure as are available on cin. The behaviour is identical to readIntArray, except that
integers are being added to the end of an existing intArray. The signature is as follows:
void addToIntArray(IntArray&);
• Write the function printIntArray, which takes a reference to an IntArray structure, and whose signature
is as follows:
void printIntArray(const IntArray&);
The function printIntArray(a) prints the contents of a (as many elements as are actually present) to cout,
on the same line, separated by spaces, and followed by a newline. There should be a space after each element in
the array (including the last element), and not before the first element.
It is not valid to print or add to an array that has not previously been read, because its fields may not be
properly set. You should not test this.
For memory allocation, you must follow this allocation scheme: every IntArray structure begins with a capacity of
0. The first time data is stored in an IntArray structure, it is given a capacity of 5 and space allocated accordingly.
If at any point, this capacity proves to be not enough, you must double the capacity (so capacities will go from 5 to 10
to 20 to 40 ...). Note that there is no realloc in C++, so doubling the size of an array necessitates allocating a new
array and copying items over. Your program must not leak memory.
A test harness is available in the starter file a2q4.cc, which you will find in your cs246/1211/a2 directory. Make
sure you read and understand this test harness, as you will need to know what it does in order to structure your
test suite. Note that we may use a different test harness to evaluate the code you submit on Due Date 2 (if your functions
work properly, it should not matter what test harness we use).
(a) Due on Due Date 1: Design a test suite for this program, using the main function provided in the test harness.
Call your suite file suiteq4.txt. Zip your suite file, together with the associated .in and .out files, into the
file a2q4.zip.
(b) Due on Due Date 2: Write the program in C++. Call your solution a2q4.cc.
Submission
The following files are due at Due Date 1: a2q1.zip, a2q2.zip, a2q3.zip, a2q4.zip.
The following files are due at Due Date 2: a2q2.cc, a2q3.cc, a2q4.cc.
Page 5 of 5
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!