You are on page 1of 6

TARIK MOURAD

223J01
CST22
Abstract:
This report provides an analysis of a C program designed to manage a list of drugs using a sequential list data
structure. The system's capabilities include reading drug data from a file, sorting drugs by price, searching for
drugs by number or name, and printing the drug list. The code is evaluated for its structure, functionality,
efficiency, and maintainability.

Introduction:
The management of pharmaceutical data is critical for healthcare providers, pharmacies, and medical facilities.
The C program analyzed here is a prototype for a drug inventory system that includes fundamental operations
such as reading from a file, sorting, searching, and displaying data.

Data Structures:
The program uses two primary data structures:
1. DataType - A struct that encapsulates a single drug's data.
2. SequenList - A struct that contains an array of DataType elements, representing the list of drugs,
and an integer indicating the number of current elements in the list.

File I/O Operations:


The ReadDataFromFile function is responsible for populating the SequenList with drug information from a
given file. It opens the file in read mode and processes the data line by line. Error handling is present to notify
the user if the file cannot be opened.

Sorting Algorithm:
The BubbleSort function implements the bubble sort algorithm to organize the drugs by their price in
ascending order. While bubble sort is known for its simplicity, it is not the most efficient sorting method,
especially for large datasets.
Search Functions:
Two search functions, SearchByNumber and SearchByName, provide linear search capabilities to locate drugs by
their unique number or name, respectively. These functions iterate through the list and compare each element
with the search key, returning the index of the matching element or -1 if not found.

User Interface:
The main function offers a simple text-based interface for users to interact with the system. It provides options
to search by number or name and to exit the program. User inputs are captured and processed, with appropriate
messages displayed based on the search results.

Code Organization and Quality:


The code is organized into functions that handle specific tasks, promoting a degree of modularity. However,
several improvements could be made to enhance code quality:
 Implementing more efficient algorithms for sorting and searching.
 Introducing dynamic memory allocation to handle an arbitrary number of drug entries.
 Incorporating better input validation to guard against invalid data.
 Improving error handling for robustness against unexpected scenarios.

Efficiency:
The efficiency of the code is a concern due to the use of bubble sort and linear search algorithms. For larger
datasets, these operations can be significantly slow, affecting the system's overall performance.

Maintainability:
The code's maintainability is aided by its modular structure but is limited by the fixed size of the SequenList.
Future improvements could include refactoring to make the codebase more adaptable to changes and
enhancements.

Conclusion:
The analyzed code serves as a basic implementation of a drug list management system with core functionalities
required for managing a small dataset of pharmaceutical products. It demonstrates elementary file operations,
sorting, searching, and user interaction in C.

You might also like