Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include <stdlib.h>
- typedef struct Node
- {
- char code[20];
- char type[20];
- char name[20];
- int price;
- int num;
- char date[20];
- struct Node *next;
- } node;
- int t=0;
- void insert_after(node *p,char name[20],char code[20],int num,char type[20],int price,char ex_date[20])
- {
- while(p->next != NULL)
- {
- p = p->next;
- }
- p->next = (node *)malloc(sizeof(node));
- strcpy(p->next->name,name);
- strcpy(p->next->code,code);
- p->next->num = num;
- strcpy(p->next->type,type);
- p->next->price = price;
- strcpy(p->next->date,ex_date);
- p->next->next = NULL;
- }
- /*void insert_first(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
- {
- node *temp;
- temp = (node *)malloc(sizeof(node));
- strcpy(temp->name,name);
- strcpy(temp->id,id);
- strcpy(temp->dept,dept);
- strcpy(temp->bg,bg);
- strcpy(temp->phone,cont);
- temp->next = p->next;
- p->next = temp;
- }
- void edit_data(node *p,char id[])
- {
- int n,ct=0;
- char name1[20];
- char id1[20];
- char dept1[20];
- char bg1[20];
- char phone1[20];
- //node *temp = search(p,id);
- p = p->next;
- while(p != NULL)
- {
- if(strcmp(p->id,id) == 0)
- {
- printf("\n****Student's Data To Edit****\n");
- printf("1.Student name : %s\n", p->name);
- printf("2.Student ID : %s\n", p->id);
- printf("3.Student Department : %s\n", p->dept);
- printf("4.Student Blood group: %s\n", p->bg);
- printf("5.Student Contact : %s\n\n",p->phone);
- printf("Select your option to Edit: ");
- scanf("%d",&n);
- if(n == 1)
- {
- printf("Enter the name: ");
- scanf(" %[^\n]s",name1);
- strcpy(p->name,name1);
- }
- else if(n == 2)
- {
- printf("Enter the ID: ");
- scanf(" %s",id1);
- strcpy(p->id,id1);
- }
- else if(n == 3)
- {
- printf("Enter the Department: ");
- scanf("%s",dept1);
- strcpy(p->dept,dept1);
- }
- else if(n == 4)
- {
- printf("Enter the Blood Group: ");
- scanf("%s",bg1);
- strcpy(p->bg,bg1);
- }
- else if(n == 5)
- {
- printf("Enter the Contact: ");
- scanf("%s",phone1);
- strcpy(p->phone,phone1);
- }
- else
- {
- printf("\nError Selection!!\n");
- }
- }
- ct++;
- p = p -> next;
- }
- if(ct == 0)
- printf("\nElement not Found!\n");
- }
- int search(node *p, char id[20])
- {
- p = p->next;
- while(p != NULL)
- {
- if(strcmp(p->id,id) == 0)
- {
- printf("\n****Displaying Searched Information****\n");
- printf("Student name : %s\n", p->name);
- printf("Student ID : %s\n", p->id);
- printf("Student Department : %s\n", p->dept);
- printf("Student Blood group: %s\n", p->bg);
- printf("Student Contact : %s\n\n",p->phone);
- return;
- }
- p = p -> next;
- }
- printf("Sorry!Element not found.\n");
- return;
- }
- void blood_grp(node *p, char bg[5])
- {
- int ct=0;
- p = p->next;
- printf("\n****Information of Desired Blood Group****\n");
- while(p != NULL)
- {
- if(strcmp(p->bg,bg)==0)
- {
- ct++;
- printf("\nStudent Name : %s\n",p->name);
- printf("Blood Group : %s\n",p->bg);
- printf("Contact number: %s\n",p->phone);
- }
- p = p->next;
- }
- if(ct == 0)
- printf("\nNot found\n");
- }
- void dept_search(node *p, char dept[20])
- {
- int ct=0;
- p = p->next;
- printf("\n****Department Wise Student Information****\n\n");
- while(p != NULL)
- {
- if(strcmp(p->dept,dept)==0)
- {
- ct++;
- printf("Student name : %s\n", p->name);
- printf("Student ID : %s\n", p->id);
- printf("Student Department : %s\n", p->dept);
- printf("Student Blood group: %s\n", p->bg);
- printf("Student Contact : %s\n\n", p->phone);
- }
- p = p->next;
- }
- if(ct == 0)
- printf("\nNot found\n");
- }*/
- int sold(node *p, char code[20],int pc)
- {
- int ct=0,sum=0;
- //node *temp;
- while(p->next != NULL)
- {
- if(strcmp(p->next->code,code) == 0)
- {
- for(int i=0; i<pc; i++){
- sum = sum + p->next->price;
- }
- p->next->num = p->next->num - pc;
- return sum;
- }
- p = p->next;
- }
- if(ct == 0)
- {
- printf("Element Not Found!!\n");
- }
- }
- void display(node *p)
- {
- while(p -> next != NULL)
- {
- printf("Product name : %s\n", p->next->name);
- printf("Product CODE : %s\n", p->next->code);
- printf("Number of Products : %d Pieces\n",p->next->num);
- printf("Product TYPE : %s\n", p->next->type);
- printf("Product PRICE : %d\n", p->next->price);
- printf("Product EXPIRED DATE: %s\n\n", p->next->date);
- //printf("Student name: %s\n", p->next->name);
- p = p->next;
- }
- }
- int total(int sum)
- {
- t = t + sum;
- return t;
- }
- int main()
- {
- int n,p,s;
- char q;
- char name[20];
- char code[20];
- char type[20];
- int num;
- int price;
- char ex_date[20];
- node *start = (node *)malloc(sizeof(node));
- start -> next = NULL;
- while(1)
- {
- printf("\n\n1. Insert Product data\n");
- printf("2. Buyer's BILL\n");
- printf("3. Display\n");
- printf("4. Total SALE\n");
- printf("5. Insert at first\n");
- printf("6. Edit Student information\n");
- printf("7. Search Blood Group\n");
- printf("8. Search Department\n");
- printf("\nEnter your choice: ");
- scanf(" %c",&q);
- switch(q)
- {
- case '1':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\n\nEnter Product information\n\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter CODE: ");
- scanf("%s", code);
- printf("Number of product: ");
- scanf("%d",&num);
- printf("Enter Product Type: ");
- scanf(" %s", type);
- printf("Enter Product Price: ");
- scanf("%d", &price);
- printf("Enter Product Expired Date: ");
- scanf(" %s", ex_date);
- insert_after(start,name,code,num,type,price,ex_date);
- }
- break;
- case '2':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("Enter the Numbers of Sold product: ");
- scanf("%d",&n);
- int sum =0;
- for(int i=0; i<n; i++){
- printf("Enter the Product code: ");
- scanf("%s", code);
- printf("How many pieces? :- ");
- scanf("%d",&p);
- sum = sum+ sold(start,code,p);
- }
- total(sum);
- printf("Total BILL: %d taka\n",sum);
- }
- break;
- case '3':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\n\n****Product's information****\n\n");
- display(start);
- }
- break;
- case '4':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("Total Daily SALE: %d\n",t);
- }
- break;
- /*case '4':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("Enter the ID: ");
- scanf("%s",id);
- search(start,id);
- }
- break;
- case '5':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\n\nEnter student information\n\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter ID: ");
- scanf("%s", id);
- printf("Enter Department: ");
- scanf(" %[^\n]s", dept);
- printf("Enter Blood Group: ");
- scanf("%s", bg);
- printf("Enter contact: ");
- scanf("%s", phone);
- insert_first(start,name,id,dept,bg,phone);
- }
- break;
- case '6':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\nEnter the ID to Edit data: ");
- scanf("%s",id);
- edit_data(start,id);
- }
- break;
- case '7':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\nEnter the desired Blood Group: ");
- scanf("%s",bg);
- blood_grp(start,bg);
- }
- break;
- case '8':
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\nEnter Department Name: ");
- scanf("%s",dept);
- dept_search(start,dept);
- }
- break;*/
- default:
- printf("Invalid choice.Try again!\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment