Fraser International College CMPT XXXXXXXXXXAssignment 2 Dr. Yonas T. Weldeselassie Page 1 FIC - CMPT XXXXXXXXXXAssignment 2 Due Date and Time: Tuesday 15 March 2022 at 11:55PM PST Instructor: Dr....

2 answer below »
i have attached the file below


Fraser International College CMPT 135 2022-01 Assignment 2 Dr. Yonas T. Weldeselassie Page 1 FIC - CMPT 135 202201 - Assignment 2 Due Date and Time: Tuesday 15 March 2022 at 11:55PM PST Instructor: Dr. Yonas T. Weldeselassie (Ph.D.) In this assignment, we will be working with C++ classes to represent nodes of linked lists and linked list data structure and then use the linked list class in order to store numeric information representation in unsigned binary, sign and magnitude binary, and twos complement binary representations. For a detailed description of the linked list data structure, please refer to the supplementary material posted on Moodle together with this assignment. Representing Linked Lists with C++ class We may design a C++ class in order to represent a linked list. From our discussion in the supplementary material, we observe that a linked list class requires only one member variable which is the head pointer and then we could implement all the functions discussed in the supplementary material as member functions. You are provided the following Node class declaration and definition as well as LinkedList class declaration. The definitions of the member and friend functions of the LinkedList class are almost identical to the non member functions discussed in the supplementary material. The only difference is that the head pointer parameter of the non member functions discussed in the supplementary material is removed from these member and friend functions because the head pointer is a member variable of the class and therefore each of these member and friend functions has access to it and doesn't need it as a parameter. #include using namespace std; class Node { typedef Node* NodePtr; private: int data; NodePtr link; public: Node(); Node(const int &); Node(const Node &); int getData() const; NodePtr getLink() const; void setData(const int &); void setLink(const NodePtr &); friend ostream& operator < (ostream="" &,="" const="" node="" &);="" };="" typedef="" node*="" nodeptr;="" node::node()="" :="" data(0),="" link(nullptr)="" {}="" node::node(const="" int="" &d)="" :="" data(d),="" link(nullptr){}="" node::node(const="" node="" &n)="" :="" data(n.data),="" link(n.link){}="" int="" node::getdata()="" const="" {="" return="" data;="" }="" nodeptr="" node::getlink()="" const="" {="" return="" link;="" }="" void="" node::setdata(const="" int="" &d)="" {="" data="d;" }="" void="" node::setlink(const="" nodeptr="" &p)="" {="" link="p;" }="" ostream&="" operator="">< (ostream&="" out,="" const="" node&="" n)="" {="" out="">< n.data;="" return="" out;="" }="" typedef="" node*="" nodeptr;="" fraser="" international="" college="" cmpt="" 135="" 2022-01="" assignment="" 2="" dr.="" yonas="" t.="" weldeselassie="" page="" 2="" class="" linkedlist="" {="" private:="" nodeptr="" head;="" public:="" linkedlist();="" linkedlist(const="" linkedlist="" &);="" copy="" constructor="" (deep="" copy)="" ~linkedlist();="" destructor="" (must="" delete="" all="" the="" nodes="" from="" the="" heap)="" linkedlist&="" operator="(const" linkedlist="" &);="" assignment="" operator="" (deep="" copy)="" int="" getlength()="" const;="" return="" the="" number="" of="" nodes="" in="" the="" linked="" list="" void="" head_insert(const="" int="" &);="" nodeptr="" search_node(const="" int="" &)="" const;="" void="" insert_after(const="" nodeptr="" &,="" const="" int="" &)="" const;="" void="" remove_node(const="" nodeptr="" &);="" void="" remove_node(const="" int="" &);="" void="" remove_all(const="" int="" &);="" void="" tail_insert(const="" int="" &);="" void="" insert_before(const="" nodeptr="" &,="" const="" int="" &);="" friend="" ostream&="" operator="">< (ostream&,="" const="" linkedlist="" &);="" assignment="" specific="" member="" functions="" void="" flipbits()="" const;="" void="" reversebits()="" const;="" linkedlist="" operator="" +="" (const="" linkedlist="" &)="" const;="" void="" addone()="" const;="" int="" twoscomplementtodecimal()="" const;="" };="" you="" are="" required="" to="" implement="" the="" linkedlist="" class="" as="" described="" in="" the="" supplementary="" material.="" restrictions="" and="" requirements="" ="" you="" are="" not="" allowed="" to="" add="" or="" remove="" any="" include="" directive,="" namespace,="" member="" function,="" or="" friend="" function="" to="" the="" provided="" node="" and="" linkedlist="" classes.="" ="" you="" are="" not="" allowed="" to="" declare,="" define,="" or="" use="" any="" container="" variables="" (objects)="" such="" as="" static="" arrays,="" dynamic="" arrays,="" or="" any="" stl="" container="" such="" as="" vectors="" in="" your="" linkedlist="" class="" definition.="" ="" you="" are="" not="" allowed="" to="" use="" any="" stl="" algorithm="" in="" your="" linkedlist="" class="" definition.="" the="" flipbits,="" reversebits,="" operator="" +,="" addone,="" and="" twoscomplementtodecimal="" member="" functions="" of="" the="" linkedlist="" class="" should="" be="" implemented="" as="" follows:="" ="" flipbits:-="" a="" member="" function="" to="" flip="" the="" bits="" in="" the="" nodes="" of="" the="" calling="" object.="" assume="" each="" node="" data="" is="" a="" bit="" (0="" or="" 1).="" ="" reversebits:-="" a="" member="" function="" to="" reverse="" the="" bits="" in="" the="" nodes="" of="" the="" calling="" object.="" please="" note="" that="" this="" is="" a="" constant="" function="" because="" it="" only="" needs="" to="" modify="" the="" data="" of="" each="" node="" without="" modifying="" any="" member="" variable.="" example:="" reverse="" of="" 11100="" is="" 00111.="" ="" operator="" +:-="" a="" member="" function="" to="" add="" the="" bits="" in="" the="" nodes="" of="" the="" calling="" object="" and="" the="" argument="" object="" and="" return="" a="" linkedlist="" object="" whose="" nodes="" store="" the="" sum.="" ="" addone:-="" a="" member="" function="" to="" add="" 1="" to="" the="" bits="" in="" the="" nodes="" of="" the="" calling="" object.="" ="" twoscomplementtodecimal:-="" a="" member="" function="" to="" compute="" and="" return="" the="" decimal="" value="" of="" the="" bits="" in="" the="" nodes="" of="" the="" calling="" object="" assuming="" twos="" complement="" representation.="" fraser="" international="" college="" cmpt="" 135="" 2022-01="" assignment="" 2="" dr.="" yonas="" t.="" weldeselassie="" page="" 3="" information="" representation="" using="" linked="" lists="" now="" consider="" the="" following="" test="" program="" that="" makes="" use="" of="" the="" linkedlist="" class="" in="" order="" to="" represent="" numeric="" information="" in="" unsigned="" binary,="" sign="" and="" magnitude="" binary,="" and="" twos="" complement="" binary="" representations.="" int="" selectcomputation()="" {="" cout="">< "select="" your="" computation"="">< endl;="" cout="">< "="" 1.="" unsigned="" binary="" representation="" computation"="">< endl;="" cout="">< "="" 2.="" sign="" and="" magnitude="" representation="" computation"="">< endl;="" cout="">< "="" 3.="" two's="" complement="" representation="" computation"="">< endl;="" cout="">< "="" 4.="" exit="" program"="">< endl;="" int="" selection;="" cout="">< "enter="" your="" selection="" (1,="" 2,="" 3,="" or="" 4):="" ";="" cin="">> selection; while (selection != 1 && selection != 2 && selection != 3 && selection != 4) { cout < "please="" enter="" a="" correct="" choice:="" ";="" cin="">> selection; } return selection; } int main() { cout < "this="" program="" demonstrates="" the="" linked="" list="" data="" structure="" in="" c++"="">< endl;="" cout="">< "linked="" lists="" will="" be="" used="" for="" numeric="" information="" representation="" using"="">< endl;="" cout="">< "="" ***="" unsigned="" binary="" representation"="">< endl;="" cout="">< "="" ***="" sign="" and="" magnitude="" binary="" representation"="">< endl;="" cout="">< "="" ***="" two's="" complement="" binary="" representation"="">< endl="">< endl;="" cout="">< "in="" addition,="" the="" program="" demonstrates"="">< endl;="" cout="">< "="" ***="" two's="" complement="" binary="" addition,="" and"="">< endl;="" cout="">< "="" ***="" conversion="" from="" two's="" complement="" to="" decimal."="">< endl="">< endl;="" do="" {="" int="" selection="selectComputation();" if="" (selection="=" 1)="" {="" int="" bit_pattern_size,="" num;="" cout="">< endl="">< "enter="" a="" positive="" integer="" for="" the="" bit="" pattern="" size:="" ";="" cin="">> bit_pattern_size; while (bit_pattern_size <= 0)="" {="" cout="">< "you="" must="" enter="" a="" positive="" integer.="" enter="" again="" please:="" ";="" cin="">> bit_pattern_size; } cout < "enter="" a="" non-negative="" integer:="" ";="" cin="">> num; while (num < 0)="" {="" cout="">< "you="" must="" enter="" a="" non-negative="" integer.="" enter="" again="" please:="" ";="" cin="">> num; } LinkedList LL = computeUnsignedBinary(num, bit_pattern_size); cout < "the="" unsigned="" binary="" representation="" of="" "="">< num="">< "="" in="" "="">< bit_pattern_size="">< "="" bit="" is="" "="">< ll="">< endl;="" cout="">< endl;="" }="" else="" if="" (selection="=" 2)="" {="" int="" bit_pattern_size,="" num;="" cout="">< endl="">< "enter="" a="" positive="" integer="" for="" the="" bit="" pattern="" size:="" ";="" cin="">> bit_pattern_size; while (bit_pattern_size <= 0)="" {="" fraser="" international="" college="" cmpt="" 135="" 2022-01="" assignment="" 2="" dr.="" yonas="" t.="" weldeselassie="" page="" 4="" cout="">< "you="" must="" enter="" a="" positive="" integer.="" enter="" again="" please:="" ";="" cin="">> bit_pattern_size; } cout < "enter="" an="" integer:="" ";="" cin="">> num; LinkedList LL = computeSignAndMagnitudeBinary(num, bit_pattern_size); cout < "the="" sign="" and="" magnitude="" binary="" representation="" of="" "="">< num="">< "="" in="" "="">< bit_pattern_size="">< "="" bit="" is="" "="">< ll="">< endl;="" cout="">< endl;="" }="" else="" if="" (selection="=" 3)="" {="" int="" bit_pattern_size,="" num1,="" num2;="" cout="">< endl="">< "enter="" a="" positive="" integer="" for="" the="" bit="" pattern="" size:="" ";="" cin="">> bit_pattern_size; while (bit_pattern_size <= 0)="" {="" cout="">< "you="" must="" enter="" a="" positive="" integer.="" enter="" again="" please:="" ";="" cin="">> bit_pattern_size; } cout < "enter="" an="" integer:="" ";="" cin="">> num1; LinkedList LL1 = computeTwosComplementBinary(num1, bit_pattern_size); cout < "the="" two's="" complement="" binary="" representation="" of="" "="">< num1="">< "="" in="" "="">< bit_pattern_size="">< "="" bit="" is="" "="">< ll1="">< endl;="" cout="">< endl;="" cout="">< "enter="" a="" second="" integer:="" ";="" cin="">> num2; LinkedList LL2 = computeTwosComplementBinary(num2, bit_pattern_size); cout < "the="" two's="" complement="" binary="" representation="" of="" "="">< num2="">< "="" in="" "="">< bit_pattern_size="">< "="" bit="" is="" "="">< ll2="">< endl;="" cout="">< endl;="" linkedlist="" ll3="LL1" +="" ll2;="" cout="">< "the="" binary="" sum="" of="" "="">< ll1="">< "="" and="" "="">< ll2="">< "="" is="" "="">< ll3="">< endl;="" int="" sum="LL3.twosComplementToDecimal();" cout="">< "the="" integer="" value="" of="" the="" binary="" sum="" is="" "="">< sum="">< endl;="" if="" (sum="=" num1="" +="" num2)="" cout="">< "this="" is="" a="" correct="" result."="">< endl; else endl;="">
Answered 1 days AfterMar 11, 2022

Answer To: Fraser International College CMPT XXXXXXXXXXAssignment 2 Dr. Yonas T. Weldeselassie Page 1 FIC -...

Vaibhav answered on Mar 13 2022
99 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here