Question

In: Computer Science

C++ Create a vector of student records (minimum 15+ records) which is unsorted (For Vector, refer...

C++
Create a vector of student records (minimum 15+ records) which is unsorted
(For Vector, refer to Chapter 7.11 or 17.3, or you may use Array of structures)
- You should read student records from a file into the vector in C++
or in Java program.
- Display the unsorted 10+ student records (entire record, not just ID) and associated test scores.
- Each Student record should include Student ID, Name, GPA, Student Address, and a pointer which points to (10+) test scores somewhere in the program or in the file.
- Use QuickSort and recursion to Sort the student records according to student ID or GPA.
- Display the sorted list of student records (entire record, not just ID) and associated test scores.
- Repeat the above on two sets of student records. Each set with a minimum of
10 records.
Your program output must show proper information to be understood well
by the reader/viewer.

Solutions

Expert Solution

I am also atteching input text file which contains 5 records for referance

this is test data

5
12 Gaurav 9 5
Gujarat,India
90 98 99 100 96
10 ABC 8 4
Mumbai,India
90 98 99 96
16 Utsav 9 4
Surat,India
88 98 99 100
1 Vivek 10 5
Gujarat,India
90 98 99 100 96
2 Akshit 9 5
Amd,India
90 90 88 100 96

#include <bits/stdc++.h>
using namespace std;

//Structure Defining Student Details
struct Student
{
    int studentID;
    string Name;
    int GPA;
    string Address;
    int *scores;
    int no_Of_scores;
};

//Print the records
void displayRecords(vector<Student>&v){
    for(int i=0;i<v.size();i++){

         cout<<"Details of Student "<<i+1<<endl;
        cout<<"StudentId: "<<v[i].studentID<<endl;
        cout<<"Name: "<<v[i].Name<<endl;
        cout<<"Address: "<<v[i].Address<<endl;
        cout<<"GPA: "<<v[i].GPA<<endl;
        cout<<"Scores: ";
        for(int j=0;j<v[i].no_Of_scores;j++){
            cout<<v[i].scores[j]<<" ";

        }
        cout<<endl<<endl;
    }
}

//If you want to sort according to GPA change v[index].studentId to v[index].GPA
int Partition(vector<Student>&v,int low,int high){
    
     int pivot =v[high].studentID; 
    int i = (low - 1); 
    for (int j = low; j <= high - 1; j++)  
    {    
        if (v[j].studentID < pivot)  
        {  
            i++; 
            swap(v[i], v[j]);  
        }  
    }  
    swap(v[i + 1], v[high]);  
    return (i + 1);  

}
//recursive function to sort vector of student
void QuickSort(vector<Student>&v,int low,int high){
    if(low<high){

        int partition_index=Partition(v,low,high);
        QuickSort(v,low,partition_index-1);
        QuickSort(v,partition_index+1,high);
    }
}

int main()
{
    //Uncomment the cout parts if you want to enter the details 
    //From console.That is for referance and better readability 
    //of code
    
    
    //Reading file input
    //Input format:
    //No of student
    //studentId,Name,GPA,No of Scores
    //Address
    //scores eg 5 10 12 13 ...

    freopen("input.txt", "r", stdin);
    //cout<<"Enter Required Details\n";
    //cout<<"Enter Number Of Students\n";
    int no_of_students;
    cin >> no_of_students;
    vector<Student> v;
    int index=0;
    while(index<no_of_students){

        Student temp;
       // cout<<"Enter StudentId,Name,GPA,Number Of Subjects Scores\n";
        cin>>temp.studentID>>temp.Name>>temp.GPA>>temp.no_Of_scores;
        //cout<<"Enter Address\n";
        cin>>temp.Address;
        temp.scores=new int[temp.no_Of_scores];
        //cout<<"Enter Scores \n";
        for(int i=0;i<temp.no_Of_scores;i++)
        {
            cin>>temp.scores[i];
        }
        v.push_back(temp);
        index++;
    }
    cout<<"\n===Unsorted Details===\n\n";
    displayRecords(v);
    QuickSort(v,0,v.size()-1);
    cout<<"\n===Sorted Details===\n\n";
    displayRecords(v);

}

Related Solutions

Create a vector of student records (minimum 15+ records) which is unsorted (For Vector, refer to...
Create a vector of student records (minimum 15+ records) which is unsorted (For Vector, refer to Chapter 7.11 or 17.3, or you may use Array of structures) - You should read student records from a file into the vector in C++ or in Java program. - Display the unsorted 10+ student records (entire record, not just ID) and associated test scores. - Each Student record should include Student ID, Name, GPA, Student Address, and a pointer which points to (10+)...
Create a table with a minimum of 10 Records. Each Record should have a Minimum of...
Create a table with a minimum of 10 Records. Each Record should have a Minimum of 8 fields, one of which should be a phone, one a birth date and 1 (Memo) a long Text. Don't forget a Key Field Using Microsoft Access
Create a C structure which stores information about a student. Each student should be represented by...
Create a C structure which stores information about a student. Each student should be represented by a student ID (integer), first name, last name, day, month and year of birth, and program code (string). Write a C program which creates an array of 100 of these structures, then prompts the user to enter data from the keyboard to fill the array. If an ID of 0 is entered, data entry should finish, and the list of students should be printed...
In basic C++ Create a function that takes in a vector, sorts it, then outputs to...
In basic C++ Create a function that takes in a vector, sorts it, then outputs to the console the result.
C++ Suppose the vector v = [4 -6 7]. Create three vectors: 1. p, which is...
C++ Suppose the vector v = [4 -6 7]. Create three vectors: 1. p, which is twice as long as v and points in the same direction as v 2. q, which has the same length as v and points in the opposite direction of v 3. r, which is three quarters the length of v and points in the same direction as v Print out the results of each vector calculation.
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t specify a size and don’t initialize with values. Starting with 2, pushing these into the back of the vector:   2, 4, 6, 8, 10 vector capacity (array size) changes and is dependent on the compiler. The size of the list is now 5. The vector capacity (array size) is 6. The back element is: 10 The front element is: 2 Now deleting the value at...
Create a family tree with a 3D vector in C++. Then, determine the worst, average and...
Create a family tree with a 3D vector in C++. Then, determine the worst, average and best time complexities of the program.
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT