Question

In C++ write a class. The requirements for the class are define as followings: Class StudentBubbleSorter...

In C++ write a class. The requirements for the class are define as followings:

  • Class StudentBubbleSorter – This class will have the following methods with their signatures as listed below:
    • Sort() – This method will receive an array of Student records to be sorted. It will sort the records by Student ID(s). It will also return the sorted array of Student records.
    • PrintRecords() – This method will receive an array of Student records. It will print out the information of each Student record.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

I am putting the required code for couple of functions of the class below. In the code, a class student is created with Student_ID as variable, On the basis of ID, bubble sort is implemented. You can always add more variables in class student according to records data available. I have temporarily created record using create_array method in the code itself. You can send your array of students record if available to the sort function directly. students_record[] is my records array. Please refer code below.

******************* Code Begin ********************

#include<iostream>
#include<conio.h>
#include<string>
#define MAX 50
using namespace std;

class student
{
public:
   int Student_ID;
};

class StudentBubbleSorter
{
public:
   void Sort(student students_record[], int count) //Here function receiving array of student records and total count of records // for sorting
   {
       for (int i = 0; i < (count - 1); i++)
       {
           for (int j = 0; j < (count - i - 1); j++)
           {
               if (students_record[j].Student_ID > students_record[j + 1].Student_ID)
               {
                   student temp = students_record[j];
                   students_record[j] = students_record[j + 1];
                   students_record[j + 1] = temp;
               }
           }
       }
   }

   void PrintRecords(student students_record[], int count) //printing student records
   {
       cout << "Here is the sorted record date => \n";
       int i;
       for (i = 0; i < count; i++)
       {
           cout << students_record[i].Student_ID << "\n";
       }
   }

};

int create_array(student students_record[]) //This function is only for creating temporary students record data.
{

   int count, i;
   cout << "Enter no of students you want to insert";
   cin >> count;
   for (i = 0; i < count; i++)
   {
       cout << "Enter student ID => ";
       cin >> students_record[i].Student_ID;
   }

   return count; //Returning total no of records in array.
}
int main()
{
   student students_record[MAX]; //Array of students record. Keeping max size of array to 50
   StudentBubbleSorter obj; //Object of class StudentBubbleSorter

   int count = create_array(students_record); //Creating temporary data for the code. If you have actual array ready, you // can skip this function call and directly send array to the sort function.
    obj.Sort(students_record, count); //Calling sort function and sending records array as well as total count of records.
   obj.PrintRecords(students_record, count); //Calling print function to print records.


  
   return 0;
}


********************* End Of Code ******************

That's all for now.

Open for comments , queries if any.

Thank You.

Add a comment
Know the answer?
Add Answer to:
In C++ write a class. The requirements for the class are define as followings: Class StudentBubbleSorter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ write a class. The requirements for the class are define as followings: Class StudentMergeSorter...

    In C++ write a class. The requirements for the class are define as followings: Class StudentMergeSorter – This class will have the following methods with their signatures as listed below: Sort() Java - This method will receive an array of Student records to be sorted. It will sort the records by Student ID(s). It will also return the sorted array of Student records. C++ - This method will have two parameters. The first parameter will be an array of Student...

  • In C++ write a class. The requirements for the class are define as followings: Class StudentQuickSorter...

    In C++ write a class. The requirements for the class are define as followings: Class StudentQuickSorter – This class will have the following methods with their signatures as listed below:        Sort()             This method will have two parameters. The first parameter will be an array of Student records to be sorted. The second parameter will be the number of Student records in the array.        PrintRecords()             This method will have two parameters. The first parameter will be an...

  • Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double...

    Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double hashing uses the idea of applying a second hash function to key when a collision occurs.   The software program will be based on the following requirements: Development Environment: If the software program is written in C++, its project must be created using Microsoft Visual Studio 2017. If the software program is written in Java, its project must be created using NetBeans v8.2. Algorithm: If...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector>...

    /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Student { public:    // default constructor    Student()    {        studentID = 0;        studentFirst = "First";        studentMiddle = "Middle";        studentLast = "Last";    }    void SetStudentID(int number) { studentID = number; }    void SetStudentFirst(string name) { studentFirst = name; }    void SetStudentMiddle(string name) { studentMiddle =...

  • The object class should be a Student with the following attributes: id: integer first name: String...

    The object class should be a Student with the following attributes: id: integer first name: String last name: String write the accessors, mutators, constructor, and toString(). In your main test class you will write your main method and do the following things: Create an array of Student objects with at least 5 students in your array. Write a sort method that must be your original work and included in the main class. The sort method will sort based on student...

  • Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Ini...

    Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...

  • Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main,...

    Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main, arrayMystery, and countTotalOdd. You need to create main method. Inside the main method...you need to create an integer array named myld that consists of each of the digits in your student ID, call arrayMystery method and print out myld, then call count TotaOdd method and print out the total number of odd digits in your ID. (8 points) The arrayMystery method is given as...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • Write a C++ program to keep records and perform statistical analysis for a class of 20...

    Write a C++ program to keep records and perform statistical analysis for a class of 20 students. The information of each student contains ID, Name, Sex, quizzes Scores (2 quizzes per semester), mid-term score, final score, and total score. The program will prompt the user to choose the operation of records from a menu as shown below: ==============================================                                            MENU =============================================== 1. Add student records 2. Delete student records 3. Update student records 4. View all student records 5. Calculate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT