首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导EEE computing程序、讲解C++设计编程 讲解SPSS|辅导R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
Assignment 2 (Spring 2021)
This assignment deals with the representation of boolean functions (in the sense of logic functions, not of C++ functions)
using linked data structures. Let's begin with an example.
Consider the logic and boolean function, with two parameters x1 and x2 and the following truth table:
x1 x2 x1 and x2
0 0 0
0 1 0
1 0 0
1 1 1
It can be represented in a tree-like form as follows (a left branch represents assigning a 0 to that parameter, a right branch
assigning a 1):
In C++ this can be implemented as a linked data structure whose nodes are defined by a structured data type.
Complete the following code:
bt.cpp
#include
#include
#include
// you can include other headers
// you need for your code
// you can use only headers from the C++ standard library
// you can use any headers from the C++ standard library
// except for the algorithm header
// do not use "using namespace std;"
// do not alter this structured data type definition
2021/3/17 progeng:a2sp21 [EEE computing]
https://intranet.ee.ic.ac.uk/m.cattafi/scripts/dw/doku.php?id=progeng:a2sp21 2/6
struct BNode{
std::string val;
// this will contain
// "x1", "x2"... "xn" in non-leaf nodes
// "0" or "1" in leaf nodes
BNode* left;
// this will conventionally represent the 0 branch
BNode* right;
// this will conventionally represent the 1 branch
// (as usual leaf nodes will have both left and right pointing to NULL)
};
// you can define other functions to be used in the two functions below
// if you want you can also define and use other
// structured data types or classes including member data and member functions
// do not alter the following line that begins the function build_bt
BNode* build_bt(const std::vector
& fvalues){
// implement this function (see explanation further down)
}
// do not alter the following line that begins the function eval_bt
std::string eval_bt(BNode* bt, const std::string& input){
// implement this function (see explanation further down)
}
// add a main for you to test your program
// but the content of the main won't be considered for the assessment
build_bt
This function returns a pointer to the first node of the linked data structure representing the boolean function. The input
contains only the rows of the truth table with a value of 1 for the boolean function.
For example for the and boolean function we would have:
int main(){
std::vector
fvalues;
std::string row;
row = "11";
fvalues.push_back(row);
BNode* bt;
bt = build_bt(fvalues);
}
For the or boolean function we could have:
int main(){
std::vector
fvalues;
std::string row;
row = "01";
fvalues.push_back(row);
row = "10";
fvalues.push_back(row);
row = "11";
fvalues.push_back(row);
BNode* bt;
bt = build_bt(fvalues);
2021/3/17 progeng:a2sp21 [EEE computing]
https://intranet.ee.ic.ac.uk/m.cattafi/scripts/dw/doku.php?id=progeng:a2sp21 3/6
}
However the function must work whatever the order of the lines so for the or boolean function we could also equivalently
have for example:
int main(){
std::vector
fvalues;
std::string row;
row = "11";
fvalues.push_back(row);
row = "01";
fvalues.push_back(row);
row = "10";
fvalues.push_back(row);
BNode* bt;
bt = build_bt(fvalues);
}
We consider boolean functions with any number (greater than 0) of parameters. We could have for instance a function with
six parameters whose value is always 0 except for the following lines of the truth table:
x1 x2 x3 x4 x5 x6 f(x1, x2, x3, x4, x5, x6)
0 0 0 0 1 0 1
0 1 0 0 1 0 1
1 1 0 0 1 1 1
In which case we could have for example:
int main(){
std::vector
fvalues;
std::string row;
row = "000010";
fvalues.push_back(row);
row = "010010";
fvalues.push_back(row);
row = "110011";
fvalues.push_back(row);
BNode* bt;
bt = build_bt(fvalues);
}
Note that the order of the values within each string is important, for example if we have “000010” then the parameter with
value 1 in that string is expressed unambiguously as corresponding to x5.
eval_bt
This function takes in input a pointer to the first node of a linked data structure representing a boolean function and a string
representing the values for the parameters of the boolean function and returns the value of the boolean function for that
configuration of values.
For example:
int main(){
std::vector
fvalues;
2021/3/17 progeng:a2sp21 [EEE computing]
https://intranet.ee.ic.ac.uk/m.cattafi/scripts/dw/doku.php?id=progeng:a2sp21 4/6
std::string row;
row = "000010";
fvalues.push_back(row);
row = "010010";
fvalues.push_back(row);
row = "110011";
fvalues.push_back(row);
BNode* bt = build_bt(fvalues);
std::cout << eval_bt(bt, "000010") << std::endl;
// should print "1"
std::cout << eval_bt(bt, "000001") << std::endl;
// should print "0"
}
Guidelines
Please note that there are important guidelines also in the comments in the source code above.
None of the functions, except for the main, should contain user or file input or output (std::ifstream, std::cin, std::cout, etc) in
their implementation. In other words, std::ifstream, std::cin, std::cout, etc are only allowed in the main. If you add any of
these to other functions for debugging purposes you must remove them before submitting.
All the variables should be declared in the scope of a function (either the main or some other one). In other words, global
variables are not allowed.
All the loops should be controlled/terminated either by the loop condition or by return. Statements such as break, continue,
goto are not allowed anywhere in the program.
Do not use the switch statement.
Our reference C++ compiler is the one on repl. To make sure that your program respects the standard, periodically check
that your code runs and works as expected also on repl (but do not leave your code for the assignment on repl for longer than
it takes to test that it works).
Assessment criteria
In order to be awarded a mark in the the 70%-100% range, a submission must fulfill all of these conditions:
All the requirements and guidelines must be respected.
The code must be entirely correct. For example (this is not an exhaustive list):
If one or more of the automated tests are not passed, the code is not correct.
If there are occurrences of crashes, infinite loops, or infinite recursion, the code is not correct.
If there are undefined behaviour instructions in the code, then it is not correct (regardless of whether or not it is
noticeable when the program is run).
The code must be generally well indented and formatted and readable, with reasonably meaningful names for the
variables.
Within the 70%-100% range the criteria are:
The more readable the code, the better.
Good functional decomposition should be applied, also in order to avoid code duplication.
The code doesn't need to be optimised for efficiency, but wastefulness should be avoided, as in the examples in the
notes. Think of the prime number example, in which the loop terminates as soon as the first factor is found (instead of
going on to try other potential factors) or as soon as the square root of the number is reached (instead of trying all the
numbers up to the input).
Q&A
2021/3/17 progeng:a2sp21 [EEE computing]
https://intranet.ee.ic.ac.uk/m.cattafi/scripts/dw/doku.php?id=progeng:a2sp21 5/6
I am not sure how to do something and it's not in the notes.
Yes, some aspects of this assignment require you to do some autonomous study using for example resources such as the C++
documentation.
The following program also shows an example of some useful operations on std::string:
#include
#include
bool contains_letter(std::string letter, std::string word){
std::string word_i;
// we can use member function size on std::string as we would do for std::vector
for(int i = 0; i < word.size(); i++){
// we can index an std::string character by character
// using [] as we would do for std::vector
// but the return is of type char, not of type std::string
// and we can't compare a char and an std::string directly
// however if we add the char to an empty std::string
// using push_back (once again as we would do for std::vector)
// we obtain an std::string containing the character
word_i = "";
word_i.push_back(word[i]);
// now we can compare the two std::string
if(letter == word_i){
return true;
}
}
return false;
}
int main(){
std::string word, letter;
std::cout << "please enter a word" << std::endl;
std::cin >> word;
std::cout << "please enter a letter" << std::endl;
std::cin >> letter;
if(contains_letter(letter, word)){
std::cout << letter << " is contained in " << word << std::endl;
}
else{
std::cout << letter << " is not contained in " << word << std::endl;
}
}
Can I assume that the functions will always be tested with meaningful and consistent input?
Yes.
Can I make the data structure start from a node other than x1? Or rearrange the order, e.g. have nodes
other than x2 at the level below x1? Or reduce the number of allocated nodes by having that nodes can have
several parent nodes or that left and right point to the same node etc?
No, you must keep everything as shown in the requirements also because the automated testing will not work if you make
changes of this kind.
Consider again the figure shown above:
2021/3/17 progeng:a2sp21 [EEE computing]
https://intranet.ee.ic.ac.uk/m.cattafi/scripts/dw/doku.php?id=progeng:a2sp21 6/6
each node in the figure must be a distinct node allocated at a different address in memory, even though several of them will
have the same content for the val member data, for example all the leaf nodes with value 0.
Should I add comments?
Feel free to add some if you think they would be useful for yourself to understand your own code or to explain some aspects of
your program, but it is more important that your code is clear and readable on its own, minimising the need for comments.
Do not add too many comments: that will only make us waste time by having to remove them before we check your
submission.
The code draft has already some comments containing instructions, etc. You can leave them in your submission or remove
them, that's up to you.
When will the grades be available?
By the end of the first week of Summer term (Friday 30th April) grades and feedback for most submissions (those not
presenting particular issues) will be available on Blackboard (I will send a notification email).
Can you or a TA help me with the assignment?
No because it's assessed. We can however help you with other exercises on the topics involved in the assignment.
I have another question.
Sure, you can send me an email but:
1) First please reread this page and double check that the answer isn't already here or elsewhere on this website or on
Blackboard.
2) Make sure you send your email by Tuesday 23rd March as I am unlikely to answer emails received after that.
progeng/a2sp21.txt · Last modified: 2021 by mc
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写infosys 110 digital syst...
2024-12-28
代写fbe 506 quantitative met...
2024-12-28
代做part i: (crazy eddie htm...
2024-12-28
代写infosys 110 digital syst...
2024-12-28
代做stats 769 statistics sec...
2024-12-28
代写ece3700j introduction to...
2024-12-28
代做tcm2301 biochemistry代做...
2024-12-28
代做ece5550: applied kalman ...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写scicomp project 3 week 4...
2024-12-28
代做business operations anal...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写socs0100 computational t...
2024-12-28
热点标签
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
软件定制开发网!