You are on page 1of 13

NAME :- Priyanshu Raj

Section :- K22CC
Reg, No. :- 12219279
Roll No. :- 24
PROJECT TITLE :- Courier Management System.

Introduction:
Courier Management System (CMS) is a software solution that enables businesses to manage their
courier and delivery services. The system streamlines the entire process, from package pickup to
delivery, by automating various operations such as order processing, tracking, dispatch, and billing.
In this report, we will discuss the key modules of a CMS, including Insert, Display, Search, Delete,
Update, and Sort.

Module 1: Insert
The Insert module is responsible for adding new courier details into the CMS. This module includes
various fields such as sender and recipient information, courier type, weight, and delivery location.
Once the data is entered into the system, it is stored in the database for future reference.

Module 2: Display
The Display module allows users to view the list of couriers that have been added to the CMS. This
module provides various options to filter and sort the data based on sender, recipient, date, or
delivery status. Users can also view additional details such as courier ID, delivery date, and shipping
cost.

Module 3: Search
The Search module enables users to find specific courier details based on various criteria such as
sender, recipient, courier type, or delivery location. This module uses the database to search for
relevant data and returns the results to the user.

Module 4: Delete
The Delete module is used to remove courier details from the CMS. Users can select one or more
couriers from the list and delete them from the system. This module ensures that the data is
permanently removed from the database to avoid any future conflicts.

Module 5: Update
The Update module enables users to modify existing courier details in the CMS. This module allows
users to change the courier type, weight, or delivery location. Once the modifications are made, the
data is updated in the database, and the changes are reflected in the

Module 6:Sort

The module sort is an essential component of the courier management system. It is responsible for
sorting the shipments based on various criteria such as destination, delivery date, and shipment size.
The module sort is a function that takes an array of shipments and sorts them based on the selected
criterion.

The sorting algorithm used in the module sort is the bubble sort algorithm. The bubble sort
algorithm is a simple sorting algorithm that works by repeatedly swapping adjacent elements if they
are in the wrong order. The algorithm takes O(n^2) time to sort n elements.
Overall, the courier management system with the module sort is a useful software system that helps
courier companies streamline their operations and provide better services to their customers.

.
Add:-
#include <stdio.h>
#include <stdlib.h>

void addCourier(){
FILE *fp = fopen("couriers.txt", "a");
printf("Please enter the courier's name: ");
char name[100];
scanf("%s", name);
printf("Please enter the courier's phone number: ");
char phone[100];
scanf("%s", phone);
printf("Please enter the courier's address: ");
char address[100];
scanf("%s", address);
fprintf(fp, "%s %s %s\n", name, phone, address);
printf("Added!\n");
fclose(fp);
}

Cerdiental .h:-

#include <stdio.h>
#include <string.h>

void addNewUser(char *username, char *password){


FILE *fp = fopen("credentials.txt", "a");
fprintf(fp, "%s %s\n", username, password);
fclose(fp);
printf("User added successfully!");
}

