You will create a C program that can evaluate arithmetic ope

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=<file name>;digitsPerNode=<number>\".

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=<number>\\\"\ \");
   }
   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;
}

Solution

For this question we have the following program:

#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>

int main() {

ifstream myReadFile;
myReadFile.open(\"input.txt\"); //Name of Input File
char input[100];
String operand={\"\",\"\"};
char operation;
int n1,n2;
int i=0;
while (!myReadFile.eof()) {
myReadFile >> input;
if(input!=\"\ \")
{ cout<<input;
   if(input!=\'+\'|| input!=\'-\'|| input!=\'/\'|| input!=\'*\')
   {
   operand[i]=operand[i]+input;
   }
   else
   {
       operation=input;
       i=1;
   }
else
{
   cout<<\"=\";
   n1=atoi(operand[0]); // Convert String into number
   n2=atoi(operand[1]);
   if(operation==\"+\")
       cout<<n1+n2;
   elseif(operation==\"-\")
       cout<<n1-n2;
   elseif(operation==\"/\")
       cout<<n1/n2;
   else
       cout<<n1*n2;
   i=0;
}

}

}
myReadFile.close();
getch();
return 0;
}

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 s
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 s
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 s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site