Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi. First of all this need to be done in c++.Topic is Data Structures.I need to do read basic math expression from a text file

Hi. First of all this need to be done in c++.Topic is Data Structures.I need to do read basic math expression from a text file , convert every seperated number to linked list and in the end i need to do operations like adding and multiplying and sending result to another text file. If you ask why are we doing this purpose of this project is store as big numbers as the memory of our computer allow us. Because of that we will use linked list not ints. The ints are limited as you know.

Input example(Given text's info);

Example:

12345678901234567890123456789012345678901234567890 + 34 * 1234567890123456789012345678901234567890

I need createBigInt, updateBigInt and freeBigInt functions.We need only two basic operations: + an *. You can refer to them as addBigInt and multiplyBigInt in our interface which can be used for adding or multiplying two big integers. And these functions should be in a separed header.

I decided using doubly linked list because of adding operation's carry bit so i can go prev and add carry over here. Same for multiplying. The doubly linked list code is given so i ll write it here. Also i am adding the pdf version of this homework as a png if you need any extra information.

---------------Doubly Linked List Code------------------------------------------------

#ifndef DOUBLY_LINKED_LIST #define DOUBLY_LINKED_LIST

template class DLLNode { public: DLLNode() { next = prev = 0; } DLLNode(const T& el, DLLNode *n = 0, DLLNode *p = 0) { info = el; next = n; prev = p; } T info; DLLNode *next, *prev; };

template class DoublyLinkedList { public: DoublyLinkedList() { head = tail = 0; } void addToDLLTail(const T&); T deleteFromDLLTail(); ~DoublyLinkedList() { clear(); } bool isEmpty() const { return head == 0; } void clear(); void setToNull() { head = tail = 0; } void addToDLLHead(const T&); T deleteFromDLLHead(); T& firstEl(); T* find(const T&) const; protected: DLLNode *head, *tail; friend ostream& operatornext) out info

template void DoublyLinkedList::addToDLLHead(const T& el) { if (head != 0) { head = new DLLNode(el,head,0); head->next->prev = head; } else head = tail = new DLLNode(el); }

template void DoublyLinkedList::addToDLLTail(const T& el) { if (tail != 0) { tail = new DLLNode(el,0,tail); tail->prev->next = tail; } else head = tail = new DLLNode(el); }

template T DoublyLinkedList::deleteFromDLLHead() { T el = head->info; if (head == tail) { // if only one DLLNode on the list; delete head; head = tail = 0; } else { // if more than one DLLNode in the list; head = head->next; delete head->prev; head->prev = 0; } return el; }

template T DoublyLinkedList::deleteFromDLLTail() { T el = tail->info; if (head == tail) { // if only one DLLNode on the list; delete head; head = tail = 0; } else { // if more than one DLLNode in the list; tail = tail->prev; delete tail->next; tail->next = 0; } return el; }

template T* DoublyLinkedList::find(const T& el) const { DLLNode *tmp = head; for ( ; tmp != 0 && !(tmp->info == el); // overloaded == tmp = tmp->next); if (tmp == 0) return 0; else return &tmp->info; }

template T& DoublyLinkedList::firstEl() { return head->info; }

template void DoublyLinkedList::clear() { for (DLLNode *tmp; head != 0; ) { tmp = head; head = head->next; delete tmp; } }

#endif

---------------Doubly Linked List Code------------------------------------------------

link to below picture if you cant see clearly: https://i.hizliresim.comJBrAg.png

image text in transcribed

unre tunarsty in laneunes there's a limit for integer number2 The limitsars defined in "lim tah" These can yary. For example the lergest lon inteser for my computer is 2147433647. Thererat mot 10- digits I can haus But someimes we neeg lareernumbers bavand the limit. The Input File Inths nputfile, themll be a ngle infK55ecesalonwithat most1D tokens. The tokens can bc RORtw inteers end+and Exempls We can have larger.oumbers if we store integers in liaked lists iostead, of ied addressable memec locations. In a linked list sech nods stares ons disit of the number. This way ws can storebi inte8sss as the memorx of the comuter allows The Output File In the result should be written to an ouput file nsmed "outout.txt to the same directory of the input file. hs sutputfle shauld hausa sinals Une whers thuswratten For sxamels ths follawing list rsaresentsa 6-digit gumbsr 153074 Bonus : fxou complete the followins extras you will set 10 bonus goints -Heving-and/ as xtre operstors Bonus 2: The students who can calculate the first 10000 digits of pi will et 20 bonus points Hint 1: YALcan wa sum of series approash such as Nilakantha series: We can stors as big numbers es ths memary of gur computer allow us Of courss thers are many other wavs te do this just maks your tsssarch and find a way te do it if Write an geplication that ws can stors vy bis intsasrs Your aeplication should provids an interfass for cceatine uedating and freeins laree itee herefare ey need createBleint updateblelnt and free NEint functio iw nsco tea o w 5 w5225ls.9peranong + an + You can refer them as addBig nt and multiplyBigint in your interface which can be used for addingc mulitwe big integers. You are frgeta inelude aav addltional fuoctiens nteyeur applikation Hint 2: The fica100 000 gigliare pi are. listed in here: http://www.geom.ui ty/math5337/groupe/digits.html You can teatesent roer integers with a linked list The type of the linked ist is SO meletexwR tXOM-You can erefer adoubl linked list Test your intcesos by addne assinin and muitipying 50 dt intcess Forsal, of simplicity ths neut integers will be assumed hev ng at most 50dats Note that the output can be lower than this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions