0% found this document useful (0 votes)
12 views5 pages

Practical Part 3

Uploaded by

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

Practical Part 3

Uploaded by

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

/*

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)

c) Arrange list of students to find out first ten toppers from a class. (Use Quick sort)

*/

//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";

// QUICK SORT FUNCTION

void quick_sort(struct student list[arraySize], int first, int last) {

int pivot, i, j;

if (first < last) {

pivot = first;

i = first;

j = last;

while (i < j) {

while (list[i].roll_no <= list[pivot].roll_no && i < last) {

i++;

while (list[j].roll_no > list[pivot].roll_no) {

j--;

if (i < j) {

swap(list[i], list[j]);
}

swap(list[pivot], list[j]);

quick_sort(list, first, j - 1);

quick_sort(list, j + 1, last);

int main() {

int ch, i;

struct student data[arraySize];

accept(data);

do {

cout << "\n";

cout << "\n 1) Quick Sort ";

cout << "\n 2) Exit \n";

cout << "\n Select Your Choice: ";

cin >> ch;

switch (ch) {

case 1:

quick_sort(data, 0, arraySize - 1);

display(data);

break;

case 2:

cout << "\nYou Have Successfully Exi ed!!!.";

break;
default:

cout << "\nPlease Enter Valid Choice.\n";

} while (ch != 2);

return 0;

Output =
Enter Roll-Number, Name, SGPA:102 Aditya 7.8

Enter Roll-Number, Name, SGPA:105 Tejas 8.0

Enter Roll-Number, Name, SGPA:101 Shubham 8.5

1) Quick Sort

2) Exit

Select Your Choice: 1

Roll-Number Name SGPA


101 Shubham 8.5

102 Aditya 7.8

105 Tejas 8

1) Quick Sort

2) Exit

Select Your Choice: 2

You Have Successfully Exi ed!!!.

=== Code Execu on Successful ===

You might also like