Question: Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest to make main.cpp compile. Put the declaration and definition
Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest to make main.cpp compile. Put the declaration and definition of find youngest in StudentClub.h and StudentClub.cpp separately. You may not modify provided files and only submit StudentClub.h and StudentClub.cpp.
Non-member function find youngest is declared as follows. It returns the names of students who have the youngest age. Note there may exist more than one students who are youngest. std::vector find_youngest(const std::vector member);
StudentClub should have the following private data members. name: a string that stores the name of student club. president: treasurer: pointers to Student objects. member: a vector of pointers to Student objects. Hint: std::vector member; StudentClub should also have at least the following methods. StudentClub(std::string n): initializes name with n, pointers as null pointers and member as a vector of size 0. StudentClub(std::string n, Student* p, Student* t, std::vector m): initializes private members with provided arguments. get president(), get treasurer(), get member(): return private members accordingly. Hint: dont forget they are const methods or so-called accessors. void set president(Student* p) and void set treasurer(Student* t). void add member(Student* s): appends the student pointer object to member. print: prints the information of the StudentClub class object. Change the following /* *** */ part with correct syntax to print according information on the console.
void StudentClub::print() const {
std::cout << std::setw(20) << "Club Name: " << name << std::endl; std::cout << std::setw(20) << "President Name: " << /* president name*/ << std::endl; std::cout << std::setw(20) << "Treasurer Name: " << /* treasurer name*/ << std::endl; std::cout << std::setw(20) << "Current members: " << /* number of current members */ << std::endl; }
main.cpp:
#include"StudentClub.h"
int main() { StudentClub math("MATHBRUINS"); Student * jess = new Student("Jess",20); Student * john = new Student("John",50); Student * kate = new Student("Kate",20); Student * mary = new Student("Mary",30); // set president/treasurer math.set_president(john); math.set_treasurer(john); // update members math.add_member(kate); math.add_member(mary); math.add_member(jess); math.add_member(john); //print Student club info math.print(); // find youngest students and print their names std::vector // reclaim memory, without doing so, it runs into memory leaks // even though the memory space will be recalled by the OS after the program terminates, we should manually reclaim the memory after declaring them delete jess; delete john; delete kate; delete mary; return 0; } Student.h: #ifndef __STUDENT_H__ #define __STUDENT_H__ #include class Student { private: std::string name; int age; public: Student(std::string n, int y); std::string get_name() const; int get_age() const; }; #endif Student.cpp: #include "Student.h" Student::Student(std::string n, int y) { name = n; age = y; } std::string Student::get_name() const { return name; } int Student::get_age() const { return age; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
