practical part 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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)

b) Arrange list of students alphabe cally. (Use Inser on 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) Inser on 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;

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) Inser on Sort

2) Exit

Select Your Choice: 1

Number of passes is: 1

Roll-Number Name SGPA

102 Aditya 7.8

101 Shubham 8.5

105 Tejas 8

1) Inser on Sort

2) Exit

Select Your Choice: 2

You Have Successfully Exited!!!

=== Code Execu on 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