Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the following program so that instead of using input from the user, the program gets it's input from a file called input.txt where the

Change the following program so that instead of using input from the user, the program gets it's input from a file called "input.txt" where the data is terminated by -1.

Example of input.txt:

957994954495949457454 774874754744875847484 80485080443358 4849850549686868696 99999999 11111111111111111876333 777777678 9999999999 5555555555 44444444444444444465 -1

And that the output is shown in both the console as

image text in transcribed

and in a output.txt as

image text in transcribed

The program is as follows:

#include #include #include #include

using namespace std;

class Node { public: int value; Node * next; Node(); Node(int); };

Node::Node():value(0),next(NULL){} Node::Node(int j):value(j),next(NULL){}

void Print(Node * k)

{

if(!k) return; Print(k->next); coutvalue;

}

void AddHead(Node* & head, int n)

{

Node * temp = new Node(n); temp->next = head; head=temp;

}

void Addition( Node* int1,Node* int2)

{

int carry = 0, sum; Node* result = NULL; Node* temp = NULL; Node* prev = NULL; while(int1 !=NULL || int2 != NULL)

{

sum = carry +((int1? int1->value: 0) +(int2? int2->value: 0)); carry = (sum >=10)? 1:0; sum = sum % 10; temp = new Node(sum); if(result== NULL){ result = temp;} else{ prev->next = temp;} prev = temp; if(int1) int1=int1->next; if(int2) int2=int2->next;

}

if(carry > 0) temp->next = new Node(carry); Print(result);

}

int Length(Node* head) { int i=0; while(head) { i++; head=head->next; } return i; }

int main() { ifstream fin; ofstream fout; int *num1, *num2; char ans; int j; Node* int1 = NULL; Node* int2 = NULL; fin.open("input.txt"); fout.open("output.txt"); num1=(int*)malloc(sizeof(int)); num2=(int*)malloc(sizeof(int)); fin >> *num1; while(*num1!='-1'){ fin >> *num2; fout> *num2; for(unsigned int i=0; i> *num1; cout clanq version 7.0.0-3-ubuntu0.18.04.1 (taqs/RELEASE 700/fina Large Integer 1: 957994954495949457454 Large Integer 2: 774874754744875847484 957994954495949457454+ 774874754744875847484 1732869709240825304938 Large Integer 1: 804885080443358 Large Integer 2: 4849850549686868696 804885080443358+ 4849850549686868696 4850655434767312054 Large Integer 1: 99999999 99999999+ output - Notepad File Edit Fomat View Help Large Integer 1: 957994954495949457454 Large Integer 2: 114814/54/448/584/484 957994954495949457454 + 774874754744875847484 1732869789240825304938 Large Integer 1: 80485080443358 Large Integer 2: 4349358549686368696 80185080143358 4849850549686868696 4849931034/67312054 Large Ineger 1: 99999999 Large Integer 2: 9999999999 Large Integer 1: 5555555555 Large Integer 2: 44444444444444444465 Windows (CRLF rn 1, Col1 100% 7:38 PM 12/03/2019

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_2

Step: 3

blur-text-image_3

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Question How is life insurance used in a DBO plan?

Answered: 1 week ago