Please help me!!!
How can I do the below ex. , please help me!!!

Description:
In this assignment you will implement the ADT Stack. You
will be using stacks in order to count the pairs of three types
of brackets: {}, [], and (). The input will consist of an input
stream of characters, text and numerics. The input will have
embedded brackets occuring in pairs. For example:
Main(int argc, char** argv) { int A[100]; double B[50]; }
Your program should run with this input stream, for example:
$ ../bin/main < ../dat/input.dat
The output should be:
$ Number of () pairs = 1
$ Number of [] pairs = 2
$ Number of {} pairs = 1

Example of an input stream:
(((123)[1]{1(2345)}))
The following should result in an
error:
((…{...1234 })}}
Any crossing pair match should
also trigger an error.


Thank you all of you!!

I have just write out somrrthing like this

int main() {
stack<char> allwords;
char word;
while (cin >> word) {
if (word == '(')
{allwords.push(word);}
else
if (word == ')')
{allwords.pop();}
}

if (allwords.size() == 0)
{cout << "The stack is %d. It is balance!" << allwords.size() << endl;}
else
{cout << "Number of words = " << allwords.size() << endl;}

return 0;
}

So how can I count number of those braces??

Can you help me??

I have just write out somrrthing like this

int main() {
stack<char> allwords;
char word;
while (cin >> word) {
if (word == '(')
{allwords.push(word);}
else 
if (word == ')') 
{allwords.pop();}
}
 
if (allwords.size() == 0)
{cout << "The stack is %d. It is balance!" << allwords.size() << endl;}
else
{cout << "Number of words = " << allwords.size() << endl;}
 
return 0;

So how can I count number of those braces??

Can you help me??

Please use the bultin tags around your code. I changed it above for you but try to remember to use them. Anyway I've done a similar project where I had to read in an HTML document and determine how many tags and their corresponding closing tag, discarding any tags that don't need closing tags as defined in my project. With yours you might use a ratio for each opening and closing tags and determine it that way. In otherwords, if you have 25 opening braces and 25 closing braces their ratio would be 25/25, which is 1 and means that there are 25 pairs of braces. If their different values than I'll leave it up to you to figure out that one ;)

Good luck, LamaBot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.