Homework Assignment 4 Solved

$30.00 $24.00

Problem 1: A string may use more than one type of delimiter to bracket information into “blocks”. For example, a string may use braces {}, parentheses (), and brackets [] as delimiters. A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type. Delimiters are not…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Problem 1:

A string may use more than one type of delimiter to bracket information into “blocks”. For example, a string may use braces {}, parentheses (), and brackets [] as delimiters. A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type.

Delimiters are not balanced when there is an extra closing delimiter, a missing closing delimiter, or a mismatch between the open and closed delimiter.

Write a function ProperlyBalanced that uses a stack to check if a string contains properly balanced delimiters. This function returns true if a string containing braces, parentheses, and brackets is properly delimited. Otherwise, it displays a message stating why the string is not properly balanced (extra closing delimiter, a missing closing delimiter, delimiter mismatch) and returns false.

Then write a main program to test your function. Your main program should have a loop that asks the user to enter a string and calls the function ProperlyBalanced to check if the string entered has balanced delimiters. The loop should repeat until the user enters a sentinel value. You may test your function by having the user enter the following strings:

• While(a==b){a++;

• [A*(B+2)-{(3/C+(E-F))+[(E*3)-4]}]

• if(a<(b*c)))

• {3+4+5+6-7]

• [A*(E+2)-((G*3+(E-B))+[(E*3)-4]}]

• A+B+C

• (a+b+c*(d-2]))

• [e-f)

• [[()()])

Note: if the delimiters are not balanced, don’t forget to display the reason

Problem 2:

Write a C++ program that uses a queue to generate all 1-character, 2-character, and 3-character strings that can be formed using the letters A, B, and C. The strings can have repeated letters and must be generated in the following order:

A

B
C
AA
AB
AC
BA
BB

BC
CA
CB
CC
AAA

AAB
AAC
ABA
ABB

ABC

Extra credit:

Stacks and queues are useful in a wide range of applications. Research other applications and explain how stacks and/or queues are used to solve such problems.

Once done, you need to submit the following:

1. A folder containing the following:

◦ Printed copies of the source codes of problems 1 and 2 (.h and .cpp files)

◦ Printed output run for each program (program1Run, program2Run). Use the script command to record your output runs. Start recording before compiling your code. In other words, script results of compiling and executing your programs should include

the lines for compiling your files even if the program does not compile.

You should hand in the folder during the first 5 minutes of the class when the homework is due.

You lose 10% of the grade if you do not provide a complete folder.

2. An electronic copy of your source codes. You should place all source codes in a zipped folder and name it based on your first/last name and the assignment number. For example, JoeSmith-A1.zip. You should submit the zipped folder online through cougar website.

Homework Assignment 4 Solved
$30.00 $24.00