Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will create a C++ program that can evaluate arithmetic operators with integer numbers having any number of digits. These numbers are an alternative to

You will create a C++ program that can evaluate arithmetic operators with integer numbers having any number of digits. These numbers are an alternative to xed size integers or oating point numbers that always have a maximum number of accurate digits (dependent on size of CPU register).

The input is a regular text le, where each line is terminated with an end-of-line character(s). Each line will containanarithmeticoperationbetweentwonumbers. Theprogramshoulddisplaytheinputexpressionand the results, separated with =.

The main program should be called innitearithmetic. infinitearithmetic "input=;digitsPerNode=".

The following is the pseudocode

// DoubleLinkedList.h struct Node { long long num; Node* prev; Node* next; };

class DoubleLinkedList { public: DoubleLinkedList(); // default construct ~DoubleLinkedList(); // deconstruct DoubleLinkedList(const std::string& num, int digitsPerNode); // user defined construct DoubleLinkedList(const DoubleLinkedList& list); // copy construct DoubleLinkedList& operator = (const DoubleLinkedList& list); // assignment consturct public: DoubleLinkedList operator + (const DoubleLinkedList& list) const; DoubleLinkedList operator * (const DoubleLinkedList& list) const; // optional DoubleLinkedList operator - (const DoubleLinkedList& list) const; // 10% extra DoubleLinkedList operator / (const DoubleLinkedList& list) const; // 20% extra DoubleLinkedList Sqrt(const DoubleLinkedList& list) const; public: const Node* GetHead() const; const Node* GetTail() const; void Append(Node* node); void Print() const; private: Node* head; Node* tail; int m_digitsPerNode; long long remainder; // for / operator float decimal; // for sqrt() 7 valid digits. }

// main.cpp #include "ArgumentManager.h" int main(int argc, char* argv[]) { if (argc < 2) { std::cerr("Usage: infinitearithmetic \"filename=xyz.txt;digitsPerNode=\" "); } ArgumentManager am(argc, argv); std::string filename = am.get("filename"); int digitsPerNode = std::stoi(am.get("digitsPerNode")); std::ifstream ifs(filename.c_str()); std::string line; while (getline(ifs, line)){ std::string num1; std::string num2; std::string op; // get num1 num2 and operator in line // ... DoubleLinkedList l1(num1, digitsPerNode); // DoubleLinkedList(const std::string& num, int digitsPerNode) DoubleLinkedList l2(num2, digitsPerNode); DoubleLinkedList l(); // DoubleLinkedList(); if (/* plus */) {l = l1 + l2;} // DoubleLinkedList operator + (const DoubleLinkedList& list) const; DoubleLinkedList& operator = (const DoubleLinkedList& list); else if (/* mult */) // DoubleLinkedList operator * (const DoubleLinkedList& list) const; {l = l1 * l2;} else if (/* div */) {l = l1 / l2;} // DoubleLinkedList operator / (const DoubleLinkedList& list) const; else if (...) {//...} else { // ... } // output result } return 0; }

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

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago