Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Passing Array through object composition (C++)

Person.h

#pragma once
#include<iostream>
#include<string>
#include"birthday.h"
using namespace std;

class Person
{

public:

    Person()
    {
        name[100] = " ";
    };
    Person(string n[100], Birthday b);

    void printperson();
    void setName(string n)
    {
        name[100] = n;
    };
    string getName()
    {
        return name[100];
    };
    void setBirthday(Birthday b)
    {
        birth = b;
    };
    Birthday getBirthday()
    {
        return birth;
    };

protected:

private:

    string name[100];
    Birthday birth;
};

Person.cpp

#include<iostream>
#include"Birthday.h"
#include"Person.h"
#include<string>
using namespace std;

Person::Person(string n[100], Birthday b) : name(n[100]), birth(b)
{
    name[100] = n[100];
}

void Person::printperson()
{
    cout << "This person is " << name << ". Thier birthday is " << endl;
    birth.printbirthday();
}

main.cpp

#include<iostream>
#include<string>
#include"person.h"
#include"birthday.h"
using namespace std;

int main()
{

    string name[100];
    int month, day, year;
    Birthday birth[100];
    int people[100];

    for (int i = 0; i < 100; i++)
    {

        cout << "enter name." << endl;
        cin >> name[i];

        cout << "enter month." << endl;
        cin >> month;
        birth[i].setMonth(month);

        cout << "enter day." << endl;
        cin >> day;
        birth[i].setDay(day);

        cout << "enter year." << endl;
        cin >> year;
        birth[i].setYear(year);

        Person Chris(name[i], birth);

        Chris.printperson();

    }

    system("pause");
    return 0;
}

Hello. I've been trying to understand object composition in C++ and got stuck once I included an array. I had this working when the string for name was not an array but once I started to store the string as an array i couldn't figure it out. I have no problems as of now converting the birthday ints into arrays but not sure whats going wrong with the string. I keep having problems with the line :name(n[100]), birth(b).

Comments