Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WITHOUT the use of #include : Change the following code to format the console output as: instead of: as well as output it in the

WITHOUT the use of #include :

Change the following code to format the console output as:

image text in transcribed

instead of:

image text in transcribed

as well as output it in the same format (as shown in the first picture) to a file called 'output.txt'

This is the code:

#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); cout

}

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; string num1, num2; int j; fin.open("input.txt"); fout.open("output.txt");

while(true){ Node* int1 = NULL; Node* int2 = NULL; fin>>num1; if(num1=="-1"){ break; } cout

for(unsigned int i=0; i { j= num1[i] - '0'; AddHead(int1,j); }

cout>num2; cout

cout

}

return 0;

}

Large Integer 1: 957994954495949457454 Large Integer 2: 774874754744875847484 957994954495949457454 + 774874754744875847484 1732869709240825304938 Large Integer 1: 80485080443358 Large Integer 2: 4849850549686868696 80485080443358+ 4849850549686868696 4849931034767312054 Large Integer 1: 99999999 99999999+ Large Integer 1: 957994954495949457454 Large Integer 2: 774874754744875847484 + 1732869709240825304938 Large Integer 1: 80485080443358 Large Integer 2: 4849850549686868696 + 4849931034767312054 Large Integer 1: 99999999 Large Integer 2: 9999999999 -+ Large Integer 1: 5555555555 Large Integer 2: 44444444444444444465 +

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

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans and nature?

Answered: 1 week ago