1. Homepage
  2. Programming
  3. COMP 322 Introduction to C++ - Assignment 2: Exploring Dynamic Memory Management

COMP 322 Introduction to C++ - Assignment 2: Exploring Dynamic Memory Management

Engage in a Conversation
CanadaMcGill UniversityCOMP 322COMP322Introduction to C++Exploring Dynamic Memory ManagementC++git322

Assignment 2: Exploring Dynamic Memory Management CourseNana.COM

●  Research for similar problems is tolerated. However, your submission should reflect individual work and personal effort. CourseNana.COM

●  Some of the topics may not be covered in class due to our limited time. You are encouraged to find answers online. You can also reach out to the TAs for guidance. CourseNana.COM

●  Please submit your assignment before the due date to avoid penalties or worse risking your assignment being rejected. CourseNana.COM

●  Submit one file called assignment2.cpp containing all the functions together with their implementations. It will also contain the main() function that runs everything. CourseNana.COM

Make sure your code is clear and readable. Readability of your code as well as the quality of your comments will be graded. CourseNana.COM

●  No submission by email. Submit your work to mycourse. CourseNana.COM

●  If your code does not compile it will not be graded. CourseNana.COM

●  Be happy when working on your assignment, because a happy software developer has more inspiration than a sad one :). CourseNana.COM

We saw in assignment 1 some ways of creating a diff tool to check whether 2 files have the same content. In this assignment we will push the development a bit further in order to create a git-like system. CourseNana.COM

Git is a code versioning system that keeps track of all previous states of a file. When a file gets modified git will keep both versions of the file, the old one and the new modified one. Git will offer you some utilities to retrieve previous versions of the same file and to compare them with newer versions. CourseNana.COM

We will be using dynamic memory management in order to implement our Comp322 version of git. Let’s call our program git322. CourseNana.COM

git322 will track one file and will keep all versions of this file in memory. The user decides when to take a snapshot of his/her modification. The user should be able to load a specific version to make it the current version or can also decide to delete any version of the file. Here are the allowed operations while running git322 program: CourseNana.COM

  1. Adding a version of the file when the user finds suitable
  2. Removing a version (any version that was being tracked)
  3. Loading a specific version and making it the current active one
  4. Printing to the screen the list of all versions of the file
  5. Comparing any 2 versions of the file
  6. Searching and displaying all the versions having a specific keyword
  7. Exiting the program

git322 has to keep all versions of the file in memory in a linked list using dynamic memory allocation. Every element in the list holds information about one version of the file. CourseNana.COM

The following example shows the interaction between the user and git322 when you execute your program: CourseNana.COM

 Welcome to the Comp322 file versioning system! CourseNana.COM

To add the content of your file to version control press 'a' To remove a version press 'r' CourseNana.COM

By pressing ‘a’ the following output should be displayed to the screen: CourseNana.COM

Your content has been added successfully. CourseNana.COM

Which means that your code has to verify first whether the file has changed before attempting to add a new unnecessary version. CourseNana.COM

The logic of adding the content of the file to the tracking system should reside in a function called add and having the following signature: CourseNana.COM

void add(string content); CourseNana.COM

Now let’s print all the available versions (we only have one so far) to the screen. This function is handy for debugging. From the menu press ‘p’. This should print the following to the screen: CourseNana.COM

 Number of versions: 1 CourseNana.COM

 Version number: 1 CourseNana.COM

Hash value: 35345342435 Content: Dear Comp 322 students. CourseNana.COM

The logic of printing should reside in a function called print and having the following signature: CourseNana.COM

void print(void); CourseNana.COM

Now let’s modify the file by adding a line to it, so go to your text editor and add the following to your file:
Dear Comp 322 students. C++ is a complicated language. CourseNana.COM

Your content has been added successfully. CourseNana.COM

Now let’s verify by printing. Choose ‘p’, the following should be printed out to the screen: CourseNana.COM

Number of versions: 2
Version number:
1
Hash value: 35345342435 Content: Dear Comp 322 students. CourseNana.COM

If the user wants to work on the first version of the file, he/she has to load it to his/her editor first. This is what option ‘l’ is for. Go back to your command prompt where your program is still running and press ‘l’. The following should be printed to the screen: CourseNana.COM

 Which version would you like to load? CourseNana.COM

