1: /*
2: ==============================================================
3: Name : Mobile Information
4: Author : Shivkumar, Mujahid
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<string.h>
12: typedef struct mobile
13: {
14: char mobile_no[11];
15: int bal;
16: char name[20];
17: }mobile;
18: void creat(mobile st[],int n);
19: void insert(mobile st[],int position,int n);
20: void del(mobile st[],int position,int n);
21: int search(mobile st[],char mobile_no[],int n);
22: void print(mobile st[],int n);
23: void sort_bal(mobile st[],int n);
24: void sort_name(mobile st[],int n);
25: void modify(mobile st[],int n);
26: /*---- Main Function ----*/
27: void main()
28: {
29: mobile st[20];
30: int n,position,choice,count;
31: char mobile_no[15];
32: printf("\nEnter number of mobile: ");
33: scanf("%d",&n);
34: creat(st,n);
35: print(st,n);
36: do
37: {
38: printf("--------------------------------------------------------------");
39: printf("\nChoose the operation which do you want to perform: ");
40: printf("\n 1.Insert\n 2.Print\n 3.Delete\n 4.Search\n 5.Sort By bal(Descending Order)\n ");
41: printf("6.Sort By Name(Ascending Order)\n 7.Modify\n");
42: printf("Your choice is: ");
43: scanf("%d",&choice);
44: switch(choice)
45: {
46: case 1:
47: printf("\nEnter the position where you want to insert mobile user information: ");
48: scanf("%d",&position);
49: if(position<=n+1)
50: {
51: insert(st,position,n);
52: n++;
53: printf("\nEntered mobile user Information");
54: print(st,n);
55: }
56: else
57: printf("\nCan not insert");
58: break;
59: case 2:
60: printf("\nEntered mobile user Information");
61: print(st,n);
62: break;
63: case 3:
64: printf("\nEnter the mobile no: ");
65: scanf("%s",mobile_no);
66: position=search(st,mobile_no,n);
67: if(position!=-1)
68: {
69: del(st,position,n);
70: n--;
71: printf("\nEntered mobile user Information");
72: print(st,n);
73: }
74: else
75: printf("Can not be delete");
76: break;
77: case 4:
78: printf("\nEnter the mobile no: ");
79: scanf("%s",mobile_no);
80: position=search(st,mobile_no,n);
81: if(position==-1)
82: printf("Not found...");
83: else
84: {
85: printf("\nFound at location= %d",position+1);
86: printf("\n%s\t%s\t%d",st[position].name,st[position].mobile_no,st[position].bal);
87: }
88: break;
89: case 5:
90: sort_bal(st,n);
91: break;
92: case 6:
93: sort_name(st,n);
94: break;
95: case 7:
96: modify(st,n);
97: printf("\nModified mobile user Information");
98: print(st,n);
99: break;
100: default:
101: printf("Invalid choice....!!");
102: break;
103: }
104: printf("\n\n Enter your choice:");
105: printf("\n Do you want to continue or not??? (1/0): ");
106: scanf("%d",&count);
107: }while(count==1);
108: }
109: /*---- Creat Function ------*/
110: void creat(mobile st[],int n)
111: {
112: int i;
113: printf("\nEnter data:\n (name,mobile no,bill amount)\n");
114: for(i=0;i<n;i++)
115: scanf("%s%s%d",st[i].name,st[i].mobile_no,&st[i].bal);
116: }
117: /*----- Insert Function ----*/
118: void insert(mobile st[],int position,int n)
119: {
120: int i;
121: printf("\nEnter data:\n (name,mobile no,bill amount)\n");
122: for(i=n-1;i>=position-1;i--)
123: st[i+1]=st[i];
124: scanf("%s%s%d",st[position-1].name,st[position-1].mobile_no,&st[position-1].bal);
125: }
126: /*----- Delete Function ----*/
127: void del(mobile st[],int position,int n)
128: {
129: int i;
130: for(i=position+1;i<n;i++)
131: st[i-1]=st[i];
132: }
133: /*----Search Functin ---*/
134: int search(mobile st[],char mobile_no[],int n)
135: {
136: int i;
137: for(i=0;i<n;i++)
138: if(strcmp(st[i].mobile_no,mobile_no)==0)
139: return i;
140: return(-1);
141: }
142: /*---- Print Function -----*/
143: void print(mobile st[],int n)
144: {
145: int i;
146: printf("\n_____________________________________");
147: printf("\nName\tMobile No\tBill Amount");
148: printf("\n_____________________________________");
149: for(i=0;i<n;i++)
150: printf("\n%s\t%s\t%d",st[i].name,st[i].mobile_no,st[i].bal);
151: printf("\n_____________________________________\n");
152: }
153: /*---- bal Sort Function ---*/
154: void sort_bal(mobile st[],int n)
155: {
156: int i,j,passes=0,comparisons=0;
157: mobile temp;
158: for(i=1;i<n;i++)
159: {
160: for(j=0;j<n-i;j++)
161: {
162: comparisons++;
163: if(st[j].bal<st[j+1].bal)
164: {
165: temp=st[j];
166: st[j]=st[j+1];
167: st[j+1]=temp;
168: passes++;
169: }
170: }
171: }
172: printf("\nSorted mobile Information By Bill Amount: ");
173: print(st,n);
174: printf("\n\nPasses: %d \tComparisons: %d",passes,comparisons);
175: if(passes==0)
176: printf("\nBest case...!!!");
177: else if(0<passes && passes<n)
178: printf("\nAverage case...!!!");
179: else if(passes>=n)
180: printf("\nWorst case...!!!");
181: }
182: /*---- Nmae Sort Function ---*/
183: void sort_name(mobile st[],int n)
184: {
185: int i,j,k=0,passes=0,comparisons=0;
186: mobile temp;
187: for(i=0;i<n-1;i++)
188: {
189: k=i;
190: for(j=i+1;j<n;j++)
191: {
192: comparisons++;
193: if(strcmp(st[j].name,st[k].name)<0)
194: {
195: k=j;
196: temp=*(st+i);
197: *(st+i)=*(st+k);
198: *(st+k)=temp;
199: passes++;
200: }
201: }
202: }
203: printf("\nSorted mobile Information By Name: ");
204: print(st,n);
205: printf("\n\nPasses: %d \tComparisons: %d",passes,comparisons);
206: if(passes==0)
207: printf("\nBest case...!!!");
208: else if(0<passes && passes<n)
209: printf("\nAverage case...!!!");
210: else if(passes>=n)
211: printf("\nWorst case...!!!");
212: }
213: /*---- Modify Function ----*/
214: void modify(mobile st[],int n)
215: {
216: int i;
217: char mobile_no[15];
218: printf("Enter the mobile no: ");
219: scanf("%s",mobile_no);
220: i=search(st,mobile_no,n);
221: if(i==(-1))
222: printf("No such mobile no number...!!!!");
223: else
224: {
225: scanf("%s%s%d",st[i].name,st[i].mobile_no,&st[i].bal);
226: }
227: }
228: ---------------OUTPUT----------------
229: Enter number of mobile: 3
230: Enter data:
231: (name,mobile no,bill amount)
232: shivkumar 8007921033 250
233: mujahid 9856478596 300
234: pradip 8253691453 200
235: _____________________________________
236: Name Mobile No Bill Amount
237: _____________________________________
238: shivkumar 8007921033 250
239: mujahid 9856478596 300
240: pradip 8253691453 200
241: _____________________________________
242: --------------------------------------------------------------
243: Choose the operation which do you want to perform:
244: 1.Insert
245: 2.Print
246: 3.Delete
247: 4.Search
248: 5.Sort By bal(Descending Order)
249: 6.Sort By Name(Ascending Order)
250: 7.Modify
251: Your choice is: 1
252: Enter the position where you want to insert mobile user information: 4
253: Enter data:
254: (name,mobile no,bill amount)
255: anonyomus 8000000003 500
256: Entered mobile user Information
257: _____________________________________
258: Name Mobile No Bill Amount
259: _____________________________________
260: shivkumar 8007921033 250
261: mujahid 9856478596 300
262: pradip 8253691453 200
263: anonyomus 8000000003 500
264: _____________________________________
265: Enter your choice:
266: Do you want to continue or not??? (1/0): 1
267: --------------------------------------------------------------
268: Choose the operation which do you want to perform:
269: 1.Insert
270: 2.Print
271: 3.Delete
272: 4.Search
273: 5.Sort By bal(Descending Order)
274: 6.Sort By Name(Ascending Order)
275: 7.Modify
276: Your choice is: 3
277: Enter the mobile no: 8000000003
278: Entered mobile user Information
279: _____________________________________
280: Name Mobile No Bill Amount
281: _____________________________________
282: shivkumar 8007921033 250
283: mujahid 9856478596 300
284: pradip 8253691453 200
285: _____________________________________
286: Enter your choice:
287: Do you want to continue or not??? (1/0): 1
288: --------------------------------------------------------------
289: Choose the operation which do you want to perform:
290: 1.Insert
291: 2.Print
292: 3.Delete
293: 4.Search
294: 5.Sort By bal(Descending Order)
295: 6.Sort By Name(Ascending Order)
296: 7.Modify
297: Your choice is: 4
298: Enter the mobile no: 8007921033
299: Found at location= 1
300: shivkumar 8007921033 250
301: Enter your choice:
302: Do you want to continue or not??? (1/0): 1
303: --------------------------------------------------------------
304: Choose the operation which do you want to perform:
305: 1.Insert
306: 2.Print
307: 3.Delete
308: 4.Search
309: 5.Sort By bal(Descending Order)
310: 6.Sort By Name(Ascending Order)
311: 7.Modify
312: Your choice is: 5
313: Sorted mobile Information By Bill Amount:
314: _____________________________________
315: Name Mobile No Bill Amount
316: _____________________________________
317: mujahid 9856478596 300
318: shivkumar 8007921033 250
319: pradip 8253691453 200
320: _____________________________________
321: Passes: 1 Comparisons: 3
322: Average case...!!!
323: Enter your choice:
324: Do you want to continue or not??? (1/0): 1
325: --------------------------------------------------------------
326: Choose the operation which do you want to perform:
327: 1.Insert
328: 2.Print
329: 3.Delete
330: 4.Search
331: 5.Sort By bal(Descending Order)
332: 6.Sort By Name(Ascending Order)
333: 7.Modify
334: Your choice is: 6
335: Sorted mobile Information By Name:
336: _____________________________________
337: Name Mobile No Bill Amount
338: _____________________________________
339: mujahid 9856478596 300
340: pradip 8253691453 200
341: shivkumar 8007921033 250
342: _____________________________________
343: Passes: 1 Comparisons: 3
344: Average case...!!!
345: Enter your choice:
346: Do you want to continue or not??? (1/0): 0
No comments:
Post a Comment