0% found this document useful (0 votes)
6 views9 pages

Vimal C Assignment 1

The document presents a C program for a Blood Donation System that includes donor registration, eligibility checks, and a summary report of donations. It emphasizes modular programming for maintainability and debugging, along with the use of pre-processor directives for defining constants related to donor criteria. Additionally, it discusses the challenges of automating donor eligibility checks and the efficiency of various programming constructs used in the system.

Uploaded by

rvvd551977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Vimal C Assignment 1

The document presents a C program for a Blood Donation System that includes donor registration, eligibility checks, and a summary report of donations. It emphasizes modular programming for maintainability and debugging, along with the use of pre-processor directives for defining constants related to donor criteria. Additionally, it discusses the challenges of automating donor eligibility checks and the efficiency of various programming constructs used in the system.

Uploaded by

rvvd551977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

NAME:R VIMAL

REG NO:192421350

COURSE CODE & NAME:CSA0284 (C PROGRAMMING)

ASSIGNMENT-1

C Program for Blood Donation System

Here’s a basic implementation of the Blood Donation System in C that satisfies the given
requirements. This program includes:

 A brief history of C programming when the system starts.

 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.

 A summary report showing the highest and lowest number of donations.

CODING:

#include <stdio.h>

#include <string.h>

#define MIN_AGE 18

#define MAX_AGE 65

#define MIN_DONATION_INTERVAL 56

#define MAX_DONORS 100

// Donor structure

typedef struct {

char name[50];

int age;

int donations;
} Donor;

// Function prototypes

void inputDonorDetails(Donor* donor);

int isEligible(int age, int donations);

void displaySummary(Donor donors[], int totalDonors);

int main() {

Donor donors[MAX_DONORS];

int totalDonors = 0;

char choice;

// Loop to register multiple donors

while (totalDonors < MAX_DONORS) {

inputDonorDetails(&donors[totalDonors]);

totalDonors++;

printf("Do you want to register another donor? (y/n): ");

scanf(" %c", &choice);

if (choice != 'y' && choice != 'Y') {

break;

displaySummary(donors, totalDonors);

return 0;

// Function to input donor details

void inputDonorDetails(Donor* donor) {

printf("Enter donor name: ");


scanf(" %[^\n]%*c", donor->name); // To read name with spaces

printf("Enter donor age: ");

scanf("%d", &donor->age);

printf("Enter number of donations: ");

scanf("%d", &donor->donations);

if (isEligible(donor->age, donor->donations)) {

printf("%s is eligible to donate.\n\n", donor->name);

} else {

printf("%s is not eligible to donate.\n\n", donor->name);

// Function to check if the donor is eligible based on age and donations

int isEligible(int age, int donations) {

return (age >= MIN_AGE && age <= MAX_AGE && donations >=
MIN_DONATION_INTERVAL);

// Function to display summary report

void displaySummary(Donor donors[], int totalDonors) {

if (totalDonors == 0) {

printf("No donors registered.\n");

return;

int highestDonations = donors[0].donations, lowestDonations = donors[0].donations;

int highestIndex = 0, lowestIndex = 0;

for (int i = 1; i < totalDonors; i++) {

if (donors[i].donations > highestDonations) {

highestDonations = donors[i].donations;

highestIndex = i;

}
if (donors[i].donations < lowestDonations) {

lowestDonations = donors[i].donations;

lowestIndex = i;

printf("Summary Report:\n");

printf("Highest donations by: %s with %d donations.\n", donors[highestIndex].name,


highestDonations);

printf("Lowest donations by: %s with %d donations.\n", donors[lowestIndex].name,


lowestDonations);

Sample Output:

Enter donor name: John Doe

Enter donor age: 25

Enter number of donations: 60

John Doe is eligible to donate.

Do you want to register another donor? (y/n): y

Enter donor name: Jane Smith

Enter donor age: 17

Enter number of donations: 30

Jane Smith is not eligible to donate.

Do you want to register another donor? (y/n): n

Summary Report:

Highest donations by: John Doe with 60 donations.

Lowest donations by: Jane Smith with 30 donations.


Question Analysis
a) Discuss the benefits of modular programming in a blood donation system with efficiency analysis.

Benefits:

 Improved Maintainability: Dividing the program into functions like inputDonorDetails(),


checkEligibility(), and displaySummary() makes it easier to maintain and update individual
components.

 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.

d) Identify challenges in automating donor eligibility checks with efficiency analysis.

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.

 Development Efficiency: Building a comprehensive eligibility check system requires careful


planning, increasing development time. The system needs regular updates and extensive testing
to ensure accuracy and security.
CODING SCREENSHOTS:

You might also like