(Solved) : Use Maincpp Studenth Studentcpp Written Write Classes Studentclub Non Member Function Find Q43964948 . . .
Use main.cpp, Student.h, Student.cpp (written below) and writeclasses StudentClub and a non-member function find youngest to makemain.cpp compile. Put the declaration and definition of findyoungest in StudentClub.h and StudentClub.cpp separately. You maynot modify provided files and only submit StudentClub.h andStudentClub.cpp.
Non-member function find youngest is declared as follows. Itreturns the names of students who have the youngest age. Note theremay exist more than one students who are youngest. std::vectorfind_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 ofpointers to Student objects. Hint: std::vector member; StudentClubshould also have at least the following methods. •StudentClub(std::string n): initializes name with n, pointers asnull 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. • getpresident(), get treasurer(), get member(): return private membersaccordingly. Hint: don’t forget they are const methods or so-calledaccessors. • void set president(Student* p) and void settreasurer(Student* t). • void add member(Student* s): appends thestudent pointer object to member. • print: prints the informationof the StudentClub class object. Change the following /* *** */part with correct syntax to print according information on theconsole.
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 ofcurrent 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<std::string> youth;
youth = find_youngest(math.get_member());
std::cout << std::setw(20) << “Youngestmembers:”;
for (int i=0; i<youth.size(); ++i)
std::cout << ” ” << youth[i] ;
std::cout << std::endl;
// reclaim memory, without doing so, it runs into memoryleaks
// even though the memory space will be recalled by the OS afterthe program terminates, we should manually reclaim the memory afterdeclaring them
delete jess;
delete john;
delete kate;
delete mary;
return 0;
}
Student.h:
#ifndef __STUDENT_H__
#define __STUDENT_H__
#include<string>
#include<vector>
#include<iomanip>
#include<iostream>
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;
}
Expert Answer
Answer to Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find younge…
OR