0% found this document useful (0 votes)
2 views4 pages

practical part 1

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)
2 views4 pages

practical part 1

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/ 4

/*

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) Design a roll call list, arrange list of students according to roll numbers in ascending order (Use
Bubble Sort)

*/

#include <iostream>

#include <string>

#define SIZE 5

using namespace std;

struct student {

int roll_no;

string name;

float SGPA;

};

void accept(struct student list[SIZE]) {

cout << "Enter roll number, name, and SGPA for " << SIZE << " students:\n";

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

cout << "Student " << i + 1 << ":\n";

cin >> list[i].roll_no >> list[i].name >> list[i].SGPA;

void display(struct student list[SIZE]) {


cout << "Roll No\tName\tSGPA\n";

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

cout << list[i].roll_no << "\t" << list[i].name << "\t" << list[i].SGPA << "\n";

void bubble_sort(struct student list[SIZE]) {

int i, j;

student temp;

for (i = 0; i < SIZE; i++) {

for (j = 0; j < SIZE - 1 - i; j++) {

if (list[j].roll_no > list[j + 1].roll_no) {

// swap the elements if they are in the wrong order

temp = list[j];

list[j] = list[j + 1];

list[j + 1] = temp;

int main() {

student list[SIZE];

accept(list);

cout << "\nOriginal List:\n";

display(list);

bubble_sort(list);
cout << "\nSorted List:\n";

display(list);

return 0;

Output=
Enter roll number, name, and SGPA for 5 students:

Student 1:

105 Tejas 8.0

Student 2:

101 Shubham 8.5

Student 3:

102 Aditya 7.8

Student 4:

106 Kunal 8.7

Student 5:

104 Rohan 9.6

Original List:

Roll No Name SGPA

105 Tejas 8

101 Shubham 8.5

102 Aditya 7.8

106 Kunal 8.7

104 Rohan 9.6

Sorted List:

Roll No Name SGPA


101 Shubham 8.5

102 Aditya 7.8

104 Rohan 9.6

105 Tejas 8

106 Kunal 8.7

=== Code Execution Successful ===

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy