0% found this document useful (0 votes)
24 views4 pages

Exp 10

The document outlines a lab manual for creating a STORE class in C programming to manage products, display a menu, and generate bills based on user orders. It details the objectives, required materials, theoretical background, and step-by-step instructions for implementing the program without using functions. The conclusion emphasizes the simulation of class-like behavior using structures and the program's effectiveness in handling orders and bill calculations.

Uploaded by

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

Exp 10

The document outlines a lab manual for creating a STORE class in C programming to manage products, display a menu, and generate bills based on user orders. It details the objectives, required materials, theoretical background, and step-by-step instructions for implementing the program without using functions. The conclusion emphasizes the simulation of class-like behavior using structures and the program's effectiveness in handling orders and bill calculations.

Uploaded by

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

Peoples Empowerment Group

ISBM COLLEGE OF ENGINEERING, NANDE, PUNE


DEPARTMENT OF FIRST YEAR ENGINEERING
Academic Year 2024-25

LAB MANUAL

Experiment/Program 10
Create class STORE to keep track of Products (Product Code, Name and price). Display
menu of all products to users. Generate bills as per orde.

Objective:

To create a STORE class that keeps track of products, displays a menu of available products to
users, and generates bills based on user orders without using functions in C programming.

Materials Required:
 A computer with a C compiler installed.
 Basic knowledge of C programming, including arrays, loops, and structures.

Theory:

In C programming, classes are not explicitly supported as in object-oriented languages like C++
or Java. However, similar behavior can be simulated using structures. The STORE class can be
represented using a structure, and its operations can be carried out using loops and conditionals
without functions.

Steps Involved:

1. Define a Structure to Store Product Information:


o Define a structure Product that contains:
 int code for the product code.
 char name[30] for the product name.
 float price for the product price.
2. Initialize an Array of Products:

o Create an array of Product structures to store details of different products avail-


able in the store.
3. Display the Menu of Products:

oIterate through the array of products and display each product's code, name, and
price.
4. Accept User Orders:
Peoples Empowerment Group
ISBM COLLEGE OF ENGINEERING, NANDE, PUNE
DEPARTMENT OF FIRST YEAR ENGINEERING
Academic Year 2024-25
oUse a loop to accept product codes and quantities from the user.
oStore the selected products and their quantities in separate arrays.
5. Calculate the Bill:

o Iterate through the user's order, calculate the total cost for each product (quantity
* price), and accumulate the total bill amount.
6. Display the Bill:

o Display the detailed bill, including product names, quantities, unit prices, and the
total amount.

C Program:

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

struct Product {
int code;
char name[30];
float price;
};

int main() {
// Step 1: Define products
struct Product store[3] = {
{101, "Product A", 50.0},
{102, "Product B", 30.0},
{103, "Product C", 20.0}
};

int i, code, quantity, total_quantity = 0;


float total_bill = 0.0;
int order_codes[10];
int order_quantities[10];

// Step 2: Display menu of products


printf("Available Products:\n");
printf("Code\tName\t\tPrice\n");
for (i = 0; i < 3; i++) {
printf("%d\t%s\t%.2f\n", store[i].code, store[i].name, store[i].price);
}

// Step 3: Accept user order


Peoples Empowerment Group
ISBM COLLEGE OF ENGINEERING, NANDE, PUNE
DEPARTMENT OF FIRST YEAR ENGINEERING
Academic Year 2024-25
while (1) {
printf("Enter product code to order (0 to finish): ");
scanf("%d", &code);
if (code == 0) break;

printf("Enter quantity: ");


scanf("%d", &quantity);

order_codes[total_quantity] = code;
order_quantities[total_quantity] = quantity;
total_quantity++;
}

// Step 4: Generate bill


printf("\nBill:\n");
printf("Code\tName\t\tQuantity\tPrice\tTotal\n");
for (i = 0; i < total_quantity; i++) {
for (int j = 0; j < 3; j++) {
if (store[j].code == order_codes[i]) {
float item_total = order_quantities[i] * store[j].price;
total_bill += item_total;
printf("%d\t%s\t%d\t\t%.2f\t%.2f\n", store[j].code, store[j].name,
order_quantities[i], store[j].price, item_total);
}
}
}

printf("Total Bill Amount: %.2f\n", total_bill);

return 0;
}

Explanation of the Code:


1. Structure Definition: The Product structure stores the product code, name, and price.
2. Product Array: The store array is initialized with 3 products.
3. Menu Display: The for loop iterates through the store array to display the available
products.
4. Order Processing: A while loop is used to accept product codes and quantities until the
user enters 0.
5. Bill Calculation: Nested for loops match the ordered product codes with the store in-
ventory, calculate the total cost for each product, and sum the total bill amount.
Peoples Empowerment Group
ISBM COLLEGE OF ENGINEERING, NANDE, PUNE
DEPARTMENT OF FIRST YEAR ENGINEERING
Academic Year 2024-25
6. Bill Display: The bill details are printed, showing each product's name, quantity, price,
and total cost.

Conclusion:

This experiment demonstrates how to simulate a class-like behavior in C using structures, and
how to process orders and generate a bill without using functions. The program effectively tracks
products, handles user orders, and calculates the total bill.

You might also like