Question

In: Computer Science

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+) 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);

}

THANK YOU!! PLEASE VOTE


Related Solutions

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...
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 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...
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list...
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list with the named elements ‘name’, ‘subjects completed’, ‘grades’, and ‘credit’. Write a studentRecord method for the generic function mean, which returns a weighted GPA, with subjects weighted by credit. Also write a studentRecord method for print, which employs some nice formatting, perhaps arranging subjects by year code. Finally create a further class for a cohort of students, and write methods for mean and print...
Create a Python program that will take an unsorted list of 1000 integers and sort them...
Create a Python program that will take an unsorted list of 1000 integers and sort them using a bubble sort and an insertion sort. Your output should include displaying both sorted lists (from each algorithm) identifying each sorted list by the algorithm used.
On python : d. Create a null vector of size 10 but the fifth value which...
On python : d. Create a null vector of size 10 but the fifth value which is 1. - 5 Point e. How to sum a small array faster than np.sum?- 5 Point
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...
Create an unsorted LIST class. Each list should be able to store 100 names.
Create an unsorted LIST class. Each list should be able to store 100 names.
Create a function that takes a vector of vectors as an argument. Each inner vector has...
Create a function that takes a vector of vectors as an argument. Each inner vector has 2 elements. The first element is the numerator and the second element is the denominator. Return the sum of the fractions rounded to the nearest whole number. Examples: sum_fractions({{18, 13}, {4, 5}}) ➞ 2 sum_fractions({{36, 4}, {22, 60}}) ➞ 9 sum_fractions({{11, 2}, {3, 4}, {5, 4}, {21, 11}, {12, 6}}) ➞ 11 Notes Your result should be a number not string. Code in C++...
Create an array of 10,000 elements, use sorted, near sorted, and unsorted arrays. Implement find the...
Create an array of 10,000 elements, use sorted, near sorted, and unsorted arrays. Implement find the kth smallest item in an array. Use the first item as the pivot. Compare sets of results using a static call counter. Reset counter before running another search. Create a Test drive to exhaustively test the program. // Assume all values in S are unique. kSmall(int [] S, int k): int (value of k-smallest element) pivot = arbitrary element from S:  let’s use the first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT