Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <malloc.h>
- #include <string.h>
- void clrscr() {
- system("@cls||clear");
- }
- struct node {
- struct node *next;
- char name[30];
- int qty;
- char type[5];
- int price;
- };
- struct node *start = NULL;
- struct node *create_ll(struct node*);
- struct node *display(struct node*);
- struct node *insert_end(struct node*);
- struct node *delete_beg(struct node*);
- void menu() {
- printf("COOL COMPUTER ADMINSTRATOR\n");
- printf("++++++++++++++++++++++++++\n\n");
- printf("1. Item List\n");
- printf("2. Add <push> new item\n");
- printf("3. Delete <pop> recently added item\n");
- printf("4. Exit\n\n");
- printf("> Input your choice : ");
- }
- int main() {
- int choice;
- do {
- clrscr();
- menu();
- scanf("%d", &choice);
- switch(choice) {
- case 1: {
- clrscr();
- start = display(start);
- getch();
- break;
- }
- case 2: {
- clrscr();
- start = create_ll(start);
- printf("\n--- Item was sucessfully added! ---");
- getch();
- break;
- }
- case 3: {
- break;
- }
- }
- } while (choice != 4);
- }
- struct node *create_ll(struct node *start) {
- struct node *new_node, *ptr;
- char nname[20], ttype[20];
- int qqty, pprice;
- int tc = 0;
- do {
- printf("> Input name [3...20] :");
- fflush(stdin);
- scanf("%[^\n]", &nname);
- } while (strlen(nname) < 3 || strlen(nname) > 20);
- do {
- printf("\n> Input type [processor/graphic card/memory] : ");
- scanf("%s", &ttype);
- if (strcmp("processor", ttype) == 0) {
- tc = 1;
- } else if (strcmp("graphic card", ttype) == 0) {
- tc = 1;
- } else if (strcmp("memory", ttype) == 0) {
- tc = 1;
- } else {
- tc = 0;
- }
- } while (tc == 0);
- do {
- printf("\n> Input quantity [1...20] : ");
- scanf("%d", &qqty);
- } while (qqty < 4 || qqty > 20);
- do {
- printf("\n > Input price [$1...$1000]: ");
- scanf("%d", &pprice);
- } while (pprice < 1 || pprice > 1000);
- new_node = (struct node* ) malloc(sizeof(struct node));
- strcpy(new_node -> name, nname);
- new_node -> qty = qqty;
- strcpy(new_node -> type, ttype);
- new_node -> price = pprice;
- if (start == NULL) {
- new_node -> next = NULL;
- start = new_node;
- } else {
- ptr = start;
- while (ptr -> next != NULL) {
- ptr = ptr -> next;
- }
- ptr -> next = new_node;
- new_node -> next = NULL;
- }
- return start;
- }
- struct node * display(struct node *start) {
- int no=1;
- struct node *ptr;
- ptr = start;
- clrscr();
- printf("\t\t--- ITEM LIST ---\n\n");
- printf("------+-------------------+---------------+----------+-------+\n");
- printf("| No. | Name | Type | Quantity | Price |\n");
- printf("------+-------------------+---------------+----------+-------+\n");
- while (ptr != NULL) {
- printf("|");
- printf(" %-4d|", no);
- printf(" %-18s|", ptr -> name);
- printf(" %-18s|", ptr -> type);
- printf(" %-9d|", ptr -> qty);
- printf(" %-6d|\n", ptr -> price);
- ptr = ptr -> next;
- no++;
- }
- printf("------+-------------------+--------+----------+-------+\n");
- return start;
- }
Advertisement
Add Comment
Please, Sign In to add comment