CS 107 – Introduction To Computing And Programming – Spring ✓ Solved
```html
CS 107 – Introduction to Computing and Programming – Spri
For this assignment, you are to write a program that reads in sentences character-by-character, creates a linked list out of the character stream, and then performs various operations on the resulting list(s).
The linked list node that you create for this assignment shall be named “nodeâ€, and shall have at a minimum the following fields:
struct node {
char c;
int sequence, totalSequence;
struct node * next;
};
Where: The char c is a character read in from the keyboard. Sequence is the original position of this character within the sentence, starting from 1. The first character in the sentence will have sequence 1, the second 2, etc. TotalSequence is the same idea as sequence, but the numbers are since the program started.
Your program should do the following:
- Ask the user to enter a sentence.
- Read the characters one-by-one, until the newline character ( ‘\n’ ) is read in. For each character read in:
- Create a new node, using dynamic allocation ( malloc ), and fill in the node fields.
- Add the node to the beginning of a linked list for this sentence.
- Once the sentence is stored in a linked list, give the user a list of operations supported, and allow them to choose which one(s) to perform.
- Two choices on the list must be to quit the program and to read in the next sentence. In the latter case the current sentence must be either deleted or added to a linked list of past sentences.
- Repeat from step 1 until the user enters "done".
- Print overall summary statistics, such as number of characters and sentences processed.
Required Functions:
- void print( struct node *head );
- void printReversed( struct node *head );
- void delete( struct node *head );
- struct node find( struct node head, char c );
- void removeDuplicates( struct node *head );
- void removeIfEqual( struct node *head, char target );
- struct node copy( struct node source );
Optional Enhancements:
- void reverseInPlace( struct node **head );
- struct node createSortedCopy( struct node head );
- struct node findPrevious( struct node head, char c );
- void insertAfter( struct node *previous, char c );
- void applyFunction( struct node head, char (fp)( char ) );
- struct node select( struct node head, bool (*fp)( char ) );
- bool isPalindrome( struct node * head );
- bool isPurePalindrome( struct node *head );
Incremental Development is recommended, starting with implementing and testing functions one-by-one. The final submission should include your code, a README file, and any other necessary documentation.
Paper For Above Instructions
The assignment for CS 107 entails creating a program that effectively uses linked lists to manage character sequences from user input. The primary focus is on manipulating these sequences as nodes in a linked list structure, allowing for various operations to be performed based on user input.
In the context of this assignment, the program should start by prompting the user to input a sentence. Each character will be read and converted into a linked list node, which includes information on the character itself, its position in the sentence, and its total position from all the sentences read so far. This dynamically allocated structure utilizes the `malloc` function to ensure efficient memory usage as new nodes are created.
Once the user inputs characters, the program will allow them to perform certain operations. This may include printing the sentence, reversing the print order, finding specific characters within the linked list, removing duplicates, or deleting nodes altogether. A switch statement will facilitate these operations, guiding users in navigating the functionality of the program.
The linked list will store characters in reverse order to be processed correctly upon printing. To achieve this, the `print` function will systematically traverse the linked list from the head, while the `printReversed` function will leverage recursion to access nodes in the opposite order.
Moreover, memory management is central to this program. The `delete` function will be fundamental in ensuring that the linked list correctly removes old sentences before starting anew. This function should implement a loop that iteratively frees memory allocated for each node, maintaining system efficiency and preventing memory leaks.
Searching for specific characters will be facilitated by the `find` function, which returns the first node containing the specified character, along with its sequence and total sequence numbers. The `removeDuplicates` function will scrub the linked list of repeated characters based on sensitivity to case, maintaining unique characters for each occurrence in the string.
In terms of enhancements, optional functionality could include in-place reversal of the linked list, the creation of sorted copies of the original linked list, and applying user-defined functions to each character in the list. These enhancements not only provide greater flexibility in manipulation but also enhance the overall user experience.
To accomplish this, function pointers will be employed to allow users to define their own character manipulation functions, such as toggling case or implementing simple ciphers. Such functionalities can dramatically increase the versatility of the linked list management system.
Furthermore, the program must also be user-centric, ensuring prompts are clear, and the logic flows intuitively from one operation to the next. Users should be able to follow their command execution through terminal outputs that clearly delineate each input, output, and the processing occurring behind the scenes.
Overall, this assignment encapsulates significant concepts from the field of computer science, including dynamic memory allocation, linked data structures, recursion, and user interaction through command-line interfaces. Mastering these components is essential for students pursuing advanced studies in programming and software development.
References
- 1. Deitel, P. J., & Deitel, H. M. (2018). C: How to Program (10th ed.). Pearson.
- 2. Kernighan, B. W., & Ritchie, D. M. (1988). The C Programming Language (2nd ed.). Prentice Hall.
- 3. Goodrich, M. T., Tamassia, R., & Goldwasser, M. (2014). Data Structures and Algorithms in Java (6th ed.). Wiley.
- 4. Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley.
- 5. Skiena, S. S. (2009). The Algorithm Design Manual (2nd ed.). Springer.
- 6. Weiss, M. A. (2013). Data Structures and Algorithm Analysis in C++ (4th ed.). Pearson.
- 7. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press.
- 8. Bjarne Stroustrup. (2013). The C++ Programming Language (4th ed.). Addison-Wesley.
- 9. Lippman, S. B., Lajoie, J. & Moo, B. E. (2012). C++ Primer (5th ed.). Addison-Wesley.
- 10. Bartosz Milewski, (2013). Category Theory for Programmers. Retrieved from http://categorytheoryforall.com/
```