Starting from:

$29.99

CS204 Take Home Exam 3 – Common Tokens Solution

DISCLAIMER:
Introduction
The aim of this Take-Home Exam (THE) is to practice on stack structures and templated classes. In this THE, you will implement a program for finding the common tokens in two given files. It might seem like a trivial CS201 task at first, but you must do this by using dynamic stacks and in a templated class fashion.
Backstory
Input to Your Program
Your program will take three (3) inputs from the console. Firstly, the user will enter the name of the first file, and then (s)he will enter the name of the second file. Then, the user will enter either the number ‘1’ or the number ‘2’ as an indicator for a task that will be explained later in this document. The content to be compared against will be inside the provided two files.
Format of the Inputs
As mentioned above, the user will enter 3 inputs: 2 file names and a numeric value. For the file names, if the file, for which the name is entered, does not exist in the same project directory as of the program, your program should then output a predefined message and terminate. Similar approach should be taken for the third input (‘1’ or ‘2’) as well; if anything other than the digits ‘1’ or ‘2’ is entered, your program should then output a predefined message and terminate. For the details, and the exact predefined messages, please refer to the sample runs.
As the user enters the correct file names (for both of the files), and the correct option (either ‘1’ or ‘2’), your program should start parsing the information out of these given files.
In this assignment, there will be three different categories of text files in terms of the type of information stored. One of the given files will contain only integers, another one of files will contain only words (i.e., strings), and the one will contain only characters. However, your program should work as generic as possible to cover any type (built-in or class) that might be used as the content to be compared.
A convention that will be followed throughout the document and the sample runs is that the files containing only integers will have a name that starts with the lowercase letter ‘i’, the files containing only words (strings) will have a name that starts with the lowercase letter ‘s’, and the files containing only special symbols (characters) will have a name that starts with the lowercase letter ‘c’.
Example:
● sFile1.txt → contains words (string datatype)
● iFile1.txt → contains integers (int datatype)
● cFile1.txt → contains individual characters (e.g. special symbols) (char datatype)
Notes:
In any valid single run for your program:
● The input files will be of the same type, i.e. there will not be a case where the name of the first file is cFile1.txt, for example, and the name of the second file is sFile2.txt. In other words, the content types of the given files will match one another. You can safely assume that this is the case for all test cases (sample runs) that we will use to test your program, and you don’t have to check for that.
● The input files will be different; i.e., we are not going to test your program against a case where the two input files are the same as one another, such as (iFile1.txt and iFile1.txt). So, you might safely assume that the two input files are different, and you don’t need to check for that.
Option ‘1’ or ‘2’
Lastly, regarding the third input to your program, the option “1” or “2”: this input is responsible for determining the order of displaying the output later in the program.
Option “1” means that the common token will be displayed in the order that they appear in the first file, whereas option “2” means that they will be displayed in the order that they appear in the second file. If the option is invalid, your program should then print a predefined message and terminate. Details of these operations can be inspected in the Sample Runs section.
Data Structure to be Used and Details of Implementation
You must use dynamic stacks for this assignment. Indeed, you are not allowed to use any other aggregate data type other than dynamic stacks (array, vector, queue, static stack etc. should not be used anywhere in your code). Moreover, you are not allowed to read the files more than once. You need to think on how to utilize dynamic stacks to store linear information.
We will inspect your codes other than testing them with test cases; so, any attempt of using an alternative data structure or reading the files more than once will be easily spotted and your grade will be set to zero.
Notes:
● A dynamic stack is a stack which is implemented in a dynamic linked list manner with dynamic memory allocation and deallocation operations. For this THE, you are not allowed to implement a static stack which uses arrays or vectors internally.
As you might have guessed by now, your program should work with different types of data, such as strings, integers, and characters. For that reason, your program should implement the dynamic stack class as a templated class. We advise you to revisit the lecture slides and the lab samples to refresh your mind about the implementation details.
You might be wondering about the Fundamental Dilemma in using Templated Classes that we studied in the class, and how you are going to solve it, or more specifically, which of the solutions that we learned in the class you are going to implement. For the purpose of the task in hand, while developing the solution for this THE, you should use the solution # 3 that is mentioned in the “5-templated” lecture slides. The choice here is just to allow easy and smooth submission for your THE. Please refer to the section What and where to submit... for more important details.
Finally, as usual, you must implement a destructor for the dynamic stack class such that it will deallocate the dynamically created memory for the dynamic stack objects. And also, you must implement a copy constructor and/or assignment overloading, if your program requires deep copy operations.
Details of the Tasks and Outputs of Your Program
Attached files
Also, some sample input text files are provided. Note the naming convention as mentioned earlier. You can safely assume that is the case for all other unshared input files that we will use later to test your code. So, you don’t need to check for that.
Sample Runs
Below, we provide some sample runs of the program that you will develop (more are shown on the submission page at the examples section). You have to display the required information in the same order and with the same presentation (format) as here. You should not print any extra messages other than the ones that you see in the sample runs, such as “Hello…” or “please enter the file name:”, etc.
In all sample runs, the output should start with :
TOKEN --> MINIMUM OCCURRENCE COUNT
----------
The word “TOKEN” in upper case followed by a whitespace and then two dashes (hyphens) and then an angle bracket, then another whitespace and the words MINIMUM OCCURRENCE COUNT. Then, on a new line, your program should display ten (10) dashes (hyphens). After that, your program should print out the rest of the output of your program, if any.
Sample run 1 shows the case when there are no common tokens between the two input files.
CodeRunner first to make sure that you are following the correct output format.
For the cases where there are at least one common tokens, the output convention is as follows: for every token that is common between the two files, you will print it followed by a white space, and then again as was in the very first output line, two hyphens and the angle bracket, then another whitespace then comes the minimum occurrence count of that token in the two files; all of that and on the same line. The order of printing the common token, as explained earlier, is determined by the third input: ‘1’ will show the common tokens in the order they appeared in the first input file, and ‘2’ will show them in the order they appeared in the second input file.
Input Result Explanation
iFile1.txt iFile4.txt
1 TOKEN --> MINIMUM OCCURRENCE COUNT
---------- As there are no common tokens (integers in these example files) in the two given input files, the output is just as shown in the Result column, and as was explained in detail above this table.
iFile3.txt iFile2.txt
1 TOKEN --> MINIMUM OCCURRENCE COUNT
----------
4 --> 1
6 --> 1
3 --> 1 The order of display here is the order of appearance in the first file (i.e., iFile3.txt)
iFile1.txt iFile3.txt
2 TOKEN --> MINIMUM OCCURRENCE COUNT
----------
4 --> 1
5 --> 1
6 --> 1
However, when option 1 was entered by the user, as in the second test case here, the common tokens were displayed in the order they appeared in the first file (i.e.,iFile3.txt).
iFile1.txt iFile3.txt
1 TOKEN --> MINIMUM OCCURRENCE COUNT
----------
10 --> 1
6 --> 1
5 --> 1
4 --> 1

