I have included the program. I am half way done. I just need help with compareBD
ID: 672968 • Letter: I
Question
I have included the program. I am half way done. I just need help with compareBDs and searching the array. you can make changes if you want.
birthday.h file
#ifndef manii_birthday_h
#define manii_birthday_h
#include <iostream>
using namespace std;
class Birthday
{ private:
double month;
double day;
double year;
public:
Birthday (double, double, double);
void setmonth(double);
void setday(double);
void setyear(double);
double getmonth() const
{
return month;
}
double getday() const
{
return day;
}
double getyear() const
{
return year;
}
};
#endif
.cpp file
#include "birthday.h"
#include <iostream>
using namespace std;
Birthday::Birthday(double m, double d, double y)
{
month = m;
day = d;
year = y;
}
int main()
{
double birthmonth1,
birthdate1,
birthyear1;
cout << "Enter the birthmonth for 1st person: " << endl;
cin >> birthmonth1;
cout << "Enter the birthdate for 1st person: " << endl;
cin >> birthdate1;
cout << "Enter the birthyear for 1st person: " << endl;
cin >> birthyear1;
double birthmonth2,
birthdate2,
birthyear2;
cout << "Enter the birthmonth for 2nd person: " << endl;
cin >> birthmonth2;
cout << "Enter the birthdate for 2nd person: " << endl;
cin >> birthdate2;
cout << "Enter the birthyear for 2nd person: " << endl;
cin >> birthyear2;
Birthday birthinfo(birthmonth1, birthdate1, birthyear1);
Birthday birthinfo2(birthmonth2, birthdate2, birthyear2);
cout << "The birthmonth of 1st person is: " << birthinfo.getmonth() << endl;
cout << "The birthdate of 1st person is: " << birthinfo.getday() << endl;
cout << "The birthyear of 1st person is: " << birthinfo.getyear() << endl;
cout << "/************************************* " << endl;
cout << "The birthmonth of 2nd person is: " << birthinfo2.getmonth() << endl;
cout << " The birthdate of 2nd person is: " << birthinfo2.getday() << endl;
cout << "The birth year of 2nd person is: " << birthinfo2.getyear() << endl;
};
Topic: classes and array Create a class called birthday. The class should store the birthday of a person in the three integers: month, day and year. birthday class has member functions to get these values and return them to the user. birthday class takes the three values through the constructor. outside the class, define a function called compareBDs that finds who is older among two persons. create an array of four objects in the main function. search the aray to find the youngest person. Notes: please take your time, no rush. please follow the directions, it must have an array. create separate header for class definitions language is: c++Explanation / Answer
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class birthday
{
public:
char Name[128];
char dob[10];
};
birthday getbirthday()
{
birthday Birthday;
cout << " Enter enter person name "
<< "Name: ";
cin >> Birthday.Name;
cout << "Date of birth: ";
cin >> Birthday.dob;
return birthday;
}
int getPeople(birthday people[], int nMaxSize)
{
int index;
for(index = 0; index < nMaxSize; index++)
{
char cAnswer;
cout << "Enter another name? (Y or N): ";
cin >> cAnswer;
if(cAnswer != 'Y' && cAnswer != 'y')
{
break;
}
people[index] = getbirthday();
}
return index;
}
void displaybirthday(birthday Birthday)
{
cout << "Name: " << birthday.Name << endl;
cout << "Date of Birth: " << birthday.dob << endl;
}
void displayPeople(birthday people[], int nCount)
{
for(int index = 0;index < nCount; index++)
{
displaybirthday(people[index]);
}
}
void CompareBDS(birthday people[], int nCount)
{
int nSwaps = 1;
while(nSwaps != 0)
{
nSwaps = 0;
for(int n = 0; n < (nCount - 1); n++)
{
if(people[n].ndob > people[n+1].ndob)
{
birthday temp = people[n+1];
people[n+1] = people [n];
people[n] = temp;
nSwaps++;
}
}
}
}
int main(int nNumberofArgs,char* pszArgs[])
{
birthday people[128];
cout << "This program stores names,DOB ";
int nCount = getPeople(people, 128);
CompareBDS(people, nCount);
cout << " Here is the list sorted by "
<< "dob" << endl;
displayPeople(people,nCount);
system("PAUSE");
return 0;
}