CS163 Spring 2021 Program 1 Individual Programming Assignmen
Cs163 Spring 2021 Program 1individual Programming Assignment 1cs 163
Write a program that manages a collection of trivia questions categorized by type, using classes and linked lists. The program should allow the user to add questions, display questions of a specific category or all questions, remove categories, select and display random questions from a category, and check answers in a case-insensitive manner. All data should be dynamically allocated, and member functions must adhere to data abstraction rules, including avoiding user prompts or output within the class methods. The main function should serve as an interactive test client, providing a menu for testing class functionalities without hardcoded test cases. Use only C-style strings and standard library functions for string handling.
Paper For Above instruction
In the context of software development, especially in data structures and object-oriented programming, designing robust, efficient, and encapsulated classes is paramount. The assignment described establishes a clear structure for managing trivia questions categorized by type using linked lists. This exercise encapsulates core principles such as dynamic memory management, data abstraction, and modular design, all critical for developing scalable and maintainable applications.
At its core, the program's primary data structure is a collection of linked lists, each representing a category containing questions and their answers. Using classes, specifically a class like CS_Trivia, enables encapsulation of data and functions, ensuring that implementation details are hidden from users of the class. The design emphasizes that member functions should not interact directly with the user environment—avoiding prompts, outputting error messages, or reading from standard input within class methods. Instead, these functions should operate solely based on arguments, returning success or failure statuses to facilitate testing and debugging.
The class must include constructors and destructors to manage dynamic memory properly—creating and destroying linked list nodes as needed, thus avoiding memory leaks. For instance, the constructor should initialize the head pointer to nullptr, and the destructor should traverse the linked list, deallocating each node safely.
Adding questions involves passing the category, question, and answer as arguments to a class member function. This function will then create new nodes dynamically and insert them into the appropriate category list. It is crucial that the implementation supports multiple categories, which can be managed via a linked list of category nodes, each containing a pointer to a linked list of questions.
Displaying questions for a specific category or all questions for debugging purposes involves traversing the respective linked lists, printing the questions and answers. These display functions are allowed to output directly since they are primarily for testing and debugging. Similarly, removing a category requires passing the category name, which leads to deallocating all nodes within that list and removing the category node itself.
The selection of a random question from a category enhances the interactive aspect of the program, simulating the experience of asking questions in a trivia game. The function responsible for this should take the category as an argument, randomly select a question from the category's linked list, and display it. This process requires calculating the number of questions in the list, generating a random index, and traversing the list accordingly.
Answer checking is performed by comparing the user's response with the stored answer, ignoring case differences. This comparison should utilize C standard string functions like strcmp, strcasecmp, or a custom case-insensitive compare function, which respects the restriction of not using the C++
This program emphasizes the implementation of core object-oriented programming principles, such as encapsulation, modularity, and data abstraction, making the class interface clean and the internal data structures hidden. Proper header and implementation files foster code organization, readability, and maintainability. The client program serves as a menu-driven interface for testing all functionalities interactively without hardcoded test cases, enabling comprehensive testing of the class methods under various scenarios.
References
- Stroustrup, B. (2013). The C++ Programming Language (4th ed.). Addison-Wesley.
- Gaddis, T. (2018). Starting Out with C++: Early Objects (9th ed.). Pearson.
- Horowitz, E., Sahni, S., & Rajasekaran, S. (2008). Fundamentals of Computer Algorithms. Silicon Press.
- Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley.
- Liskov, B., & Guttag, J. (2000). Program Development in Java: Abstraction, Specification, and Object-Oriented Design. Addison-Wesley.
- Price, B., & Ruggiero, C. (2001). Data Structures and Algorithms in C++ (2nd ed.). McGraw-Hill.
- Strang, G. (2009). Introduction to Linear Algebra. Wellesley-Cambridge Press.
- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press.
- Kopec, D. (2015). Data Structures in C++. Springer.
- Thinking in C++, Volume 1: Introduction to Standard C++ (2nd ed.). (2004). Addison-Wesley.