Question
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:
instead of:
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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started