Verify that your text editor is indeed reflecting the newly loaded version. This is what you are supposed to have in your text editor now (you may need to refresh or to close and reopen the file):
Dear Comp 322 students. CourseNana.COM

The logic of loading the content of a revision into the file should reside in a function called load and having the following signature: CourseNana.COM

void load(int version); CourseNana.COM

Let’s now add a new line to the file so that the text in the editor will look like this: CourseNana.COM

Dear Comp 322 students.
Coding in C++ is like going to the gym: No pain no gain!
CourseNana.COM

Press ‘a’ in the command prompt of your program to add this 3rd version and then press ‘p’ to check the result. If all is good you must see the following as as result of ‘p’ command: CourseNana.COM

Number of versions: 3
Version number:
1
Please enter the number of the first version to compare: CourseNana.COM

The user inputs 1. The following will be printed to the screen: CourseNana.COM

 Please enter the number of the second version to compare: CourseNana.COM

The user inputs 2.
The following result will be printed to the screen:
CourseNana.COM

Line 1: Dear Comp 322 students. <<>> Dear Comp 322 students. C++ is a complicated language. CourseNana.COM

Please enter the number of the second version to compare: CourseNana.COM

The logic of comparing the content of 2 versions should reside in a function called compare and having the following signature: CourseNana.COM

void compare(int version1, int version2); CourseNana.COM

Now let’s search for the version of the file containing the word “gym”. Press ‘s’ in the command prompt where your program is still hopefully running. The following should be printed to the screen: CourseNana.COM

 Please enter the keyword that you are looking for: CourseNana.COM

The user types: gym
The program should output the following:
CourseNana.COM

The keyword 'gym' has been found in the following versions: Version number: 3
Hash value: 88345342411
Content: Dear Comp 322 students. CourseNana.COM

Your keyword 'keyword' was not found in any version. CourseNana.COM

The logic of searching the tracking system should reside in a function called search and having the following signature: CourseNana.COM

void search(string keyword); CourseNana.COM

Finally we want now to be able to remove (delete) a version from the tracking history. Input ‘r’ in the command prompt of your running program. The following should be displayed to the screen: CourseNana.COM

 Enter the number of the version that you want to delete: CourseNana.COM

void remove(int version); CourseNana.COM

Press ‘p’ to verify that version 2 is no more available. The following should appear on the CourseNana.COM

screen: CourseNana.COM

Version number: 3
Hash value: 88345342411
Content: Dear Comp 322 students.
Coding in C++ is like going to the gym: No pain no gain!
CourseNana.COM

You will need to declare a pointer to your linked list as a global variable to be able to access it from within your functions. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Canada代写,McGill University代写,COMP 322代写,COMP322代写,Introduction to C++代写,Exploring Dynamic Memory Management代写,C++代写,git322代写,Canada代编,McGill University代编,COMP 322代编,COMP322代编,Introduction to C++代编,Exploring Dynamic Memory Management代编,C++代编,git322代编,Canada代考,McGill University代考,COMP 322代考,COMP322代考,Introduction to C++代考,Exploring Dynamic Memory Management代考,C++代考,git322代考,Canadahelp,McGill Universityhelp,COMP 322help,COMP322help,Introduction to C++help,Exploring Dynamic Memory Managementhelp,C++help,git322help,Canada作业代写,McGill University作业代写,COMP 322作业代写,COMP322作业代写,Introduction to C++作业代写,Exploring Dynamic Memory Management作业代写,C++作业代写,git322作业代写,Canada编程代写,McGill University编程代写,COMP 322编程代写,COMP322编程代写,Introduction to C++编程代写,Exploring Dynamic Memory Management编程代写,C++编程代写,git322编程代写,Canadaprogramming help,McGill Universityprogramming help,COMP 322programming help,COMP322programming help,Introduction to C++programming help,Exploring Dynamic Memory Managementprogramming help,C++programming help,git322programming help,Canadaassignment help,McGill Universityassignment help,COMP 322assignment help,COMP322assignment help,Introduction to C++assignment help,Exploring Dynamic Memory Managementassignment help,C++assignment help,git322assignment help,Canadasolution,McGill Universitysolution,COMP 322solution,COMP322solution,Introduction to C++solution,Exploring Dynamic Memory Managementsolution,C++solution,git322solution,