0% found this document useful (0 votes)
21 views25 pages

Ds Exp Database

Ds exp database Sppu

Uploaded by

harshalmane2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views25 pages

Ds Exp Database

Ds exp database Sppu

Uploaded by

harshalmane2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

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:

Title: Database Management


Write as per experiment list.

Write a program in C to create database management using an array of


Proble structures. Experiment to validate the following operation: A. With
m pointers to arrays B. Without pointers to arrays
Statem 1. Create, 2. Display, 3. Modify, 4. Append, 5. Search 6. Sort.
ent

Programmer Name: Harshal Ajay Mane


Batch: G8

1. Without pointer

#include <stdio.h>
#include
<string.h>

#define MAX 100

// Structure to store component details


struct Component {
int srNo;
char
name[50];
char symbol;
int value;
float cost;
};

// Function to create components


int create(struct Component comp[], int n)
{ printf("Enter the number of components: ");
scanf("%d", &n);

DS_LAB_2024-25: Program input output 1


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:

for (int i = 0; i < n; i++) {


printf("Enter details of component %d:\n", i
+ 1); printf("Sr. No: ");
scanf("%d",
&comp[i].srNo);
printf("Name: ");
scanf("%49s", comp[i].name); // Limiting input size to avoid buffer overflow
printf("Symbol: ");
scanf(" %c", &comp[i].symbol); // Adding space to handle newline characters
printf("Value: ");
scanf("%d", &comp[i].value);
printf("Cost (Rs): ");
scanf("%f", &comp[i].cost);
}
return n; // Returning the new number of components
}

// Function to print a single underscore


line void printUnderline() {

printf(" \n");
}

// Function to display component details


void display(struct Component comp[],
int n) { if (n == 0) {
printf("No components to display.\
n"); return;
}

// Print the headers printf("Sr.No\tName\t\


tSymbol\tValue\tCost (Rs)\n");

// Print a single underline

DS_LAB_2024-25: Program input output 2


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:

printUnderline();

// Print each component's details in a single


line for (int i = 0; i < n; i++) {
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);
}
}

// Function to modify a component's


details void modify(struct Component
comp[], int n) {
int srNo, found = 0;
printf("Enter the Sr. No of the component to
modify: "); scanf("%d", &srNo);

for (int i = 0; i < n; i++) {


if (comp[i].srNo == srNo)
{ printf("Enter new
details:\n"); printf("Name:
");
scanf("%49s", comp[i].name); // Limiting
input size printf("Symbol: ");
scanf(" %c", &comp[i].symbol); // Handling newline character
printf("Value: ");
scanf("%d", &comp[i].value);
printf("Cost (Rs): ");
scanf("%f",
&comp[i].cost); found
= 1;
break;
}
}

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:

}
}

// Function to append a new component


int append(struct Component comp[],
int n) { if (n >= MAX) {
printf("Cannot add more components. Maximum limit reached.\
n"); return n;
}

printf("Enter details of the new component:\


n"); printf("Sr. No: ");
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);

n++; // Increment the number of components after


appending return n;
}

// Function to search for a component by Sr.


No void search(struct Component comp[], int
n) {
int srNo, found = 0;
printf("Enter the Sr. No of the component to
search: "); scanf("%d", &srNo);

for (int i = 0; i < n; i++) {

DS_LAB_2024-25: Program input output 5


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);
}
}

// Function to sort components by Sr.


No void sort(struct Component comp[],
int n) {
struct Component
temp; for (int i = 0; i <
n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (comp[i].srNo > comp[j].srNo)
{ temp = comp[i];
comp[i] = comp[j];
comp[j] = temp;
}
}
}
printf("Components sorted by Sr. No.\n");
}

int main() {

DS_LAB_2024-25: Program input output 6


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:

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);

// Handle user choice


switch (choice) {
case 1:
n = create(comp, n); // Update the number of components after
creation break;
case 2:
display(comp,
n); break;
case 3:
modify(comp,
n); break;
case 4:
n = append(comp, n); // Update the number of components after
appending
brea
k; case
5:
search(comp,
n); break;
case 6:
sort(comp,
n); break;
case 7:
printf("Exiting...\n");

DS_LAB_2024-25: Program input output 7


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:

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

DS_LAB_2024-25: Program input output 9


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:

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

Sr.No Name Symbol Value Cost (Rs)

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

DS_LAB_2024-25: Program input output 10


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:

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

Sr.No Name Symbol Value Cost (Rs)

1 Resistor R 1000 3.50


2 Inductor L 5 2.50
3 Transistor Q 547 4.50
4 Capacitor C 6 5.50

DS_LAB_2024-25: Program input output 11


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:

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)

3 Transistor Q 547 4.50

1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 6
Components sorted by Sr.
No.

Sr.No Name Symbol Value Cost (Rs)

1 Resistor R 1000 3.50


2 Inductor L 5 2.50
3 Transistor Q 547 4.50
4 Capacitor C 6 5.50

DS_LAB_2024-25: Program input output 12


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:

1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 7

DS_LAB_2024-25: Program input output 13


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:

