Write a program using text file I/O to open any file and print out all of the in
ID: 3638589 • Letter: W
Question
Write a program using text file I/O to open any file and print out all of the integers in the file, and their sum. You should input one character at a time, and convert contiguous characters into integers.
The code must be completed how i asked to get full points. The code must include a comment for each method describing the method, a comment for each parameter describing what the parameter represents, and a comment for each variable declaration (including instance variables) describing what the variable represents.
Explanation / Answer
#include #include #include #include struct node { char data; node *next; }; node *T=NULL; node *B=NULL; node *E; node *L; node *SL; void push(char); const char pop( ); void infix_to_postfix(char *Infix); int main( ) { clrscr( ); char Infix[50]={NULL}; coutInfix; infix_to_postfix(Infix); getch( ); return 5; } void push(char Operator) { E=new node; if(B==NULL) { E->data=Operator; E->next=NULL; B=E; T=E; } if(B!=NULL) { E->data=Operator; E->next=NULL; T->next=E; T=E; } } const char pop( ) { char Operator=NULL; if(B==NULL) coutnext=NULL; } return Operator; } void infix_to_postfix(char *Infix) { char Postfix[50]={NULL}; strcpy(Infix,"("); strcat(Infix,Infix); strcat(Infix,")"); char Operator[5]={NULL}; char Temp[5]={NULL}; int count=0; do { Operator[0]=Infix[count]; if(Operator[0]=='(') push(Operator[0]); else if(Operator[0]==')') { Operator[0]=pop( ); while(Operator[0]!='(') { strcat(Postfix,Operator); Operator[0]=pop( ); } } else if(Operator[0]=='^' || Operator[0]=='*' || Operator[0]=='/'|| Operator[0]=='+' || Operator[0]=='-') { if(Operator[0]=='*' || Operator[0]=='/') { Temp[0]=pop( ); while(Temp[0]=='^' || Temp[0]=='*' || Temp[0]=='/') { strcat(Postfix,Temp); Temp[0]=pop( ); } push(Temp[0]); } else if(Operator[0]=='+' || Operator[0]=='-') { Temp[0]=pop( ); while(Temp[0]!='(') { strcat(Postfix,Temp); Temp[0]=pop( ); } push(Temp[0]); } push(Operator[0]); } else strcat(Postfix,Operator); count++; }while(countRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.