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
  • 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 =...

  • 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...

  • 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....

  • 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...

  • IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and...

    IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array.   Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code.   Your program should output...

  • 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...

  • Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list -...

    Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...

  • Write a program in C++ to: 1. Read all records from a binary file (also attached...

    Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...

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
ADVERTISEMENT