Output Question

This is a discussion on Output Question within the C++ Programming forums, part of the General Programming Boards category; How can I get my output that is this Symbol 1 / does match Symbol 2 * Symbol 1 * ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Output Question

    How can I get my output that is this
    Symbol 1 / does match Symbol 2 *
    Symbol 1 * does match Symbol 2 /
    Symbol 1 ( does match Symbol 2 )
    Symbol 1 [ does match Symbol 2 ]
    Symbol 1 ( does match Symbol 2 )
    End of program reached when unmatched symbol
    Symbol 1 ( does match Symbol 2 ]
    )
    (
    ]
    [
    )
    (
    /
    *
    *
    /
    All Symbols correctly balanced

    to look like this

    Symbol 1 / *does match Symbol 2 */
    Symbol 1 ( does match Symbol 2 )
    Symbol 1 [ does match Symbol 2 ]
    Symbol 1 ( does match Symbol 2 )
    End of program reached when unmatched symbol
    Symbol 1 ( does match Symbol 2 ]
    )
    (
    ]
    [
    )
    (
    /
    *
    *
    /
    All Symbols correctly balanced



    code:--------------------------------------------------------------------------------
    Code:
    #include<iostream>
    #include<fstream>
    #include<iomanip> 
    #include<cstdlib> 
    #include<string>
    #include"stackLL.h"
    #include"StackLLImple.cpp"
    
    using namespace std;
    
    int main()
    {
        char answer;
    	char InputChar1, InputChar2;
        int Number=0;
    	char num;
        int success=0;
    	//string InputChar1;
    	//string InputChar2;
    
    	character link;
    	int i=0;
    	ifstream InFile;
    	ofstream OutFile;
    
    	InFile.open("input1.txt");
        OutFile.open("output2.txt");
    
        OutFile << "This is the the linked list function" << endl;
        OutFile<< "\n \n";
    
    	InFile>>InputChar1;
    	i++;
    	InFile>>InputChar2;
    	i++;
    	while(InFile != NULL)
    	{
    
    
    	if((InputChar1 == '[') && (InputChar2 == ']') || (InputChar1 == ']') && (InputChar2 == '['))
    	{
    		 link.push(InputChar1);
    		 link.push(InputChar2);
    		 Number = 1;
    		 
    	}	 
    	else if((InputChar1 == '(') && (InputChar2 == ')') || (InputChar1 == ')') && (InputChar2 == '('))
    	{
    		 link.push(InputChar1);
    		 link.push(InputChar2);
    		 Number = 1;
    	}
    		else if((InputChar1 == '/') && (InputChar2 == '*') || (InputChar1 == '*') && (InputChar2 == '/'))
    	{
    			link.push(InputChar1);
    			link.push(InputChar2);
    			Number = 1;
    	}
    else
    Number = 2;
    	
    	
    	switch (Number)
    	{
     case 1: OutFile<<"Symbol 1 "<<InputChar1<<" does match Symbol 2 "<<InputChar2<<endl;
    		Number =0;
    		break;
    	case 2 :OutFile<<" End of program reached when unmatched symbol"<<endl;
    		OutFile<<"Symbol 1 "<<InputChar1<<" does match Symbol 2 "<<InputChar2<<endl;
    while(i >2)
    {
    	OutFile<<link.pop(InputChar1)<<endl;
    	i--;
    	OutFile<<link.pop(InputChar2)<<endl;
    	i--;
    	
    }
    	Number = 3;
    	case 3 :OutFile<<"All Symbols correctly balanced"<<endl;
    	
    	default: ;
    	}
    	
    	
    	InFile>>InputChar1;
    	i++;
    	InFile>>InputChar2;
    	i++;
    	}
    	return 0;
    }
    	
    #include<iostream>
    
    //#include"stackLL.h"
    
    using namespace std;
    //constructor
    character::character()
    {
        head=NULL;
        cur=NULL;
        pre=NULL;
    }
    
    //destructor
    character::~character()
    {
        node *ptr;
    
        while(head!=NULL)     //delete all the numbers
        {
            ptr=head->next;
            delete head;
            head=ptr;
        }
    }
    
    char character:ush(char num)
    {
    
     node *temp = new node;
        temp->num = num;
        temp->next = head;     // if head was NULL, next will now be NULL (end of list)
        head = temp;
    return num;
    }
    
    
    //****remove at the head, this is stack, push at the head remove at the head.
    char character:op(char num)
    {
        //int num;
        node *temp = head;
    
        if (temp == NULL) return -1;
    
        num = temp->num;
        head = temp->next;
        delete temp;
    
        return num;
    
    
        //return success;
    }
    
    
    //this function will print from the beginning of the list to the end of the list
    void character:rint()
    {
        //if the list was empty print out an error message
        if(head==NULL)
        {
            cout << "There isn't any number" << endl;
            return;
        }
    
        //else while not the end of the list, print out the number and go to the next one
        else
        {
            cur=head;
            while(cur!=NULL)
            {
                cout << "number: " << cur->num << endl;
                cur=cur->next;
            }
        }
    }
    
    
    //the search function was search from the beginning of the head to the end of the
    //head.
    bool character::Isempty() const
    {
    	return (head == NULL);
    }
    
    int character::search(int num)
    {
    
        if(head==NULL)     //if there isn't any data return 0
        {
            
            return 0;
        }
    
        if(head->num == num)        //if delete the first node
        {
            cout << num << " was found" << endl;
            
            return 1;
        }
        else        //else delete any node other than the first node
        {
            cur=head;
            cur=cur->next;
    
    
            while(cur!=NULL)    //search all the to the end of the list
            {
    
                if(cur->num ==num)
                {
                    cout << num << " was found" << endl;
                    
    
                    return 1;
                }
                pre=cur;
                cur=cur->next;
                
            }// while
        } //else
    return 0;
    }
    #include<iostream>
    struct node
    {
        char num;
        node *next;
    };
    
    class character
    {
        public:
            character();
            ~character();
    
            char push(char num);
            char pop(char num);
            void print();
            int search(int num);
    		bool Isempty() const;
    
        private:
            node *head;
            node *cur;
            node *pre;
    };

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    How can I get my output that is this
    Symbol 1 / does match Symbol 2 *
    Symbol 1 * does match Symbol 2 /
    Symbol 1 ( does match Symbol 2 )
    Symbol 1 [ does match Symbol 2 ]
    Symbol 1 ( does match Symbol 2 )
    End of program reached when unmatched symbol
    Symbol 1 ( does match Symbol 2 ]
    )
    (
    ]
    [
    )
    (
    /
    *
    *
    /
    All Symbols correctly balanced

    to look like this

    Symbol 1 / *does match Symbol 2 */
    Symbol 1 ( does match Symbol 2 )
    Symbol 1 [ does match Symbol 2 ]
    Symbol 1 ( does match Symbol 2 )
    End of program reached when unmatched symbol
    Symbol 1 ( does match Symbol 2 ]
    )
    (
    ]
    [
    )
    (
    /
    *
    *
    /
    All Symbols correctly balanced
    I would try to help, but that makes precisely no sense to me. Can you try to explain it better, and maybe edit the code to only include what you feel is suspect?
    Away.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    the code that I think is suspect

    Code:
    switch (Number)
    	{
     case 1: OutFile<<"Symbol 1 "<<InputChar1<<" does match Symbol 2 "<<InputChar2<<endl;
    		Number =0;
    		break;
    	case 2 :OutFile<<" End of program reached when unmatched symbol"<<endl;
    		OutFile<<"Symbol 1 "<<InputChar1<<" does match Symbol 2 "<<InputChar2<<endl;
    while(i >2)
    {
    	OutFile<<link.pop(InputChar1)<<endl;
    	i--;
    	OutFile<<link.pop(InputChar2)<<endl;
    	i--;
    	
    }
    	Number = 3;
    	case 3 :OutFile<<"All Symbols correctly balanced"<<endl;
    	
    	default: ;
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question: Output of data.txt from the following program
    By outlaw525 in forum C Programming
    Replies: 9
    Last Post: 06-23-2008, 03:33 PM
  2. strange virtual function output
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2008, 07:08 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  4. a question about file output
    By wang8442 in forum C Programming
    Replies: 3
    Last Post: 12-26-2004, 02:18 AM
  5. a newbie question about file output
    By maybe in forum C Programming
    Replies: 8
    Last Post: 10-12-2004, 08:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21