Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<ctype.h>
- #include<stdbool.h>
- //#define MAX 10
- using namespace std;
- struct SymbolInfo
- {
- char name[50];
- char type[50];
- struct SymbolInfo *next;
- };
- typedef struct SymbolInfo node;
- node *head[100], *temp, *prev;
- int MAX;
- //HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);
- int getHashKey(char *name)
- {
- int index, ascii = 0;
- for(int i=0; i < strlen(name); i++)
- {
- ascii = ascii + name[i];
- }
- index = ascii % MAX;
- return index;
- }
- void Insert_Menu(char *n, char *t)
- {
- //system("cls");
- int index = getHashKey(n);
- temp = new node();
- strcpy(temp->name,n);
- strcpy(temp->type,t);
- temp->next = head[index]->next;
- head[index]->next=temp;
- //system("cls");
- //SetConsoleTextAttribute(h,FOREGROUND_INTENSITY);
- printf("\nInformation Added!\n");
- }
- void Delete_Menu(char *n, char *t)
- {
- //system("cls");
- //SetConsoleTextAttribute(h,FOREGROUND_RED);
- int flag=0;
- int index = getHashKey(n);
- prev = head[index];
- temp = head[index]->next;
- while(temp!=NULL)
- {
- if(strcmp(temp->name,n)==0&&strcmp(temp->type,t)==0)
- {
- prev->next=temp->next;
- free(temp);
- break;
- }
- temp=temp->next;
- prev=prev->next;
- }
- if(temp==NULL)
- {
- //SetConsoleTextAttribute(h,FOREGROUND_RED);
- printf("Not found");
- flag=1;
- }
- if(flag==0){
- //system("cls");
- //SetConsoleTextAttribute(h,FOREGROUND_RED);
- printf("\nInformation Deleted!\n");
- }
- }
- void Show_Menu()
- {
- //system("cls");
- int i;
- printf("______list_____\n");
- for(i=0; i<MAX; i++)
- {
- //SetConsoleTextAttribute(h,FOREGROUND_BLUE);
- printf("%d ",i);
- temp=head[i]->next;
- while(temp!=NULL)
- {
- //SetConsoleTextAttribute(h,FOREGROUND_INTENSITY);
- printf("%s,%s ",temp->name,temp->type);
- temp=temp->next;
- }
- printf("\n");
- }
- }
- void Update_Menu(char *n, char *t, char *udType)
- {
- //system("cls");
- int index = getHashKey(n);
- temp=head[index]->next;
- while(temp!=NULL)
- {
- if(strcmp(temp->name,n)==0&&strcmp(temp->type,t)==0)
- {
- strcpy(temp->type,udType);
- break;
- }
- temp=temp->next;
- }
- //system("cls");
- //SetConsoleTextAttribute(h,FOREGROUND_INTENSITY);
- printf("\nInformation Updated!\n");
- }
- bool Search_Menu(char *n, char *t)
- {
- //system("cls");
- int index = getHashKey(n);
- temp=head[index]->next;
- while(temp!=NULL)
- {
- if(strcmp(temp->name,n)==0&&strcmp(temp->type,t)==0)
- {
- return true;
- break;
- }
- temp=temp->next;
- }
- //system("cls");
- //SetConsoleTextAttribute(h,FOREGROUND_INTENSITY);
- printf("\nAfter searching!\n");
- return false;
- }
- int main()
- {
- char n[100], t[100], updType[100];
- int ch='0';
- printf("####%d",ch);
- bool TF;
- int i;
- char choice;
- printf("Enter your maximum size: ");
- scanf("%d",&MAX);
- for(i=0; i<MAX; i++)
- {
- head[i] = new node();
- head[i]->next = NULL;
- }
- while(true)
- {
- //SetConsoleTextAttribute(h,FOREGROUND_GREEN);
- fflush(stdout);
- printf("\nWelcome To Our First Assignment\n");
- printf("-- -----------------------------\n");
- printf("1 - Insert Option\n");
- printf("2 - Delete Option\n");
- printf("3 - Show Option\n");
- printf("4 - Update Option\n");
- printf("5 - Search Option\n");
- printf("-- -----------------------------\n");
- printf("Q - Quit Option\n\n");
- //SetConsoleTextAttribute(h,FOREGROUND_BLUE);
- printf("\t Enter your choice: ");
- fflush(stdin);
- choice=toupper(getchar());
- printf("\n");
- //SetConsoleTextAttribute(h,FOREGROUND_GREEN);
- switch(choice)
- {
- case '1':
- printf("-->Enter your name: ");
- scanf("%s",&n);
- printf("-->Enter your classType: ");
- scanf("%s",&t);
- Insert_Menu(n,t);
- printf("\n");
- break;
- case '2':
- printf("-->Enter the name which you want to delete: ");
- scanf("%s",&n);
- printf("-->Enter the classType which you want to delete: ");
- scanf("%s",&t);
- Delete_Menu(n,t);
- printf("\n");
- break;
- case '3':
- Show_Menu();
- printf("\n");
- break;
- case '4':
- printf("-->Enter your old name: ");
- scanf("%s",&n);
- printf("-->Enter your old classType: ");
- scanf("%s",&t);
- printf("Enter your Updated classType: ");
- scanf("%s",&updType);
- Update_Menu(n,t,updType);
- printf("\n");
- break;
- case '5':
- printf("-->Enter your searching name: ");
- scanf("%s",&n);
- printf("-->Enter your searching classType: ");
- scanf("%s",&t);
- TF = Search_Menu(n,t);
- printf("And it was ->");
- if(TF==true)
- {
- //SetConsoleTextAttribute(h,FOREGROUND_INTENSITY);
- printf("\tFound") ;
- printf("\n");
- }
- else
- {
- //SetConsoleTextAttribute(h,FOREGROUND_RED);
- printf("\tNot found");
- printf("\n");
- }
- printf("\n");
- break;
- case 'Q':
- exit(0);
- printf("\n");
- break;
- default:
- printf("Wrong Choice\n");
- printf("\n");
- break;
- }
- }while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement