In: Computer Science
C++ HW
Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student.
last name,
first name,
credits,
gpa,
date of birth,
matriculation date,
** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
If you have any doubts, please give me comment...
#include<iostream>
using namespace std;
class Student{
private:
string lastName;
string firstName;
int credits;
double gpa;
string dateOfBirth;
string matriculationDate;
public:
Student(){
lastName = "";
firstName = "";
credits = 0;
gpa = 0.0;
dateOfBirth = "01/01/1901";
matriculationDate = "01/01/2000";
}
Student(string lname, string fname, int _credits, double _gpa, string dob, string matricDate){
lastName = lname;
firstName = fname;
credits = _credits;
gpa = _gpa;
dateOfBirth = dob;
matriculationDate = matricDate;
}
void setLastName(const string &lname){
lastName = lname;
}
void setFirstName(const string &fname){
firstName = fname;
}
void setCredits(int _credits){
credits = _credits;
}
void setGpa(double _gpa){
gpa = _gpa;
}
void setDateOfBirth(string dob){
dateOfBirth = dob;
}
void setMatriculationDate(string matricDate){
matriculationDate = matricDate;
}
string getLastName(){
return lastName;
}
string getFirstName() const{
return firstName;
}
int getCredits() const{
return credits;
}
double getGpa() const{
return gpa;
}
string getDateOfBirth() const{
return dateOfBirth;
}
string getMatriculationDate() const{
return matriculationDate;
}
friend ostream &operator<<(ostream &out, const Student &student);
};
ostream &operator<<(ostream &out, const Student &student){
out<<"Name: "<<student.firstName<<", "<<student.lastName<<endl;
out<<"Credits: "<<student.credits<<endl;
out<<"GPA: "<<student.gpa<<endl;
out<<"Date of Birth: "<<student.dateOfBirth<<endl;
out<<"Matriculation Date: "<<student.matriculationDate<<endl;
return out;
}
int main(){
Student student;
cout<<"By student default argument constructor"<<endl;
cout<<student<<endl;
Student student2("NAGA", "ANU", 40, 3.5, "10-03-1993", "05-05-2009");
cout<<"By initializing all parameters"<<endl;
cout<<student2<<endl;
return 0;
}