Create a program that should read in character from the file

Assignment Help Data Structure & Algorithms
Reference no: EM131119687

charStack

Given a text file, your program will determine if all the parentheses, curly braces, and square brackets match, and are nested appropriately. Your program should work for mathematical formulas and most computer programs.

Your program should read in the characters from the file, but ignore all characters except for the following: { } ( ) [ ]

The general algorithm is to use a stack to store the opening unmatched brackets. When a closing bracket is encountered, check it against the one on top of the stack (pop it off)--make sure it matches. When you are finished there should be no unmatched brackets left on the stack.

Your program should first implement a char stack. CharStack.h is provided on the website. You must supply the CharStack.cpp file that includes the implementations of the functions in the class declaration. Note that the stack elements will be stored in a string, and no variable named top is necessary. You can complete this assignment using these string functions: at(int), size(), append() or +=, and substr(int, int). Note: Do NOT use these functions: push_back, pop_back, or back.

Input/Output:

Your Driver program must prompt the user to enter a filename. It should then try to open the file and then check it make sure the brackets all match appropriately. If they all match, the program should output a message saying so. If not, the program should output an appropriate error message.

There are three types of errors that can happen (and they can happen with any kind of bracket):

missing } : if you reach the end of the file, and there is an opening { that was never matched, like: int main () { x[size]=10;

expected } but found ) : this is a wrong closing bracket, like: {x[i]=10;)... unmatched } : this occurs if there is a closing bracket but not an opening bracket

(not even one of the wrong kind), like: int main () { x[i]=10; } }...

Reference no: EM131119687

Questions Cloud

What problems may be indicated by an average collection : What problems may be indicated by an average collection period that is substantially above or below the industry average?
What are the ethical arguments : What are the ethical arguments for or against private corrections?
How has the history of healthcare compliance changed : How has the history of healthcare compliance changed since its inception? Hint: Look at the ways in which penalties have increased in various ways. What do you think will be the key to getting control of the issue of fraud and abuse in the future
The initial down payment has not been earned and collection : What entry would be made by Campbell on January 1, 2010, if the down payment is refundable and substantial future services remain to be performed by Campbell?
Create a program that should read in character from the file : Your program should read in the characters from the file, but ignore all characters except for the following: { } ( ) [ ]. The general algorithm is to use a stack to store the opening unmatched brackets.
What is the major limitation of the current ratio : What is the major limitation of the current ratio as a measure of a firm’s liquidity? How may this limitation be overcome?
How does the correctional subculture differ : How does the correctional subculture differ from the police subculture in regards to corrupt practices? How are they similar?
What is project crashing : What is "project crashing"? When might it be appropriate to utilize project crashing? What are the potential downfalls of project crashing
What are the primary limitations of ratio analysis : What are the primary limitations of ratio analysis as a technique of financial statement analysis?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  An infix expression is one in which operators are located

an infix expression is one in which operators are located between their operands. this is how we are accustomed to

  Write algorithm that describes how program is going to work

Prior to commencing coding, you need to plan what you're going to code. Write an algorithm that describes how your program is going to work and how it links together.

  Determine schedule that obtains maximum amount of profit

Assume you have one machine and a set of n jobs a1, a2, ..., an to process on that machine. Determine the schedule that obtains the maximum amount of profit. Compute the running time of your algorithm?

  Design binary tree in ascii mode

Design the binary tree that the following allocations create. List the nodes in the order of their visit for an NLR scan.

  What steps should you take when designing an adt

What steps should you take when designing an ADT? The following function computes the sum of the first n ≥ 1 integers. Show how this function satisfies the properties of a recursive function.

  Diferentiate losles and losy algorithms

Write briefly about he Computer System Components. Diferentiate losles and losy algorithms

  How much time will it take to sort the array

If an arbitrary item is added to the end of an already sorted list, how much time will it take to sort the array again using insertion sort?

  Plot the time complexity according to theoretical bounds.

Be sure to only include the time needed for sorted, excluding the time to generate the random numbers. Plot the results (input size, running time) for BubbleSort and MergeSort.

  Write an algorithm that gets as input three data values

Write an algorithm that gets as input three data valuesx,y, andz and outputs the average of these values if the value ofx is positive.

  Create an array dynamically

Write a program to accept a number representing how many first names the user will enter from the command line (5 names maximum), and the actual first names, from the command line.

  What data structure did you choose

what data structure did you choose (from lists, stacks, queues or trees) and why, and briefly explain why you did not choose the others.

  Discuss deleting items from binary search trees

If the item to be deleted is contained in a node with one child, the reference in the parent node is set to reference the child node and the node containing the data item is deleted. This causes the child node to take the place of the deleted node..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd