Database Operations without pointers
Objective
Program for Operations on a database without using pointers. This program in c/c++ will simulate database operations such as create record, insert, delete, search, print, sort and modify records using simple menu interface which is provided to interact with the program.
Program developed using c/c++ starts with menu options where user can provide data such as employee details. User needs to provide number of employees we want to insert into the database. After entering number of employees we want to insert user can provide data inform of employee name, employee id, salary for particular employee. As soon as entered is pressed record will be inserted into database.
For more c programs check here.
1 |
<span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;"> #include <br/> #include <br/> #include <br/> typedef struct employee <br/> { int code; <br/> char name[20]; <br/> int salary; <br/> }employee; <br/> void insert(employee st[],int position,int n); <br/> void Delete(employee st[],int position,int n); <br/> int search(employee st[],int code,int n); <br/> void print(employee st[],int n); <br/> void read(employee st[],int n); <br/> void sort(employee st[],int n); <br/> void modify(employee st[],int n); <br/> void main() <br/> { employee st[30]; <br/> int n,i,op,position,code; <br/> clrscr(); <br/> do{ <br/> flushall(); <br/> printf("\n1)create\n2)insert\n3)delete\n4)search\n5)print\n6)Sort\n7)Modify"); <br/> printf("\n8)Quit"); <br/> printf("\nEnter Your Choice:"); <br/> scanf("%d",&op); <br/> switch(op) <br/> { case 1: printf("\nEnter No. of employees:"); <br/> scanf("%d",&n); <br/> read(st,n); <br/> break; <br/> case 2: printf("\n enter the position(no of records=%d):",n); <br/> scanf("%d",&position); <br/> if(position<=n+1) <br/> { <br/> insert(st,position,n); <br/> n++; <br/> print(st,n); <br/> } <br/> else <br/> printf("\n can not insert"); <br/> break; <br/> case 3:printf("\n enter the code : "); <br/> scanf("%d",&code); <br/> position=search(st,code,n); <br/> if(position != -1 ) <br/> { <br/> Delete(st,position,n); <br/> n--; <br/> print(st,n); <br/> } <br/> else <br/> printf("\n can not delete "); <br/> break; <br/> case 4: printf("\nenter code:"); <br/> scanf("%d",&code); <br/> position=search(st,code,n); <br/> if(position==-1) <br/> printf("\nnot found"); <br/> else <br/> { printf("\n found at location=%d",position+1); <br/> printf("\n %s\t%d\t%d",st[position].name,st[position].code,st[position].salary); <br/> } <br/> break; <br/> case 5: print(st,n); <br/> break; <br/> case 6: sort(st,n);print(st,n);break; <br/> case 7: modify(st,n);print(st,n);break; <br/> } <br/> }while(op!=8); <br/> } <br/> void insert( employee st[],int position,int n) <br/> { int i; <br/> printf("\n enter data(name code salary): "); <br/> for(i=n-1;i>=position-1;i--) /*index is 1 less than position*/ <br/> st[i+1]=st[i]; <br/> scanf("%s%d%d",st[position-1].name,&st[position-1].code,&st[position-1].salary); <br/> } <br/> void Delete(employee st[],int position,int n) <br/> { int i; <br/> for(i=position+1;i st[j+1].code) <br/> { <br/> temp=st[j]; <br/> st[j]=st[j+1]; <br/> st[j+1]=temp; <br/> } <br/> } <br/></span> |
Output
1 2 |
<span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:1</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter No. of employees:2</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter data(name code salary): John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Jenny 2 3000</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:2</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter the position(no of records=2):3</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter data(name code salary): Merry 3 5000</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Jenny 2 3000</span><br/><span style="font-family: 'times ne w roman', times, serif; font-size: 14pt; color: #000000;">Merry 3 5000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:3</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter the code : 2</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Merry 3 5000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:4</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter code:3</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">found at location=2</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Merry 3 5000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:5</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Merry 3 5000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:6</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Merry 3 5000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter Your Choice:7</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter the code : 3</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">enter data(name code salary): Diya 5 4000</span><br/><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">John 1 2000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Diya 5 4000</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">1)create</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">2)insert</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">3)delete</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">4)search</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">5)print</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">6)Sort</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">7)Modify</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">8)Quit</span><br/><span style="font-family: 'times new roman', times, serif; font-size: 14pt; color: #000000;">Enter the code : 8</span><br/><br/> |
Source projectgeek.com