/*
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)
a) Search students according to SGPA. If more than one student having same SGPA, then print list of
all students having same SGPA.
*/
//CODE:
#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";
// SEARCH FUNCTION
void search(struct student list[arraySize]) {
float SGPA;
int i;
cout << "\n Enter SGPA:";
cin >> SGPA;
cout << "\n Roll- Number \t Name \t SGPA \n";
for (int i = 0; i < arraySize; i++) {
if (SGPA == list[i].SGPA)
cout << "\n" << list[i].roll_no << "\t" << list[i].name << "\t" << list[i].SGPA;
int main() {
int ch, i;
struct student data[20];
accept(data);
do {
cout << "\n";
cout << "\n 1) Search ";
cout << "\n 2) Exit \n";
cout << "\n Select Your Choice: ";
cin >> ch;
switch (ch) {
case 1:
search(data);
break;
case 2:
cout << "\nYou Have Successfully Exi ed!!!.";
break;
default:
cout << "\nPlease Enter Valid Choice.\n";
// Displaying the array a er searching is probably not necessary in this context.
// If you want to display the array a er the search, uncomment the following line.
// display(data);
} while (ch != 2);
return 0;
Output =
Enter Roll-Number, Name, SGPA:105 Tejas 8.0
Enter Roll-Number, Name, SGPA:101 Shubham 8.5
Enter Roll-Number, Name, SGPA:102 Aditya 7.8
1) Search
2) Exit
Select Your Choice: 1
Enter SGPA:8.5
Roll- Number Name SGPA
101 Shubham 8.5
1) Search
2) Exit
Select Your Choice: 2
You Have Successfully Exi ed!!!.
=== Code Execu on Successful ===