Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

• Design a class Student. A student has a name and a birthday. Make a vector vec

ID: 3724379 • Letter: #

Question

• Design a class Student. A student has a name and a birthday. Make a vector vector friends; • Write a program in which the user is asked to enter a set of names and birthdays, thus populating the friends vector. See input-output for details. After the list of students’ names and birthdays is read-in, implement a loop in which the user is asked to enter a month followed by a display of all students whose birthday falls into this month. • Comment 1. Note that the birthday entered must be in the format mm/dd/yyyy. • Comment 2. Note when the user is prompted to enter a month it must be a string, not an integer

LHomework_ 5.pdf CSecure https://ccle.ucla.edu/pluginfile.php/2230142/mod_ resource/content/O/Homework 5.pdf an integer Submit the solution as hmw.5.4.cpp. Sample input-output: nter a 1ist of students tudent's nane: Alex Johnson tudent's birthday: 10/01/2000 ontinue (y/n> y tudent's nane: Lisa Snith tudent's birthday: 11/02/2000 ontinue (y/n>? y tudent's nane:John Doe tudent's birthday: 10/20/20n0 ontinue tudent nane: David Taylor y/n)? y tudent' s birthday: 10/12/2000 ontinue (y/n)? n nter a nonth: October ist of students uho were born in October: lex Johnson 10/01/2000 ohn Doe 10/20/2000 avid Taylor 10/12/2000 ontinue Cy/n>? y Enter a month: April students uho were born in April ontinue (y/n>? y nter a month: Honday here is no such nonth. Try again ontinue y/n)? ress any key to continue.. 46 PM O Type here to search 3/5/2018

Explanation / Answer

#include<iostream>

#include<vector>

#include<string>

using namespace std;

class Student

{

string name;

string date;

public:

Student();

void setData(string name, string date);

string getName();

string getDate();

};

//default constructor

Student::Student()

{

name = "";

date = "";

}

//mutator function to set name and date

void Student::setData(string str,string d)

{

name = str;

date = d;

}

string Student::getName()

{

return name;

}

string Student::getDate()

{

return date;

}

int IntValueforMonth(string d);

int main()

{

string str, d;

char choice;

vector<Student> friends;

Student s;

//take some inputs

cout << "Enter a list of students." << endl;

do

{

cout << endl<<endl<<"Student's name: ";

cin.clear();

getline(cin, str);

//cin.ignore();

cout << "Student's date of birthdate(in the format mm//dd/year): ";

cin >> d;

cout << endl;

cout << "Continue(y/n)? ";

cin.ignore();

choice = getchar() ;

//set all the data for object student

s.setData(str, d);

//push the object s of Student type onto to vector

friends.push_back(s);

cin.clear();

cin.ignore();

if (choice == 'y')

continue;

} while (choice != 'n');

string month;

do

{

//now ask user to enter the month of the student

cout << endl<<endl<<"Enter a month: ";

cin >> month;

//search the month in vector

int m, found = 0,first=0;

m = IntValueforMonth(month);

if (m == 0)

{

cout << "There is no such month.Try again.." << endl;

cout << endl;

cin.ignore();

cout << "Continue(y/n)? ";

choice = getchar();

cin.ignore();

if (choice == 'y')

continue;

if (choice == 'n')

break;

}

for (int i = 0; i < friends.size(); i++)

{

//now check the integer equivalant of the string month with the value stored in object

string delimiter = "/";

string s = friends[i].getDate();

string mon = s.substr(0, s.find(delimiter));

//if converted int value of mon matches with the value of m,, then display the student

if (m == stoi(mon))

{

if (first == 0)

{

cout << endl << endl << "List of students who were born in " << month << ": " << endl;

}

first++;

cout << friends[i].getName() << " " << friends[i].getDate() << endl;

found = 1;

}

}

if (!found)

{

cout << "No students who were born in " << month << endl;

}

cout << endl;

cout << "Continue(y/n)? ";

choice = getchar();

cin.ignore();

if (choice == 'y')

continue;

} while (choice != 'n');

}

int IntValueforMonth(string d)

{

int found = 0;

string month[12] = { "Janaury","February","March","April","May","June","July","August","September","October","November","December" };

for (int i = 0; i < 12; i++)

{

if (d == month[i])

{

return i + 1;

}

}

return 0;

}

---------------------------------------------------------------------------

//output

Enter a list of students.


Student's name: Alex JOhnson
Student's date of birthdate(in the format mm//dd/year): 10/01/2000

Continue(y/n)? y


Student's name: Lisa Smith
Student's date of birthdate(in the format mm//dd/year): 11/02/2000

Continue(y/n)? y


Student's name: John Doe
Student's date of birthdate(in the format mm//dd/year): 10/20/2000

Continue(y/n)? y


Student's name: David Taylor
Student's date of birthdate(in the format mm//dd/year): 10/12/2000

Continue(y/n)? n


Enter a month: October


List of students who were born in October:
Alex JOhnson 10/01/2000
John Doe 10/20/2000
David Taylor 10/12/2000

Continue(y/n)? y


Enter a month: April
No students who were born in April

Continue(y/n)? y


Enter a month: Monday
There is no such month.Try again..

Continue(y/n)? n