int checkUsername(char *name){


FILE *fp = fopen("credentials.txt", "r");
if(fp == NULL){
return 0;
}
while(!feof(fp)){
char username[100], password[100];
fscanf(fp, "%s %s\n", username, password);
if(strcmp(username, name) == 0){
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}

int verifyCredentials(char *username, char *password){


FILE *fp = fopen("credentials.txt", "r");
while(!feof(fp)){
char user[100], pass[100];
fscanf(fp, "%s %s\n", user, pass);
if(strcmp(user, username) == 0 && strcmp(pass, password) == 0){
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}

Cms :-

#include <stdio.h>
#include <stdlib.h>
#include "credentials.h"
#include "addCourier.h"
#include "displayCouriers.h"
#include "searchCourier.h"
#include "deleteUpdateCourier.h"
#include "sortCouriers.h"

void mainMenu(){
printf("Please select an option:\n");
printf("1. Add a new courier\n");
printf("2. Display existing courier records\n");
printf("3. Search for a courier\n");
printf("4. Delete/Update a courier record\n");
printf("5. Sort courier records\n");
printf("6. Exit\n");
printf("Please enter your choice: ");
int choice;
scanf("%d", &choice);
switch(choice){
case 1:
addCourier();
mainMenu();
break;
case 2:
displayCouriers();
mainMenu();
break;
case 3:
searchCouriers();
mainMenu();
break;
case 4:
deleteUpdateCourier();
mainMenu();
break;
case 5:
sortCouriers();
mainMenu();
break;
case 6:
exit(0);
break;
default:
printf("Invalid choice. Please try again.\n");
mainMenu();
break;
}
}

void login(){
printf("Please enter your username: ");
char username[20];
scanf("%s", username);
printf("Please enter your password: ");
char password[20];
scanf("%s", password);
if (verifyCredentials(username, password)){
printf("Login successful.\n");
mainMenu();
}
else{
printf("Invalid credentials. Please try again.\n");
login();
}
}

void newregister(){
printf("Please enter your username: ");
char username[20];
scanf("%s", username);
printf("Please enter your password: ");
char password[20];
scanf("%s", password);
if (checkUsername(username)){
printf("Username already exists. Please try again.\n");
newregister();
}
else{
addNewUser(username, password);
}
}

int main(){
printf("Welcome to the Courier Management System\n\n");
printf("Would you like to login or register?\n");
printf("1. Login\n");
printf("2. Register\n");
printf("3. Exit\n");
printf("Please enter your choice: ");
int choice;
scanf("%d", &choice);
switch(choice){
case 1:
login();
break;
case 2:
newregister();
break;
case 3:
exit(0);
break;
default:
printf("Invalid choice. Please try again.\n");
main();
break;
}

Delete and update:-


#include <stdio.h>

void deleteCourier(char* name){


FILE *fp = fopen("couriers.txt", "r");
FILE *temp = fopen("temp.txt", "w");
char line[100];
while(fgets(line, 100, fp) != NULL){
if(strstr(line, name) == NULL){
fprintf(temp, "%s", line);
}
}

fclose(fp);
fclose(temp);
temp = fopen("temp.txt", "r");
fp = fopen("couriers.txt", "w");
char c = fgetc(temp);
while(c != EOF){
fputc(c, fp);
c = fgetc(temp);
}
fclose(fp);
fclose(temp);
printf("Courier deleted successfully.\n");
}

void updateCourier(char* name){


FILE *fp = fopen("couriers.txt", "r");
FILE *temp = fopen("temp.txt", "w");
char line[100];
while(fgets(line, 100, fp) != NULL){
if(strstr(line, name) == NULL){
fprintf(temp, "%s", line);
}
else{
printf("Please enter the new address: ");
char address[100];
scanf("%s", address);
printf("Please enter the new phone number: ");
char phone[100];
scanf("%s", phone);
fprintf(temp, "%s %s %s\n", name, phone, address);
}
}
fclose(fp);
fclose(temp);
fp = fopen("couriers.txt", "w");
temp = fopen("temp.txt", "r");
char c = fgetc(temp);
while(c != EOF){
fputc(c, fp);
c = fgetc(temp);
}
fclose(fp);
fclose(temp);
printf("Courier updated successfully.\n");
}

void deleteUpdateCourier(){
FILE *fp = fopen("couriers.txt", "r+");
if(fp == NULL){
printf("No courier records found.\n");
return;
}
printf("Please enter the name of the courier you wish to delete/update: ");
char name[100];
scanf("%s", name);
int found = 0;
while(!feof(fp)){
char Cname[100], address[100], phone[100];
fscanf(fp, "%s %s %s", Cname, address, phone);
if(strcmp(name, Cname) == 0){
found = 1;
}
}
if(!found){
printf("No courier found with the name %s.\n", name);
return;
}

printf("Please select an option:\n");


printf("1. Delete courier\n");
printf("2. Update courier\n");
printf("Please enter your choice: ");
int choice;
scanf("%d", &choice);
switch(choice){
case 1:
deleteCourier(name);
break;
case 2:
updateCourier(name);
break;
default:
printf("Invalid choice. Please try again.\n");
deleteUpdateCourier();
break;
}
fclose(fp);
}

Display courier:-
#include <stdio.h>

void displayCouriers(){
FILE *fp = fopen("couriers.txt", "r");
if(fp == NULL){
printf("No courier records found.\n");
return;
}
printf("Courier Name\t | Courier Phone\t | Courier Address\n");
char name[100], address[100], phone[100];
int i = 0;
while(!feof(fp)){
if (i!=0)
printf("%s\t | %s\t | %s\n", name, phone, address);
fscanf(fp, "%s %s %s", name, phone, address);
i++;
}
fclose(fp);
}
Search courier:-

#include <stdio.h>

void searchCouriers(){
FILE *fp = fopen("couriers.txt", "r");
if(fp == NULL){
printf("No courier records found.\n");
return;
}
printf("Please enter the name of the courier you want to search for: ");
char name[100];
scanf("%s", name);
int found = 0;
while(!feof(fp)){
char Cname[100], address[100], phone[100];
fscanf(fp, "%s %s %s", Cname, address, phone);
if(strcmp(name, Cname) == 0){
printf("Courier Name\t | Courier Address\t | Courier Phone\n");
printf("%s\t | %s\t | %s\n", name, address, phone);
found = 1;
break;
}
}
if(!found){
printf("No courier found with the name %s.\n", name);
}
}
Sort courier:-

#include <stdio.h>
#include <string.h>

void sortCouriers(){
FILE *fp = fopen("couriers.txt", "r");
//declare a string array to store the details of courier in name + phone + address format where the
total size is less than 300
char couriers[300][300];
//iterate through the file and store the details of each courier in the string array
int i = 0;
while(!feof(fp)){
char name[100], address[100], phone[100];
fscanf(fp, "%s %s %s", name, phone, address);
strcpy(couriers[i], name);
strcat(couriers[i], " ");
strcat(couriers[i], phone);
strcat(couriers[i], " ");
strcat(couriers[i], address);
i++;
}
int j,k;
//sort the string array using bubble sort
for(j = 0; j < i - 1; j++)
{
for(k = 0; k < i - 1 - j - 1; k++){
if(strcmp(couriers[k], couriers[k+1]) > 0){
char temp[300];
strcpy(temp, couriers[k]);
strcpy(couriers[k], couriers[k+1]);
strcpy(couriers[k+1], temp);
}
}
}
fclose(fp);
//write the sorted string array to the file

fp = fopen("couriers.txt", "w");
for( j = 0; j < i - 1; j++){
fprintf(fp, "%s\n", couriers[j]);
}
fclose(fp);
}
DFD :-
+---------------+
| Customers |
+---------------+
|
| Request
v
+---------------+
| Courier |
| Management |
| System |
+---------------+
|
| Process
v
+---------------+
| Couriers |
+---------------+

You might also like