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: don’t 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<std::string> youth;
youth = find_youngest(math.get_member());
std::cout << std::setw(20) << "Youngest
members:";
for (int i=0; i<youth.size(); ++i)
std::cout << " " << youth[i] ;
std::cout << std::endl;
// 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<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;
}
hi, here is the code for StudentClub class. Please try it out. If you face any problems let me know, I will help.
class StudentClub
|
#include "StudentClub.h" const vector<Student*>& StudentClub::get_member()
const const string& StudentClub::get_name() const Student* StudentClub::get_president() const Student* StudentClub::get_treasurer() const
void StudentClub::set_treasurer(Student *&treasurer) StudentClub::StudentClub(string n) StudentClub::StudentClub(string n, Student *p, Student *t,
vector<Student *> m) void StudentClub::add_member(Student *s) void StudentClub::print() const vector<string> find_youngest(std::vector<Student *>
member) |
Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...
-------c++-------- The Passport class takes a social security number and the location of a photo file. The Passport class has a Photo class member, which in a full-blown implementation would store the passport photo that belongs in that particular passport. This Photo class holds its location or file name and the pixel data of the image. In this lab the pixel data is only used to show how memory maybe used when a program uses large objects. We will not...
// Inheriting member functions // Please Make all changes as noted below: // 1) Make sayHello virtual function (hint this will be done in Person class // 2) Change main to create two Person pointer variables // 3) Set each pointer to one of the two objects already instantiated below // 4) Use the pointer variable to invoke the two sayHello() methods #include <iostream > #include <string > using namespace std ; class Person { protected : string name; int...
//main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...
10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...
lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...
Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design a Ship class that has the following members: - A member variable for the name of the ship (a string) - A member variable for the year that the ship was built (a string) - A contsructor and appropriate accessors and mutators - A virtual print function that displays the ship's name and the year it was built (nobody seems to get this part...
This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...
C++ / Visual Studio Implement the member function below that returns true if the given value is in the container, and false if not. Your code should use iterators so it works with any type of container and data. template< typename Value, class Container > bool member( const Value& val, const Container& cont ); just implement this function in the code below #include <iostream> #include <array> #include <deque> #include <list> #include <set> #include <string> #include <vector> using namespace std; #define...