Hello i'm making a program witch calculates age gap of humans.
I need to pass name and birthday to my Human class and i can't figure out how.
Here is my code:
#include <iostream>
usingnamespace std;
class Human{
public:
string * name;
int * birth;
Human(string * s, int * i) : name(s), birth(i){}; //Constructor passing address of name and birthday values.
};
int main()
{
constchar buff[] = "Tom 1993 \n Jim 1983";
Human human1(/*Need to pass pointer to Tom*/, /*Need to pass pointer to 1993*/);
Human human2(/*Need to pass pointer to Jim*/, /*Need to pass pointer to 1983*/);
cout << (*human1.name) <<" and "<< (*human2.name) <<" age gap is: "<< (*human1.birth) - (*human2.birth) << endl;
return 0;
}
#include <iostream>
#include <sstream>
#include <string>
usingnamespace std;
class Human {
public:
string name;
int birth;
Human(string s, int i) : name(s), birth(i) {};
};
int main() {
constchar buff[] = "Tom 1993 \n Jim 1983";
istringstream sin(buff);
string name;
int year;
sin >> name >> year;
Human human1(name, year);
sin >> name >> year;
Human human2(name, year);
cout << human1.name <<" and "<< human2.name <<" age gap is: "
<< human1.birth - human2.birth << endl;
}