So for my task, I have 3 classes, Student, Date, and Address. Student class has two instances of the Date class and one of the Address class.
My goal is to be able to from the main.cpp create an array of objects from the Student class. I have tried a few different ways but I run into various problems.
edit: This has been marked as a duplicate but all of the other questions I find don't fully/sufficiently answer my question for what I am trying to do here, please link me to a question that does as I cannot find it. I am trying to create an object from class Student that also has objects from classes date and address.
Here is my code now in relevant files.
student.cpp
#include "student.h"
using namespace std;
Student::Student(){
Student::fName = "";
Student::lName = "";
Student::gpa = "";
Student::credits = "";
Student::address;
Student::dBirth;
Student::dGraduation;
}//end Default Constructor
Student::Student(string firstName, string lastName, string s_gpa, string s_credits, Date *s_dBirth, Date *s_dGraduation, Address *s_address){
Student::fName = firstName;
Student::lName = lastName;
Student::gpa = s_gpa;
Student::credits = s_credits;
Student::dBirth = s_dBirth;
Student::dGraduation = s_dGraduation;
Student::address = s_address;
}//end Constructor
student.h
#ifndef STUDENT_H
#define STUDENT_H
#include <string>
#include <iostream>
#include "date.h"
#include "address.h"
class Student{
private:
std::string fName;
std::string lName;
std::string gpa;
std::string credits;
Date *dBirth;
Date *dGraduation;
Address *address;
public:
Student();//Default constructor
Student(std::string fName, std::string lName, std::string gpa, std::string credits, Date *dBirth, Date *dGraduation, Address *address);//Constructor
~Student();//Destructor
};//end Student Class
#endif // STUDENT_H
date.cpp
#include "date.h"
using namespace std;
Date::Date(){
Date::month = 0;
Date::day = 0;
Date::year = 0;
}//End default constructor
Date::Date(int sMonth, int sDay, int sYear){
Date::month = sMonth;
Date::day = sDay;
Date::year = sYear;
}//End constructor
date.h
#ifndef DATE_H
#define DATE_H
#include <string>
#include <iostream>
class Date{
private:
int month;
int day;
int year;
public:
Date();
Date(int month, int day, int year);
std::string getDate();
};//end Date Class
#endif // DATE_H
address.cpp
#include "address.h"
using namespace std;
Address::Address(){
Address::aLine1 = "";
Address::aLine1 = "";
Address::city = "";
Address::state = "";
Address:zip = "";
}//end Default Constructor
Address::Address(string line1, string line2, string sCity, string sState, string sZip){
Address::aLine1 = line1;
Address::aLine2 = line2;
Address::city = sCity;
Address::state = sState;
Address::zip = sZip;
}//End Constructor
address.h
#ifndef ADDRESS_H
#define ADDRESS_H
#include <string>
#include <iostream>
class Address{
private:
std::string aLine1;
std::string aLine2;
std::string city;
std::string state;
std::string zip;
public:
Address();
Address(std::string aLine1, std::string aLine2, std::string city, std::string state, std::string zip);
std::string getAddress();
};
#endif // ADDRESS_H
I am fairly new to C++, any and all help is greatly appreciated.