CSE 2320 - Assignments - Assignment 4

Submit to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.

IMPORTANT: By submitting your answers, you are certifying that these answers have been exclusively your own work. All students enrolled in this course are expected to adhere to the UT Arlington Honor Code:

I pledge, on my honor, to uphold UT Arlington's tradition of academic integrity, a tradition that values hard work and honest effort in the pursuit of academic excellence. I promise that I will submit only work that I personally create or contribute to group collaborations, and I will appropriately reference any work from other sources. I will follow the highest standards of integrity and uphold the spirit of the Honor Code.


Task 1 (40 pts.)

Write a program (in C, C++, Java, or Python) that can evaluate infix expressions under the following assumptions:

If you are using C, C++, or Java, your program should take one command line argument. For example, in C, if your compiled program is called a.out, you should call the program as follows:

a.out filename
Commandline argument filename should be the name of a file containing expressions to be evaluated, such as in1.txt. There should be one expression per line. To help you get started, we provide the following resources:

As an example, if you run your solution using file in1.txt as the input file, you should get the following output:

--------------------------------
processing: (5 * (((9 + 8) *  (4 * 6)) + 7))

infix tokens:
( 5 * ( ( ( 9 + 8 ) * ( 4 * 6 ) ) + 7 ) ) 

postfix tokens:
5 9 8 + 4 6 * * 7 + * 

result: 2075
--------------------------------
processing: 

--------------------------------
processing: ((17 * (12-5)) + (9 / 3))

infix tokens:
( ( 17 * ( 12 - 5 ) ) + ( 9 / 3 ) ) 

postfix tokens:
17 12 5 - * 9 3 / + 

result: 122


Task 2 (10 pts.)

(This is Problem 3.56 from the textbook).

Write a function that takes a string as an argument and prints out a table giving, for each character that occurs in the string, the character and its frequency of occurrence (the number of times that the character occurs).


Task 3 (10 pts.)

(This is Problem 3.57 from the textbook).

Write a function that takes a string as an argument, and that checks whether that string is a palindrome (reads the same backward or forward), ignoring blanks. For example, your program should report success for the string "if i had a hifi".


Task 4 (15 pts.)

(This is Problem 3.60 from the textbook).

Write a function that takes in a string as an argument, and that replaces substrings of more than one blank in a given string by exactly one blank. Note that this function should modify the contents of its input argument, as opposed to returning a new string that has the required modifications.


Task 5 (15 pts.)

(This is Problem 3.74 from the textbook).

Write a function countEdges(int ** adjacencies, int A, int B, int V) that takes as input the adjacency matrix of graph, two integers specifying vertices A and B, and an integer V specifying the number of vertices in the graph. The function should return the number of vertices C with the property that there is an edge from A to C and from C to B. You can assume that the graph is undirected.


Task 6 (10 pts.)

(This is Problem 4.7 from the textbook).

Using the conventions of Textbook Exercise 4.6, give a way to insert asterisks in the sequence E A S Y so that the sequence of values returned by the pop operations is:

Or, where applicable, prove that no such sequence exists.


How to submit

The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment.zip. No other forms of compression are accepted, contact the instructor or TA if you do not know how to produce .zip files. The zipped directory should contain the following documents:

As stated on the course syllabus, programs must be in C or Java, and must run on omega.uta.edu. If you want to do this in any language other than C, you have to re-implement in that language all the code that is currently implemented at lists.c, stacks_lists.c, and tokens.c. If you want to use another language or platform, you must obtain prior approval via e-mail by the instructor.

IMPORTANT: Pay close attention to all specifications on this page, including file names and submission format. Even in cases where your answers are correct, points will be taken off liberally for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions.


Back to the list of assignments.