Vimal C Assignment 1
Vimal C Assignment 1
REG NO:192421350
ASSIGNMENT-1
Here’s a basic implementation of the Blood Donation System in C that satisfies the given
requirements. This program includes:
Modular design with separate functions for input, processing, and output.
Use of pre-processor directives for constants like blood types and eligibility criteria.
Donor eligibility checks based on age, health conditions, and donation intervals.
CODING:
#include <stdio.h>
#include <string.h>
#define MIN_AGE 18
#define MAX_AGE 65
#define MIN_DONATION_INTERVAL 56
// Donor structure
typedef struct {
char name[50];
int age;
int donations;
} Donor;
// Function prototypes
int main() {
Donor donors[MAX_DONORS];
int totalDonors = 0;
char choice;
inputDonorDetails(&donors[totalDonors]);
totalDonors++;
break;
displaySummary(donors, totalDonors);
return 0;
scanf("%d", &donor->age);
scanf("%d", &donor->donations);
if (isEligible(donor->age, donor->donations)) {
} else {
return (age >= MIN_AGE && age <= MAX_AGE && donations >=
MIN_DONATION_INTERVAL);
if (totalDonors == 0) {
return;
highestDonations = donors[i].donations;
highestIndex = i;
}
if (donors[i].donations < lowestDonations) {
lowestDonations = donors[i].donations;
lowestIndex = i;
printf("Summary Report:\n");
Sample Output:
Summary Report:
Benefits:
Easier Debugging: Bugs can be isolated in specific modules, reducing troubleshooting time.
Code Reusability: Functions like getAgeEligibility() can be reused in future projects or modified
easily without affecting other parts of the code.
Efficiency Analysis:
Execution Efficiency: Modularization does not significantly impact runtime, as each module is
designed for a specific task, ensuring efficient use of memory and resources.
Development Efficiency: The modular design makes it faster to develop since developers can
work on different functions independently, speeding up the overall development time.
b) Explain how pre-processor directives simplify donor eligibility criteria with efficiency analysis.
Explanation:
Pre-processor directives such as #define are used to declare constants like MIN_AGE and
MIN_DONATION_INTERVAL. This makes it easy to modify the criteria without changing multiple
parts of the code. For example, if the minimum age changes, only the #define MIN_AGE
statement needs to be updated.
Efficiency Analysis:
Execution Efficiency: Pre-processor directives do not affect the program's execution speed since
they are resolved at compile time.
Development Efficiency: The use of constants simplifies code readability and future updates,
leading to faster development times.
c) Analyze the role of control statements in donor categorization with efficiency analysis.
Explanation:
Control statements like if and else are used to check if a donor meets the age, health, and
donation interval criteria. This categorizes donors as eligible or ineligible.
Switch statements could also be used for more complex categorization (e.g., healthy donors vs.
special medical conditions).
Efficiency Analysis:
Execution Efficiency: Conditional statements have minimal impact on performance, as they are
evaluated in constant time.
Development Efficiency: They simplify the logic and ensure accurate categorization of donors,
reducing the need for complex, redundant checks.
Challenges:
Health Complexity: Donors may have diverse medical conditions, and automating the checks
requires comprehensive health data, which can be difficult to standardize.
Input Errors: Donor data might be entered incorrectly (e.g., age or medical history), which could
result in incorrect eligibility checks.
Data Privacy: Ensuring that sensitive medical data is handled securely while automating
eligibility checks is a challenge.
Efficiency Analysis:
Execution Efficiency: Automation might introduce delays if data validation or complex health
checks are required, particularly with large datasets.