cFile1.txt cFile3.txt
2 TOKEN --> MINIMUM OCCURRENCE COUNT
----------
; --> 1
* --> 1
! --> 1
% --> 1
# --> 3
cFile1.txt cFile3.txt
1 TOKEN --> MINIMUM OCCURRENCE COUNT
----------
; --> 1
* --> 1
# --> 3
! --> 1
% --> 1
sFile3.txt sFile4.txt
1 TOKEN --> MINIMUM OCCURRENCE COUNT ---------delete --> 2 break --> 8 sum --> 2 long --> 2 string --> 1 goto --> 2 cast --> 3 unsigned --> 1 void --> 4 friend --> 1 xyz --> 2 typedef --> 1 extern --> 9 firstvar --> 2 case --> 5 template --> 4 signed --> 1 if --> 2 myvar --> 2 return --> 2 enum --> 3 else --> 1 double --> 3 char --> 1 float --> 1 private --> 4 this --> 1 new --> 1 nullptr --> 1 class --> 4 static --> 1 operator --> 1
age --> 1 try --> 1 int --> 1 union --> 1 struct --> 4 diagonal --> 2 default --> 1 start --> 3 protected --> 1 volatile --> 2 public --> 1 sizeof --> 2 const --> 1 register --> 1 for --> 1
cFile1.txt cFile3.txt
3 Invalid choice. The third input is the digit 3 which is invalid choice, that is why you see the output is:
Invalid choice.
cFile1.txt File3.txt
3 File not found. There is no file with the name File3.txt. Therefore, the expected output in that case, as shown is:
File not found.
What and where to submit (MUST READ, VERY IMPORTANT)
It would be a good idea to write your name and last name in the program (as a comment line of course). Do not use any Turkish characters anywhere in your code (not even in comment parts). If your full name is "Duygu Karaoğlan Altop", and if you want to write it as comment; then you must type it as follows:
// Duygu Karaoglan Altop
You should copy the full content of your main.cpp file and paste it into the specified “Answer” area in the relevant assignment submission page on SUCourse. Then, you should attach two files to the specified attachment section right below the “Answer” section. The first file is for the class definition (you must name that file "DynTemplatedStack.h"), and the other file for that class implementation (you must name that file "DynTemplatedStack.cpp"). Of course, and as mentioned earlier, those files that you will upload should be the “updated” version of the files that we provided with this THE bundle. By “updated” we mean, the ones that you changed parts of them to satisfy this THE requirement and, at the same time, templated of course.
When you copy and paste the main.cpp file content and upload the "DynTemplatedStack.h" and "DynTemplatedStack.cpp" file to the corresponding attachment section, then you will be able to compile and run the program and check its output against all the test cases by clicking on the “Check” button.
● Please make sure that you are submitting the latest version of your THE codes.
● Make sure you upload your class header and cpp files to the attachment section on the submission page on SUCourse as well with the specified names mentioned above
"DynTemplatedStack.h" and "DynTemplatedStack.cpp"
● Do not zip any of the files but upload them as separate files only.
Some Important Rules
Although some of the information is given below, please also read the homework submission and grading policies from the lecture notes of the first week. In order to get a full credit, your program must be efficient, modular (with the use of functions), well commented and indented. Besides, you also have to use understandable identifier names. Presence of any redundant computation, bad indentation, meaningless identifiers, function names, or missing/irrelevant comments will decrease your grade in case that we detect them.
Submit via SUCourse ONLY! Paper, e-mail or any other methods are not acceptable.
The internal clock of SUCourse might be a couple of minutes skewed, so make sure you do not leave the submission to the last minute. In the case of failing to submit your THE on time: "No successful submission on SUCourse on time = A grade of zero (0) directly."
Since the first grading phase will be automatic, you are expected to strictly follow these guidelines. If you do not follow these guidelines, your grade will be zero (0). Any tiny change in the output format will result in your grade being zero (0), so please test your programs yourself, and against the sample runs that are available at the relevant assignment submission page on SUCourse.
How to get help?
Good Luck!
Ahmed Salem, Duygu K. Altop

More products