Question: https://programming-workshop-2.github.io/course-material/labs/lab8-stl-vectors Using C++.... Goal: a program to manage student records You are asked to implement a program to manage Student records of the following form:

https://programming-workshop-2.github.io/course-material/labs/lab8-stl-vectors

Using C++....

Goal: a program to manage student records

You are asked to implement a program to manage Student records of the following form:

class Student { private: std::string name_; int number_; std::vector<int> grades_; const int num_courses_; // You need to implement the following four methods  static std::string gen_name() { // To do }  static int gen_number() { // To do }  static int gen_grade() { // To do }  double compute_average() { // To do }  public: Student(const std::string& name, int number) : name_(name), number_(number), num_courses_(5) { for (int i=0; i<num_courses_; ++i) { grades_.push_back(std::rand()); } } friend std::ostream& operator<<(std::ostream& os, const Student& s) { os << "Name = " << s.name_ << ", Number = " << s.number_; return os; } void print_grades(std::ostream& os) const { for (int i=0; i<num_courses_; ++i) { os << grades_[i] << ", "; } } }; 

=========================================================================================================

Number of students will be specified at runtime

The number of students to be stored in the system will be specified at runtime via commandline arguments. The program will take 1 argument whose value will indicate the number of students to stored in the system. The following call, for example, will store $7$ students in the system.

$ student-record 7 ... 

============================================================================================================

Student records will be initialized with random values

Names, numbers and grades will be set to random values with the following constraints:

A name is a random string (a-zA-Z0-9) between 6 and 12 characters long;

A number is a random integer between 201100000 and 201600000; and

A grade is a random integer between 70 and 100.

Note that each student stores only 5 grades.

Required functionality

The program will store students in std::vector and will implement the following functionality:

Print student records;

Print student records sorted by name (ascending order);

Print student records sorted by average grade (ascending order); and

Print the student record with the highest average grade (and print average values).

Average values may be floats.

Some example code to get you started

Consider the code shown below, which showcases the use of sort algorithm available in STL.

#include #include #include // time() #include // srand(), rand() #include // min_element(), max_element(), sort()  bool sort(int i, int j) { return (i<j); } int main() { std::srand(std::time(0)); std::vector<int> x; int n = 10; for (int i=0; i<n; ++i) { x.push_back(std::rand()); } for (std::vector<int>::iterator xi = x.begin(); xi != x.end(); xi++) { std::cout << *xi << std::endl; } std::cout << "min value = " << *std::min_element(x.begin(), x.end()) << std::endl; std::cout << "index of min value = " << std::min_element(x.begin(), x.end()) - x.begin() << std::endl; std::cout << "max value = " << *std::max_element(x.begin(), x.end()) << std::endl; std::cout << "index of max value = " << std::max_element(x.begin(), x.end()) - x.begin() << std::endl; std::sort(x.begin(), x.end()); for (std::vector<int>::iterator xi = x.begin(); xi != x.end(); xi++) { std::cout << *xi << std::endl; } std::sort(x.begin(), x.end(), sort); for (std::vector<int>::iterator xi = x.begin(); xi != x.end(); xi++) { std::cout << *xi << std::endl; } return 0; } 

====================================================================================================

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!