Open In App

Telecom Billing System in C

Last Updated : 22 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to create a basic Telecom Billing System using the C programming language. This system allows users to perform operations such as adding new customer records, viewing the list of records, modifying existing records, viewing payment details, searching for specific records, and deleting records.

What is a Telecom Billing System?

Telecom service is one of the biggest services having millions of users and the data managed by these companies are quite large so, we need some software system to efficiently manage this data.

A telecom billing system is a digital system to keeps track of user, their service usage and their pending bill. It is able to store and manage data of multiple users and helps the telecom provider automate the billing of the services from the customer.

Operations Offered by Telecom Billing System

The following are the operations and functionalities offered by the telecom billing system.

telecom billing system in c

 

  • Add New Record: Add new customer record.
  • View List of Records: View all the records at a glance.
  • Modify Record: Modification of an already existing record.
  • View Payment: View the bill for a given customer.
  • Delete Record: The deletion of a record from the memory.

Prerequisites: This project requires you to have a basic understanding of the C programming language concepts such as arrays, strings, structs, etc.

Components of the Telecom Billing System Program

The telecom billing system is divided into multiple components each performing a specific task.

Necessary Libraries

We will use the following libraries:

  1. <stdio.h>: For Input and Output
  2. <string.h>: For String Manipulation

Both of these are standard libraries that come bundled with the C compiler.

Data Structure to Hold Customer Information

  • A structured Customer is defined as holding information about a customer.
  • Array customers[100] of type Customer is created to store customer records. It can hold up to 100 records.
  • customerCount is an integer variable used to keep track of the number of customers.
     

C




// Structure to hold customer information
struct Customer {
    char name[50];
    char phoneNumber[15];
    float usage;
    float totalBill;
};
  
// Global array to store customer data
struct Customer customers[100];
  
// Global variable to keep track of the number of customers
int customerCount = 0;


addRecord(): Function to Add New Customer Record

  • The addRecord() is created in order to add a customer record in the memory.
  • It checks if the current number of customers customerCount is less than 100 ensuring there’s space for a new record.
  • The function prompts the user to enter the customer’s name, phone number, usage in minutes.
  • It calculates the total bill for the customer by multiplying their usage in minutes by 0.1.
  • After adding the record, customerCount is incremented by 1.

C




// Function to add a new customer record
void addRecord()
{
    if (customerCount < 100) {
        printf("\nEnter name: ");
        scanf(" %[^\n]s", customers[customerCount].name);
        printf("Enter phone number: ");
        scanf("%s", customers[customerCount].phoneNumber);
        printf("Enter usage (in minutes): ");
        scanf("%f", &customers[customerCount].usage);
        customers[customerCount].totalBill
            = customers[customerCount].usage * 0.1;
        customerCount++;
        printf("\nRecord added successfully!\n");
    }
    else {
        printf("\nMaximum number of records reached!\n");
    }
}


viewRecords(): Function to Display Customer Records

  • The function named viewRecords() is responsible for displaying the list of customer records.
  • It uses a loop to iterate through each customer record.
  • Within the loop, it prints the name, phone number, usage in minutes, and total bill for each customer.

C




// Function to view the list of customer records
void viewRecords()
{
    printf("\nName\tPhone Number\tUsage(min)\tTotal "
           "Bill($)\n");
    for (int i = 0; i < customerCount; i++) {
        printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
               customers[i].phoneNumber, customers[i].usage,
               customers[i].totalBill);
    }
}


modifyRecord(): Modifying Customer Records by Phone Number

  • The function modifyRecord() is responsible for modifying a customer record using their phone number.
  • It takes a character array phoneNumber as a parameter which is used to identify the customer record to be modified.
  • Using a loop, it checks if the phone number of the current customer matches the provided phoneNumber.
  • If a matching phone number is found it prompts the user to enter the new usage in minutes for the customer and the new bill is calculated based on the updated usage.
  • It displays output to the user either confirming a successful record modification or informing them if the record was not found.

