0% found this document useful (0 votes)
11 views8 pages

Computer Programming 2

The document outlines the design and implementation of a user-friendly grocery shopping cart system for Downtown Market, aimed at enhancing the shopping experience for customers and retailers. It includes objectives, algorithms, flowcharts, and code snippets for functionalities such as item selection, cart management, and bill generation with GST calculation. The system is designed to be simple and accessible for users, promoting convenience and efficiency in grocery shopping.

Uploaded by

avadhi2006
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)
11 views8 pages

Computer Programming 2

The document outlines the design and implementation of a user-friendly grocery shopping cart system for Downtown Market, aimed at enhancing the shopping experience for customers and retailers. It includes objectives, algorithms, flowcharts, and code snippets for functionalities such as item selection, cart management, and bill generation with GST calculation. The system is designed to be simple and accessible for users, promoting convenience and efficiency in grocery shopping.

Uploaded by

avadhi2006
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/ 8

WELCOME TO DOWNTOWN

MARKET!
-​ 24BCS012 Avadhi Talera
-​ 24BCS071 Sanjini Shukla

Semester - 2
1CS504CC22 Computer Programming 2
Bachelor of Sciences CSE (2+2)

Table of Content

Introduction

Objectives

Algorithm

Flowchart

Implementation

Results

Introduction
An effective and user-friendly grocery shopping cart enhances the shopping
experience for customers and benefits retailers by promoting convenience,
efficiency, and satisfaction.
For Customers its about:
-​ Convenience
-​ Accessibility
-​ Efficiency
For Retailers it’s about:
-​ Customer satisfaction
-​ Adaptability
-​ Promotes eco-friendly usage

The downtown market interface helps in going back to the page and easily
adding the items as well as the quantity.
This interface also adds the GST to the total bill. Also adds a copy of the bill to
bill.txt file

Objectives
Making it User Friendly
The objective of this is to make grocery shopping easy and in the most
efficient way

Easy To operate for anyone


This can be used by anyone as it is very easy to operate with simple
instructions.

Algorithm
1. Program Entry: main()
-​ Prints a welcome message.
-​ Calls showCategories() to start the menu-driven item selection
process.
2. Function: showCategories()
-​ A while (1) loop repeatedly displays a menu:
1] Fruits and Vegetables
2] Snacks
3] Wellness
4] Show Bill
5] Exit​
-​ Based on the user’s input (choice), different functions are called:
-​ Choice​ Action
-​ 1​ Calls purchaseItem() for Orange, Apple, Potato
-​ 2​ Calls purchaseItem() for Chips, Noodles, Fries
-​ 3​ Calls purchaseItem() for Vicks, Bandaid, Dettol
-​ 4​ Calls showBill() to print and save bill
-​ 5​ Exits the loop with a thank-you message
-​ Other​Prints "Invalid choice!" and loops again

3. Function: purchaseItem(const char* name, int price)


-​ Asks the user how many units of a specific item they want.
-​ Reads the quantity using scanf().
-​ Calls addToCart() with the name, price, and quantity.
4. Function: addToCart()
-​ Dynamically allocates memory for a new item.
-​ Fills in its fields: name, price, quantity.
-​ Inserts it at the beginning of the cart linked list.
-​ Updates totalCost += price * quantity.
-​ Prints a message confirming addition to the cart.
5. Function: showBill()
-​ Opens bill.txt in write mode.
-​ If the file fails to open, prints an error and returns.
-​ Otherwise:
Prints and writes a table of all items in the cart (from the linked list).
-​ Calculates:
GST = 18% of totalCost
-​ Final total = totalCost + GST
-​ Displays and writes the GST and final total.
-​ Closes the file and confirms bill saving.

Data Structures Used


CartItem (Struct):
typedef struct CartItem {
char name[30];
int price;
int quantity;
struct CartItem* next;
} CartItem;

A linked list node storing an item’s name, price, quantity, and pointer to the
next item.
Global Variables:
CartItem* cart = NULL; → head of the linked list (cart)
int totalCost = 0; → total cart value before GST

Flowchart
Code input
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Structure for an item in the cart


typedef struct CartItem {
char name[30];
int price;
int quantity;
struct CartItem* next;
} CartItem;

CartItem* cart = NULL;


int totalCost = 0;

// Function to add an item to the cart


void addToCart(const char* name, int price, int quantity) {
CartItem* newItem = (CartItem*)malloc(sizeof(CartItem));
strcpy(newItem->name, name);
newItem->price = price;
newItem->quantity = quantity;
newItem->next = cart;
cart = newItem;
totalCost += price * quantity;
printf("[%d] %s %d Rs has been added to your cart.\n", quantity, name,
price);
}

// Function to display and save the bill to a file


void showBill() {
FILE *file = fopen("bill.txt", "w");
if (!file) {
printf("Error opening file for writing.\n");
return;
}

printf("\nItem\tName\tPrice\tQuantity\tTotal\n");
fprintf(file, "Item\tName\tPrice\tQuantity\tTotal\n");

CartItem* temp = cart;


int i = 1;
while (temp) {
printf("%d\t%s\t%d\t%d\t%d\n", i, temp->name, temp->price,
temp->quantity, temp->price * temp->quantity);
fprintf(file, "%d\t%s\t%d\t%d\t%d\n", i, temp->name, temp->price,
temp->quantity, temp->price * temp->quantity);
temp = temp->next;
i++;
}
float gst = totalCost * 0.18;
float finalTotal = totalCost + gst;
printf("\t\t\t\t GST on cart = %.2f\n", gst);
printf("Total Bill with GST: %.2f\n", finalTotal);

fprintf(file, "\t\t\t\t GST on cart = %.2f\n", gst);


fprintf(file, "Total Bill with GST: %.2f\n", finalTotal);
fclose(file);

printf("Bill has been saved to bill.txt\n");


}

// Function to handle purchasing items


void purchaseItem(const char* name, int price) {
int quantity;
printf("How many %s would you like to buy? ", name);
scanf("%d", &quantity);
addToCart(name, price, quantity);
}
// Function to display categories and items
void showCategories() {
int choice;
while (1) {
printf("\n1] Fruits and Vegetables\n2] Snacks\n3] Wellness\n4] Show
Bill\n5] Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
purchaseItem("Orange", 70);
purchaseItem("Apple", 100);
purchaseItem("Potato", 20);
break;
case 2:
purchaseItem("Chips", 20);
purchaseItem("Noodles", 50);
purchaseItem("Fries", 100);
break;
case 3:
purchaseItem("Vicks", 30);
purchaseItem("Bandaid", 15);
purchaseItem("Dettol", 40);
break;
case 4:
showBill();
break;
case 5:
printf("Hope to see you again!\n");
return;
default:
printf("Invalid choice! Try again.\n");
}
}
}
int main() {
printf("Welcome to Downtown Mart!\n");
showCategories();
return 0;
}

Code output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy