google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C program that simulates a kirana store's billing system

Sunday, March 30, 2025

C program that simulates a kirana store's billing system

 Here's a simplified C program that simulates a kirana store's billing system:


Kirana Store Billing Program


#include <stdio.h>

#include <stdlib.h>


// Define structure for products

typedef struct {

    char name[50];

    float retailRate;

    float wholesaleRate;

    int quantity;

} Product;


// Define structure for bills

typedef struct {

    Product product;

    float rate;

    int quantity;

    float amount;

} Bill;


// Function to create a new product

Product createProduct(char *name, float retailRate, float wholesaleRate, int quantity) {

    Product product;

    strcpy(product.name, name);

    product.retailRate = retailRate;

    product.wholesaleRate = wholesaleRate;

    product.quantity = quantity;

    return product;

}


// Function to create a new bill

Bill createBill(Product product, float rate, int quantity) {

    Bill bill;

    bill.product = product;

    bill.rate = rate;

    bill.quantity = quantity;

    bill.amount = rate * quantity;

    return bill;

}


// Function to display bill details

void displayBill(Bill bill) {

    printf("Product Name: %s\n", bill.product.name);

    printf("Rate: %.2f\n", bill.rate);

    printf("Quantity: %d\n", bill.quantity);

    printf("Amount: %.2f\n", bill.amount);

}


// Function to calculate total profit

float calculateProfit(Bill *bills, int billCount) {

    float totalProfit = 0;

    for (int i = 0; i < billCount; i++) {

        if (bills[i].rate == bills[i].product.wholesaleRate) {

            totalProfit += (bills[i].product.retailRate - bills[i].product.wholesaleRate) * bills[i].quantity;

        }

    }

    return totalProfit;

}


int main() {

    // Create products

    Product product1 = createProduct("Rice", 50.0, 40.0, 100);

    Product product2 = createProduct("Wheat", 30.0, 25.0, 50);


    // Create bills

    Bill bill1 = createBill(product1, 50.0, 20);

    Bill bill2 = createBill(product2, 25.0, 30);

    Bill bill3 = createBill(product1, 40.0, 50); // Wholesale rate


    // Display bill details

    printf("Bill 1:\n");

    displayBill(bill1);

    printf("\nBill 2:\n");

    displayBill(bill2);

    printf("\nBill 3:\n");

    displayBill(bill3);


    // Calculate total profit

    Bill bills[] = {bill1, bill2, bill3};

    float totalProfit = calculateProfit(bills, 3);

    printf("\nTotal Profit: %.2f\n", totalProfit);


    return 0;

}



This program demonstrates the following concepts:


1. *Product structure*: A structure to represent products with attributes like name, retail rate, wholesale rate, and quantity.

2. *Bill structure*: A structure to represent bills with attributes like product, rate, quantity, and amount.

3. *Billing system*: A system to create bills based on product rates and quantities.

4. *Profit calculation*: A function to calculate the total profit earned by selling products at retail and wholesale rates.


Note that this program is a highly simplified example and does not cover real-world complexities like inventory management, customer management, and tax calculations.

No comments:

Post a Comment

The rotation of money in business

 The rotation of money in business refers to the flow of funds within a company, encompassing various financial activities and transactions....