With Pointers:

#include <stdio.h>
#include
<string.h>

#define MAX 100

// Structure to store component details


struct Component {
int srNo;
char
name[50];
char symbol;
int value;
float cost;
};

// Function to create components using


pointers void create(struct Component
*comp, int *n) {
printf("Enter the number of components: ");
scanf("%d", n);

for (int i = 0; i < *n; i++) {


printf("Enter details of component %d:\n", i
+ 1); printf("Sr. No: ");
scanf("%d",
&comp[i].srNo);
printf("Name: ");
scanf("%49s", comp[i].name); // Limiting input size to avoid buffer overflow
printf("Symbol: ");
scanf(" %c", &comp[i].symbol); // Adding space to handle newline characters
printf("Value: ");
scanf("%d", &comp[i].value);
printf("Cost (Rs): ");
DS_LAB_2024-25: Program input output 14
DS_LAB_2024-25: Program input output 15
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:

scanf("%f", &comp[i].cost);
}
}

// Function to print a single underscore


line void printUnderline() {

printf(" \n");
}

// Function to display component details using


pointers void display(struct Component *comp, int
n) {
if (n == 0) {
printf("No components to display.\
n"); return;
}

// Print the headers printf("Sr.No\tName\t\


tSymbol\tValue\tCost (Rs)\n");

// Print a single underline


printUnderline();

// Print each component's details in a single


line for (int i = 0; i < n; i++) {
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);
}
}

// Function to modify a component's details using


pointers void modify(struct Component *comp, int n) {
int srNo, found = 0;

DS_LAB_2024-25: Program input output 16


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:

printf("Enter the Sr. No of the component to


modify: "); scanf("%d", &srNo);

for (int i = 0; i < n; i++) {


if (comp[i].srNo == srNo)
{ printf("Enter new
details:\n"); printf("Name:
");
scanf("%49s", comp[i].name); // Limiting
input size printf("Symbol: ");
scanf(" %c", &comp[i].symbol); // Handling newline character
printf("Value: ");
scanf("%d", &comp[i].value);
printf("Cost (Rs): ");
scanf("%f",
&comp[i].cost); found
= 1;
break;
}
}

if (!found) {
printf("Component with Sr. No %d not found.\n", srNo);
}
}

// Function to append a new component using


pointers void append(struct Component *comp, int
*n) {
if (*n >= MAX) {
printf("Cannot add more components. Maximum limit reached.\
n"); return;
}

printf("Enter details of the new component:\


n"); printf("Sr. No: ");

DS_LAB_2024-25: Program input output 17


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:

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);

(*n)++; // Increment the number of components after appending


}

// Function to search for a component by Sr. No using


pointers void search(struct Component *comp, int n) {
int srNo, found = 0;
printf("Enter the Sr. No of the component to
search: "); scanf("%d", &srNo);

for (int i = 0; i < n; i++) {


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) {

DS_LAB_2024-25: Program input output 18


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:

printf("Component with Sr. No %d not found.\n", srNo);


}
}

// Function to sort components by Sr. No using


pointers void sort(struct Component *comp, int n) {
struct Component
temp; for (int i = 0; i <
n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (comp[i].srNo > comp[j].srNo)
{ temp = comp[i];
comp[i] = comp[j];
comp[j] = temp;
}
}
}
printf("Components sorted by Sr. No.\n");
}

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);

// Handle user choice


switch (choice) {
case 1:

DS_LAB_2024-25: Program input output 19


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:

create(comp, &n); // Pass array and number of components by


pointer break;
case 2:
display(comp,
n); break;
case 3:
modify(comp,
n); break;
case 4:
append(comp, &n); // Pass array and number of components by
pointer break;
case 5:
search(comp,
n); break;
case 6:
sort(comp,
n); break;
case 7:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 7);

return 0;
}

DS_LAB_2024-25: Program input output 20


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:

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

DS_LAB_2024-25: Program input output 21


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:

1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 2

Sr.No Name Symbol Value Cost (Rs)

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

DS_LAB_2024-25: Program input output 22


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:

Sr.No Name Symbol Value Cost (Rs)

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

Sr.No Name Symbol Value Cost (Rs)

1 Resistor R 1000 3.50


2 Inductor L 5 2.50
3 Transistor Q 547 4.50
4 Capacitor C 6 5.50

1.Create
2.Display
3.Modify
4.Append

DS_LAB_2024-25: Program input output 23


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:

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)

3 Transistor Q 547 4.50

1.Create
2.Display
3.Modify
4.Append
5.Search
6.Sort
7.Exit
Enter your choice: 6
Components sorted by Sr.
No.

Sr.No Name Symbol Value Cost (Rs)

1 Resistor R 1000 3.50


2 Inductor L 5 2.50
3 Transistor Q 547 4.50
4 Capacitor C 6 5.50

1.Create
2.Display
3.Modify
4.Append

DS_LAB_2024-25: Program input output 24


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:

5.Search
6.Sort
7.Exit
Enter your choice: 7

DS_LAB_2024-25: Program input output 25

You might also like