C




// Function to modify a customer record
void modifyRecord(char phoneNumber[])
{
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber)
            == 0) {
            printf(
                "\nEnter new usage (in minutes) for %s: ",
                customers[i].name);
            scanf("%f", &customers[i].usage);
            customers[i].totalBill
                = customers[i].usage * 0.1;
            printf("\nRecord modified successfully!\n");
            return;
        }
    }
    printf("\nRecord not found!\n");
}


viewPayments(): Viewing Payment for a Customer by Phone Number

  • The function viewPayment() is responsible for displaying the total bill for a customer based on their phone number.
  • It takes a char array phoneNumber as a parameter which is used to identify the customer.
  • If a matching phone number is found it prints the total bill for the customer along with their name.
  • It displays output to the user, either displaying the total bill or informing them if the record was not found.

C




// Function to view payment for a customer
void viewPayment(char phoneNumber[])
{
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber)
            == 0) {
            printf("\nTotal Bill for %s: $%.2f\n",
                   customers[i].name,
                   customers[i].totalBill);
            return;
        }
    }
    printf("\nRecord not found!\n");
}


searchRecord(): Searching for a Customer Record by Phone Number

  • This function searchRecord responsible for searching for a customer record based on their phone number.
  • It takes a char array phoneNumber as a parameter which is used to identify the customer.
  • It uses a loop to iterate through each customer record.
  • Within the loop it checks if the phone number of the current customer matches the provided phoneNumber.
  • If a matching phone number is found it prints the information of the customer including name, phone number, usage in minutes, total bill.
  • It displays output to the user either displaying the customer record or informing them if the record was not found.

C




void searchRecord(char phoneNumber[]) {
    printf("\nName\tPhone Number\tUsage(min)\tTotal Bill($)\n");
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber) == 0) {
            printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name, customers[i].phoneNumber, customers[i].usage, customers[i].totalBill);
            return;
        }
    }
    printf("\nRecord not found!\n");
}


deleteRecord(): Deleting a Customer Record by Phone Number

  • This function deleteRecord() is responsible for deleting a customer record based on their phone number.
  • It takes a char array phoneNumber as a parameter which is used to identify the customer record to be deleted.
  • If a matching phone number is found, it shifts all records after the matched record by one position to effectively delete the record.
  • After deleting the record it decrements the customerCount by 1.
  • It provides feedback to the user confirming a successful record deletion or informing them the record was not found.

C




void deleteRecord(char phoneNumber[]) {
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber) == 0) {
            for (int j = i; j < customerCount - 1; j++) {
                customers[j] = customers[j + 1];
            }
            customerCount--;
            printf("\nRecord deleted successfully!\n");
            return;
        }
    }
    printf("\nRecord not found!\n");
}


Main Function

The main function handles the primary control of the program.

  • An infinite while loop is used to provide the user with a dashboard that resets after each.
  • A switch case is used to process the user’s choices.

C




int main()
{
    int choice;
    char phoneNumber[15];
  
    while (1) {
        displayMenu();
        printf("Enter your choice: ");
        scanf("%d", &choice);
  
        switch (choice) {
        case 1:
            addRecord();
            break;
        case 2:
            viewRecords();
            break;
        case 3:
            printf(
                "\nEnter phone number to modify record: ");
            scanf("%s", phoneNumber);
            modifyRecord(phoneNumber);
            break;
        case 4:
            printf(
                "\nEnter phone number to view payment: ");
            scanf("%s", phoneNumber);
            viewPayment(phoneNumber);
            break;
        case 5:
            printf(
                "\nEnter phone number to search record: ");
            scanf("%s", phoneNumber);
            searchRecord(phoneNumber);
            break;
        case 6:
            printf(
                "\nEnter phone number to delete record: ");
            scanf("%s", phoneNumber);
            deleteRecord(phoneNumber);
            break;
        case 7:
            return 0;
        default:
            printf("\nInvalid choice! Please try again.\n");
        }
    }
  
    return 0;
}


Finally, we implement all these components and create a complete program.

C Program to Implement Telecom Billing System

C




#include <stdio.h>
#include <string.h>
  
// Structure to hold customer information
struct Customer {
    char name[50];
    char phoneNumber[15];
    float usage;
    float totalBill;
};
  
struct Customer
    customers[100]; // Array to store customer data
int customerCount = 0; // Variable to keep track of the
                       // number of customers
  
// Function to add a new customer record
void addRecord()
{
    if (customerCount < 100) {
        printf("\nEnter name: ");
        scanf(" %[^\n]s", customers[customerCount].name);
        printf("Enter phone number: ");
        scanf("%s", customers[customerCount].phoneNumber);
        printf("Enter usage (in minutes): ");
        scanf("%f", &customers[customerCount].usage);
        customers[customerCount].totalBill
            = customers[customerCount].usage * 0.1;
        customerCount++;
        printf("\nRecord added successfully!\n");
    }
    else {
        printf("\nMaximum number of records reached!\n");
    }
}
  
// Function to view the list of customer records
void viewRecords()
{
    printf("\nName\tPhone Number\tUsage(min)\tTotal "
           "Bill($)\n");
    for (int i = 0; i < customerCount; i++) {
        printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
               customers[i].phoneNumber, customers[i].usage,
               customers[i].totalBill);
    }
}
  
// Function to modify a customer record
void modifyRecord(char phoneNumber[])
{
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber)
            == 0) {
            printf(
                "\nEnter new usage (in minutes) for %s: ",
                customers[i].name);
            scanf("%f", &customers[i].usage);
            customers[i].totalBill
                = customers[i].usage * 0.1;
            printf("\nRecord modified successfully!\n");
            return;
        }
    }
    printf("\nRecord not found!\n");
}
  
// Function to view payment for a customer
void viewPayment(char phoneNumber[])
{
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber)
            == 0) {
            printf(
                "%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
                customers[i].phoneNumber,
                customers[i].usage, customers[i].totalBill);
            return;
        }
    }
    printf("\nRecord not found!\n");
}
  
// Function to delete a customer record
void deleteRecord(char phoneNumber[])
{
    for (int i = 0; i < customerCount; i++) {
        if (strcmp(customers[i].phoneNumber, phoneNumber)
            == 0) {
            for (int j = i; j < customerCount - 1; j++) {
                customers[j] = customers[j + 1];
            }
            customerCount--;
            printf("\nRecord deleted successfully!\n");
            return;
        }
    }
    printf("\nRecord not found!\n");
}
  
// Function to display menu options
void displayMenu()
{
    printf("\n1. Add New Record\n");
    printf("2. View List of Records\n");
    printf("3. Modify Record\n");
    printf("4. View Payment\n");
    printf("5. Delete Record\n");
    printf("6. Exit\n");
}
  
int main()
{
    int choice;
    char phoneNumber[15];
  
    while (1) {
        displayMenu();
        printf("Enter your choice: ");
        scanf("%d", &choice);
  
        switch (choice) {
        case 1:
            addRecord();
            break;
        case 2:
            viewRecords();
            break;
        case 3:
            printf(
                "\nEnter phone number to modify record: ");
            scanf("%s", phoneNumber);
            modifyRecord(phoneNumber);
            break;
        case 4:
            printf(
                "\nEnter phone number to view payment: ");
            scanf("%s", phoneNumber);
            viewPayment(phoneNumber);
            break;
        case 5:
            printf(
                "\nEnter phone number to delete record: ");
            scanf("%s", phoneNumber);
            deleteRecord(phoneNumber);
            break;
        case 6:
            return 0;
        default:
            printf("\nInvalid choice! Please try again.\n");
        }
    }
  
    return 0;
}


Output

1. Customer Dashboard

output of the program - Dashboard

 

2. Add New Record

adding new customer record

 

3. View Payments

viewing payment of the customer

 

Execution of Program



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads