Bubblesort
Bubblesort
#include<iostream>
#include<string.h>
using namespace std;
// Function declarations
void create(stud s[20], int n); // To create student records
void display(stud s[20], int n); // To display student records
void bubblesort(stud s[20], int n); // To perform bubble sort on student
records
int main() {
stud s[20]; // Array to store up to 20 students
int ch, n;
do {
// Menu options for the user
cout << "\n Creating Student Database:-";
cout << "\n 1) Create student database ";
cout << "\n 2) Display student records ";
cout << "\n 3) Bubble sort ";
cout << "\n 4) Exit";
cout << "\n Enter your choice: ";
cin >> ch; // Input the user's choice
switch (ch) {
case 1:
cout << "\n Enter the number of records=";
cin >> n; // Input the number of records
create(s, n); // Create student records
break;
case 2:
display(s, n); // Display student records
break;
case 3:
bubblesort(s, n); // Perform bubble sort
cout << "\n Records sorted successfully!";
break;
case 4:
cout << "\n Exiting program.";
break;
default:
cout << "\n Invalid choice!! Re-enter your choice" << endl; //
Handle invalid choices
}
} while (ch != 4); // Repeat until the user chooses to exit
OUTPUT:-
Exiting program.