Skip to content

Instantly share code, notes, and snippets.

@Akshay090
Last active October 4, 2018 17:10
Show Gist options
  • Save Akshay090/d1a0b9ae4966f22fff2fa4ed646ef2d6 to your computer and use it in GitHub Desktop.
Save Akshay090/d1a0b9ae4966f22fff2fa4ed646ef2d6 to your computer and use it in GitHub Desktop.
DS OEP
/*Meeting Management System using single linked list
Data Structures OEP
Topic - Singly Linked List
Author : Akshay Ashok , Anuj Jain , Jainal Gosaliya
*/
/*----------------------------------------------------------------------------*/
/* Define libraries to be included */
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
/*----------------------------------------------------------------------------*/
/* Define Functions*/
void clearInput(void);
void addNewMeeting(void);
void listAll(void);
void deleteMeeting(void);
void modifyMeeting(void);
int findMeeting(void);
int prompt(void);
int findnum (int);
/*----------------------------------------------------------------------------*/
/* Define Structures*/
typedef struct Meeting {
int number; /*unique account number*/
char name[20]; /*contains name*/
char time[15]; /*contains time number*/
char venue[20]; /*contains venue address*/
struct Meeting *next; /*next is used to navigate through structures.*/
int count; /*count is used to input comments into array*/
} Meeting;
Meeting *firstc,*currentc,*newc; /*pointers*/
/* firstc is used to point to first record in list
currentc points to current record in list
newc contains address of new structure/node
*/
int cnum = 0; /*gives unique account numbers*/
/*----------------------------------------------------------------------------*/
/* Main Function */
int main()
{
char ch;
firstc = NULL;
do
{
puts("\nWelcome To The Meeting Database");/* print menu messages*/
puts("-- -----------------------------");
puts("1 - Add a new Meeting");
puts("2 - Delete Meeting");
puts("3 - List all Meetings");
puts("-- -----------------------------");
puts("Q - Save and quit\n");
printf("\tYour choice:");
ch = getchar();
ch = toupper(ch);/*changes user input case to upper case*/
switch(ch) /*stores in ch variable.*/
{
case '1':
puts("Add a new Meeting\n");
addNewMeeting();//call addNewMeeting function
break;
case '2':
puts("Delete a Meeting\n");
deleteMeeting();
break;
case '3':
puts("List all Meetings\n");
listAll();
break;
case 'Q':
puts("Save and quit\n");
default:
break;
}
}
while(ch != 'Q');
}
/*----------------------------------------------------------------------------*/
void addNewMeeting(void) /* add new Meeting function*/
{
newc = (struct Meeting *)malloc(sizeof(struct Meeting));
/*allocates memory for new structure.*/
/*
* Checks to see whether this is the first record in file
* If so, then all pointers are initialized to this record,
*/
if(firstc==NULL)
firstc = currentc = newc;
/*
* if not, end of structure list is obtained
*/
else
{
currentc = firstc; /* make the first record the current one*/
while(currentc->next != NULL)currentc = currentc->next;
/* and loop through all records*/
currentc->next = newc; /* pointer to next node */
currentc = newc; /* make current record the new one*/
}
/* update the structure */
cnum++;
printf("%27s: %5i\n","Acount number",cnum);
currentc->number = cnum; /*cnum is used to give unique account numbers*/
printf("%27s: ","Enter Meeting name");
gets(currentc->name);
gets(currentc->name);
printf("%27s: ","Enter Meeting time number");
gets(currentc->time);
printf("%27s: ","Enter Meeting venue");
gets(currentc->venue);
printf("Meeting added!");
currentc->count=0;
/*
* gives the new record a NULL pointer
* to show it's the last record:
*/
currentc->next = NULL;
}
/*----------------------------------------------------------------------------*/
void listAll(void) /* list all Meetings function*/
{
if(firstc==NULL)
puts("There are no Meetings to display! Enjoy your day"); /*prints message*/
else
{
printf("%6s %-20s %-15s %-15s\n","Acct#","Name","time","venue");
puts("------ -------------------- ------------- -------------------");
/*prints table titles*/
currentc=firstc;
do
{
printf("%6d: %-20s %-15s %-20s\n",\
currentc->number,\
currentc->name,\
currentc->time,\
currentc->venue);
/*prints values of number, name, time and venue*/
}
while((currentc=currentc->next) != NULL);
}
}
/*----------------------------------------------------------------------------*/
void deleteMeeting(void) /*delete Meeting function */
{
int record;
struct Meeting *previousa;
if(firstc==NULL)
{
puts("There are no Meetings to delete!, Don't Take too much stress");
return;
}
listAll(); /* show all records*/
printf("Enter Meeting account number to delete: ");
scanf("%d",&record);
currentc = firstc;
while(currentc != NULL)
{
if(currentc->number == record)
{
if(currentc == firstc) /*if record to be deleted is the first record*/
firstc=currentc->next; /*reset firstc to point at next record as first*/
else
previousa->next = currentc->next;/*previous pointer used if record*/
/*to delete is not the first*/
free(currentc); /*frees memory <deletes>*/
printf("Meeting %d deleted!\n",record);
return;
}
else
{
previousa = currentc;
currentc = currentc->next;
}
}
printf("Meeting %d not found!\n",record);
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* END OF PROGRAM */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment