Ds Exp Database
Ds Exp Database
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2024-2025 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2024-25/ Starting date:
Roll No:22447 Submission date:
1. Without pointer
#include <stdio.h>
#include
<string.h>
printf(" \n");
}
printUnderline();
if (!found) {
printf("Component with Sr. No %d not found.\n", srNo);
DS_LAB_2024-25: Program input output 3
DS_LAB_2024-25: Program input output 4
PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2024-2025 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2024-25/ Starting date:
Roll No:22447 Submission date:
}
}
if (comp[i].srNo == srNo)
{ printf("Component
found:\n");
printf("Sr.No\tName\t\tSymbol\tValue\tCost (Rs)\
n"); printUnderline();
printf("%d\t%-15s%c\t%d\t%.2f\n",
comp[i].srNo, comp[i].name, comp[i].symbol, comp[i].value,
comp[i].cost);
found = 1;
break;
}
}
if (!found) {
printf("Component with Sr. No %d not found.\n", srNo);
}
}
int main() {
struct Component
comp[MAX]; int n = 0, choice;
do {
// Menu for array operations
printf("\n1. Create\n2. Display\n3. Modify\n4. Append\n5. Search\n6.
Sort\n7. Exit\n");
printf("Enter your
choice: "); scanf("%d",
&choice);
brea
k;
default
:
printf("Invalid choice!\n");
}
} while (choice != 7);
return 0;
}
Output:
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 1
Enter the number of
components: 3 Enter details of
component 1:
Sr. No: 1
Name:
Resistor
Symbol: R
Value: 10
Cost (Rs): 0.5
Enter details of
component 2: Sr. No: 2
Name:
Inductor
Symbol: L
DS_LAB_2024-25: Program input output 8
Value: 5
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 2
1 Resistor R 10 0.50
2 Inductor L 5 2.50
3 Transistor Q 547 4.50
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 3
Enter the Sr. No of the component to modify: 1
Enter new
details: Name:
Resistor Symbol:
R
Value: 1000
Cost (Rs): 3.5
Sr.No Name Symbo Value Cost (Rs)
l
1 Resistor R 1000 3.50
2 Inductor L 5 2.50
3 Transistor Q 547 4.50
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 4
Enter details of the new
component: Sr. No: 4
Name:
Capacitor
Symbol: C
Value: 6
Cost (Rs): 5.5
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 5
Enter the Sr. No of the component to search: 3
Component found:
Sr.No Name Symbol Value Cost (Rs)
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 6
Components sorted by Sr.
No.
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 7
With Pointers:
#include <stdio.h>
#include
<string.h>
scanf("%f", &comp[i].cost);
}
}
printf(" \n");
}
if (!found) {
printf("Component with Sr. No %d not found.\n", srNo);
}
}
scanf("%d",
&comp[*n].srNo);
printf("Name: ");
scanf("%49s", comp[*n].name); // Limiting input
size printf("Symbol: ");
scanf(" %c", &comp[*n].symbol); // Handling newline character
printf("Value: ");
scanf("%d", &comp[*n].value);
printf("Cost (Rs): ");
scanf("%f", &comp[*n].cost);
if (!found) {
int main() {
struct Component
comp[MAX]; int n = 0, choice;
do {
// Menu for array operations
printf("\n1. Create\n2. Display\n3. Modify\n4. Append\n5. Search\n6.
Sort\n7. Exit\n");
printf("Enter your
choice: "); scanf("%d",
&choice);
return 0;
}
Output:
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 1
Enter the number of
components: 3 Enter details of
component 1:
Sr. No: 1
Name:
Resistor
Symbol: R
Value: 10
Cost (Rs): 0.5
Enter details of
component 2: Sr. No: 2
Name:
Inductor
Symbol: L
Value: 5
Cost (Rs): 2.5
Enter details of
component 3: Sr. No: 3
Name:
Transistor
Symbol: Q
Value: 547
Cost (Rs): 4.5
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 2
1 Resistor R 10 0.50
2 Inductor L 5 2.50
3 Transistor Q 547 4.50
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 3
Enter the Sr. No of the component to
modify: 1 Enter new details:
Name:
Resistor
Symbol: R
Value: 1000
Cost (Rs): 3.5
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 4
Enter details of the new
component: Sr. No: 4
Name:
Capacitor
Symbol: C
Value: 6
Cost (Rs): 5.5
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 5
Enter the Sr. No of the component to search: 3
Component found:
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 6
Components sorted by Sr.
No.
1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 7