/*
Assignment No.1
Title:- Classes and object
Problem Statement:- Consider a student database of SEIT class (at least 15 records). Database
contains different fields of every student like Roll No, Name and SGPA.(array of structure)
b) Arrange list of students alphabetically. (Use Insertion sort)
*/
#include <iostream>
#include <cstring>
using namespace std;
const int arraySize = 3; // Rename the constant to avoid conflict
struct student {
int roll_no;
char name[30];
float SGPA;
};
// ACCEPT FUNCTION
void accept(struct student list[arraySize]) {
for (int i = 0; i < arraySize; i++) {
cout << "\nEnter Roll-Number, Name, SGPA:";
cin >> list[i].roll_no >> list[i].name >> list[i].SGPA;
// DISPLAY FUNCTION
void display(struct student list[arraySize]) {
cout << "\n Roll-Number \t Name \t SGPA \n";
for (int i = 0; i < arraySize; i++) {
cout << "\n " << list[i].roll_no << " \t " << list[i].name << "\t " << list[i].SGPA;
cout << "\n";
// INSERTION SORT FUNCTION
void insert_sort(struct student list[arraySize]) {
int k, j, c = 0;
struct student key;
for (k = 1; k < arraySize; k++) {
key = list[k];
j = k - 1;
while (strcmp(list[j].name, key.name) > 0 && j >= 0) {
list[j + 1] = list[j];
j--;
c++;
list[j + 1] = key;
cout << "\nNumber of passes is: " << c;
int main() {
int ch;
struct student data[arraySize];
accept(data);
do {
cout << "\n";
cout << "\n 1) Insertion Sort";
cout << "\n 2) Exit \n";
cout << "\n Select Your Choice: ";
cin >> ch;
switch (ch) {
case 1:
insert_sort(data);
display(data);
break;
case 2:
cout << "\nYou Have Successfully Exited!!!";
break;
default:
cout << "\nPlease Enter a Valid Choice.\n";
} while (ch != 2);
return 0;
}
0