Module 1 Customer Managment
Module 1 Customer Managment
1.4 Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_CUSTOMERS 50
struct Customer {
char name[50];
int id;
float totalSpent;
};
void manageCustomers() {
char name[50];
int productID, quantity;
float total = 0;
displayProducts();
printf("\nEnter your name: ");
scanf("%s", name);
while (1) {
printf("Enter product ID to buy (0 to finish): ");
scanf("%d", &productID);
if (productID == 0) break;
if (productID > 0 && productID <= productCount) {
printf("Enter quantity: ");
scanf("%d", &quantity);
if (quantity <= products[productID - 1].quantity) {
float price = quantity * products[productID - 1].price;
total += price;
products[productID - 1].quantity -= quantity;
printf("Added to cart: %s x%d = %.2f\n", products[productID - 1].name, quantity,
price);
} else {
printf("Insufficient stock.\n");
}
} else {
printf("Invalid product ID.\n");
}
}
printf("\nTotal bill for %s: %.2f\n", name, total);
totalSales += total;
printf("\nTHANK YOU Dear Customer\n");
}
1.5 Input and Output
Input
Output
END
2.3 Flowchart
2.4 Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void addProduct() {
printf("\nEnter Product ID: ");
scanf("%d", &products[productCount].id);
printf("Enter Product Name: ");
scanf(" %[^\n]", products[productCount].name);
printf("Enter Product Price: ");
scanf("%f", &products[productCount].price);
printf("Enter Product Quantity: ");
scanf("%d", &products[productCount].quantity);
productCount++;
printf("Product added successfully!\n");
}
void viewProducts() {
printf("\nProduct List:\n");
printf("ID\tName\t\tPrice\tQuantity\n");
for (int i = 0; i < productCount; i++) {
printf("%d\t%s\t\t%.2f\t%d\n", products[i].id, products[i].name, products[i].price,
products[i].quantity);
}
}
void searchProduct() {
char searchName[50];
printf("\nEnter product name to search: ");
scanf(" %[^\n]", searchName);
int found = 0;
for (int i = 0; i < productCount; i++) {
if (strcmp(products[i].name, searchName) == 0) {
printf("Product Found: ID: %d, Name: %s, Price: %.2f, Quantity: %d\n",
products[i].id, products[i].name, products[i].price, products[i].quantity);
found = 1;
}
}
if (!found)
printf("Product not found.\n");
}
void updateProduct() {
int id;
printf("\nEnter Product ID to update: ");
scanf("%d", &id);
for (int i = 0; i < productCount; i++) {
if (products[i].id == id) {
printf("Enter new name: ");
scanf(" %[^\n]", products[i].name);
printf("Enter new price: ");
scanf("%f", &products[i].price);
printf("Enter new quantity: ");
scanf("%d", &products[i].quantity);
printf("Product updated!\n");
return;
}
}
printf("Product with ID %d not found.\n", id);
}
void lowStockAlert() {
printf("\nProducts with low stock (less than 10):\n");
for (int i = 0; i < productCount; i++) {
if (products[i].quantity < 10) {
printf("ID: %d, Name: %s, Quantity: %d\n", products[i].id, products[i].name,
products[i].quantity);
}
}
}
int main() {
int choice;
while (1) {
printf("\n--- Product Management Menu ---\n");
printf("1. View Products\n2. Add Product\n3. Search Product\n4. Update Product\n5.
Low Stock Alert\n6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: viewProducts(); break;
case 2: addProduct(); break;
case 3: searchProduct(); break;
case 4: updateProduct(); break;
case 5: lowStockAlert(); break;
case 6: return 0;
default: printf("Invalid choice!\n");
}
}
return 0;
}
2.5 Input and Output
3.3 Flowchart
3.4 Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_EMPLOYEES 20
struct Employee {
int id;
char name[50];
char position[50];
float salary;
};
void addEmployee() {
printf("\nEnter Employee ID: ");
scanf("%d", &employees[empCount].id);
printf("Enter Name: ");
scanf(" %[^\n]", employees[empCount].name);
printf("Enter Position: ");
scanf(" %[^\n]", employees[empCount].position);
printf("Enter Salary: ");
scanf("%f", &employees[empCount].salary);
empCount++;
printf("Employee added successfully!\n");
}
void viewEmployees() {
printf("\n--- Employee List ---\n");
for(int i = 0; i < empCount; i++) {
printf("ID: %d, Name: %s, Position: %s, Salary: %.2f\n",
employees[i].id,
employees[i].name,
employees[i].position,
employees[i].salary);
}
}
void searchEmployee() {
int id;
printf("\nEnter Employee ID to Search: ");
scanf("%d", &id);
for(int i = 0; i < empCount; i++) {
if(employees[i].id == id) {
printf("ID: %d, Name: %s, Position: %s, Salary: %.2f\n",
employees[i].id,
employees[i].name,
employees[i].position,
employees[i].salary);
return;
}
}
printf("Employee not found.\n");
}
void updateEmployee() {
int id;
printf("\nEnter Employee ID to Update: ");
scanf("%d", &id);
for(int i = 0; i < empCount; i++) {
if(employees[i].id == id) {
printf("Enter New Name: ");
scanf(" %[^\n]", employees[i].name);
printf("Enter New Position: ");
scanf(" %[^\n]", employees[i].position);
printf("Enter New Salary: ");
scanf("%f", &employees[i].salary);
printf("Employee updated successfully.\n");
return;
}
}
printf("Employee not found.\n");
}
void deleteEmployee() {
int id;
printf("\nEnter Employee ID to Delete: ");
scanf("%d", &id);
for(int i = 0; i < empCount; i++) {
if(employees[i].id == id) {
for(int j = i; j < empCount - 1; j++) {
employees[j] = employees[j + 1];
}
empCount--;
printf("Employee deleted successfully.\n");
return;
}
}
printf("Employee not found.\n");
}
void employeeManagementMenu() {
int choice;
do {
printf("\n--- Employee Management Menu ---\n");
printf("1. Add Employee\n2. View Employees\n3. Search Employee\n4. Update
Employee\n5. Delete Employee\n6. Back\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch(choice) {
case 1: addEmployee(); break;
case 2: viewEmployees(); break;
case 3: searchEmployee(); break;
case 4: updateEmployee(); break;
case 5: deleteEmployee(); break;
case 6: printf("Returning to Main Menu...\n"); break;
default: printf("Invalid choice!\n");
}
} while(choice != 6);
}
Input
Output