** Link to the original question is given at the bottom **
Refer to "Course.h", "Course.cpp" and "main.cpp" code
Student.h
#pragma once
#include <string>
using namespace std;
class Student {
private:
string fname;
string lname;
int age;
string address;
string city;
string phone;
public:
Student();
~Student();
Student(string, string, int, string, string, string);
};
Student.cpp
#include "Student.h"
#include <string>
using namespace std;
Student::Student(){
}
Student::~Student(){
}
Student::Student(string _fname, string _lname, int _age, string _address, string _city, string _phone) {
fname = _fname;
lname = _lname;
age = _age;
address = _address;
city = _city;
phone = _phone;
}
Course.h
#pragma once
#include <string>
#include "Student.h"
class Course {
private:
string course_name = "Intermediate C++";
Student student[3]; // Need data of three students
public:
Course();
~Course();
// *Create some constructor to pass student data*
string getCourseName();
};
Course.cpp
#include "Course.h"
#include "Student.h"
using namespace std;
Course::Course(){
}
Course::~Course(){
}
string Course::getCourseName() {
return this->course_name;
}
Main.cpp
#include <iostream>
#include "Student.h"
#include "Course.h"
using namespace std;
int main() {
Student student1("fName_1","lName_1",18,"address_1","city_1","phone_1");
Student student2("fName_2","lName_2",19,"address_2","city_2","phone_2");
Student student3("fName_3","lName_3",20,"address_3","city_3","phone_3");
Course *course = new Course;
system("pause");
return 0;
}
Now, how do I pass all the three student objects to the course object?
Original Question Link: http://ift.tt/2iBUkxp
Refer to "Module Two" -> "Lab"
Aucun commentaire:
Enregistrer un commentaire