{"id":47887,"date":"2020-08-06T17:33:57","date_gmt":"2020-08-06T17:33:57","guid":{"rendered":"https:\/\/essays.homeworkacetutors.com\/2020\/08\/c-finish-the-code\/"},"modified":"2020-08-06T17:33:57","modified_gmt":"2020-08-06T17:33:57","slug":"c-finish-the-code","status":"publish","type":"post","link":"https:\/\/www.colapapers.com\/us\/c-finish-the-code\/","title":{"rendered":"C++ Finish the code"},"content":{"rendered":"<p>Question description<\/p>\n<p>There are\u00a0two &#8220;TODO&#8221; to do. There will be more info attached in a file. You do need to make a new code from scratch, since most of it is doneI&#8217;m not paying more than 7 dollars because it&#8217;s not a big job.\u00a0#include <iostream><br \/>\n#include <string><\/p>\n<p>using namespace std;<\/p>\n<p>\/\/==========================================================================<br \/>\n\/\/                                 CONSTANTS<br \/>\n\/\/==========================================================================<\/p>\n<p>\/\/ error codes<br \/>\nconst int ERROR_CAPACITY_OVERFLOW = 1;<\/p>\n<p>\/\/ maximum size allowed for a set<br \/>\nconst int MAX_SET_SIZE = 256;<\/p>\n<p>\/\/==========================================================================<br \/>\n\/\/                                  TYPES<br \/>\n\/\/==========================================================================<\/p>\n<p>\/\/ structure to represent sets of integers<br \/>\nstruct IntSet {<\/p>\n<p>    int elem[MAX_SET_SIZE]; \/\/ the elements in the set (occupied 0 to n-1)<br \/>\n    int size = 0;           \/\/ the number of elements currently in the set<\/p>\n<p>};<\/p>\n<p>\/\/==========================================================================<br \/>\n\/\/                                FUNCTIONS<br \/>\n\/\/==========================================================================<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/ isEmpty(s): returns true if the set is empty and false otherwise.<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>bool isEmpty(IntSet s) {<\/p>\n<p>    \/\/ s is empty if its size is zero<br \/>\n    return s.size == 0;<\/p>\n<p>}<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/ isMember(s, x): Returns true if x is a memeber of set s and false otherwise.<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>bool isMember(IntSet s, int x) {<\/p>\n<p>    \/\/ for every occupied cell of our array&#8230;<br \/>\n    for (int i = 0; i < s.size ; i++) {\n\n        \/\/ compare contents to x\n        if (s.elem[i] == x)\n            return true;\n\n    }\n\n    \/\/ if we're here, x was not in the set\n    return false;\n\n}\n\n\/\/--------------------------------------------------------------------------\n\/\/ add(s, x): adds element x into set s. If x already is a member of s, then\n\/\/ this operation has no effect.\n\/\/--------------------------------------------------------------------------\n\nvoid add(IntSet &#038;s, int x) {\n\n    \/\/ if there is room remaining\n    if (s.size < MAX_SET_SIZE) {\n\n        \/\/ if x is not already in the set\n        if (!isMember(s, x)) {\n\n            \/\/ place x in the elem array of s\n            s.elem[s.size] = x;\n\n            \/\/ update the size of s\n            s.size++;\n\n        }\n\n    }\n    else {\n\n        \/\/ the set is filled to capacity\n        cout << \"Error: attempted to add an element to a maximum capacity set.\";\n        exit(ERROR_CAPACITY_OVERFLOW);\n\n    }\n\n}\n\n\/\/--------------------------------------------------------------------------\n\/\/ clear(s): Clear the set s so that it is empty.\n\/\/--------------------------------------------------------------------------\n\nvoid clear(IntSet &#038;s) {\n    s.size = 0;\n}\n\n\/\/--------------------------------------------------------------------------\n\/\/ print(s): Prints set s to the console.\n\/\/--------------------------------------------------------------------------\n\nvoid print(IntSet s) {\n\n    cout << \"{\";\n    for (int i = 0; i < s.size - 1; i++) {\n        cout << s.elem[i] << \", \";\n    }\n    if (s.size > 0) {<br \/>\n        cout << s.elem[s.size - 1];\n    }\n    cout << \"}\" << endl;\n\n}\n\n\/\/-------------------------------------------------------------------------\n\/\/ setIntersection(s1, s2, result): Compute the intersection of s1 and s2 and\n\/\/ place it into result.\n\/\/--------------------------------------------------------------------------\n\nvoid setIntersection(IntSet s1, IntSet s2, IntSet &#038;result) {\n\n    clear(result);\n\n    \/\/ TODO: Complete the code below...\n\n    \/\/ for every member of s1\n        \/\/ if it is a member of s2\n            \/\/ add it to the result\n\n}\n\n\/\/-------------------------------------------------------------------------\n\/\/ setUnion(s1, s2, result): Compute the union of s1 and s2 and place it into\n\/\/ result.\n\/\/ ------------------------------------------------------------------------\n\nvoid setUnion(IntSet s1, IntSet s2, IntSet &#038;result) {\n\n    clear(result);\n\n    \/\/ TODO: Complete the code below...\n\n    \/\/ for every member of s1\n        \/\/ add it to the result\n\n    \/\/ for every member of s2\n        \/\/ add it to the result\n\n}\n\n\/\/--------------------------------------------------------------------------\n\/\/                                 MAIN PROGRAM\n\/\/--------------------------------------------------------------------------\n\nint main() {\n\n    \/\/ fill s1 with {1, 2, 3, 4, 5}\n    IntSet s1;\n    for (int x = 1; x <= 5; x++) {\n        add(s1, x);\n    }\n    cout << \"s1: \";\n    print(s1);\n\n    \/\/ fill s2 with {4, 5, 6, 7, 8}\n    IntSet s2;\n    for (int x = 4; x <= 8; x++) {\n        add(s2, x);\n    }\n    cout << \"s2: \";\n    print(s2);\n\n    \/\/ compute intersection and print it\n    IntSet res1;\n    setIntersection(s1, s2, res1);\n    cout << \"intersection of s1 and s2: \";\n    print(res1);\n\n    \/\/ compute union and print it\n    IntSet res2;\n    setUnion(s1, s2, res2);\n    cout << \"union of s1 and s2: \";\n    print(res2);\n\n}\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question description There are\u00a0two &#8220;TODO&#8221; to do. There will be more info attached in a file. You do need to make a new code from scratch, since most of it is doneI&#8217;m not paying more than 7 dollars because it&#8217;s not a big job.\u00a0#include #include using namespace std; \/\/========================================================================== \/\/ CONSTANTS \/\/========================================================================== \/\/ error codes [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6515,8569,8567,8568,8570],"tags":[5882,6803,4009,7294,7293],"class_list":["post-47887","post","type-post","status-publish","format-standard","hentry","category-dissertation-writing","category-essay-writing","category-homework-assistance","category-online-assignment-help","category-paper-writing-services","category-write-my-essay-2","tag-best-essays-uk","tag-dissertation-topic-help","tag-do-my-essay-assignment-in-ireland","tag-essay-for-sale-australia","tag-help-with-writing-an-essay"],"_links":{"self":[{"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/posts\/47887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/comments?post=47887"}],"version-history":[{"count":0,"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/posts\/47887\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/media?parent=47887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/categories?post=47887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.colapapers.com\/us\/wp-json\/wp\/v2\/tags?post=47887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}