Hello, I am having trouble with this code in c++ for my advance data structure course . I am using the onlinegdb.com complier and get this small issue. I have provided both the snip of the result as well as the code. main.cpp #include #include"Student.h" #include #include "Student.h" #include "Faculty.h" using namespace std; int main() { Student std("John","Smith",3.75,"Spring 2019"); Faculty faculty("Mary","Smith","2019"); cout<<"===========================================\n"; faculty.Print(); cout<<"===========================================\n"; cout<<"\n\n\n"; cout<<"===========================================\n"; std.Print(); cout<<"===========================================\n"; return 0; } Person.h ifndef PERSON_H #define PERSON_H #include #include using namespace std; class Person { private: int personID; string firstName; string lastName; public: Person(string fName, string lName); string getFirstName(); string getLastName(); int getID(); virtual void Print() = 0; static int nextID; }; #endif Person.cpp #include #include "Person.h" using namespace std; int Person::nextID = 0; Person::Person(string fName, string lName){ nextID=nextID+1; personID=nextID; this->firstName=fName; this->lastName=lName; } string Person::getFirstName(){ return firstName; } string Person::getLastName(){ return lastName; } int Person::getID(){ return personID; } Student.h #ifndef STUDENT_H #define STUDENT_H #include #include #include "Person.h" using namespace std; class Student : public Person { private: float gpa; string admissionTerm; public: Student(string fName, string lName, float gpa, string adTerm); bool setGPA(float gpa); float getGPA(); string getAdmissionTerm(); void Print(); }; #endif Student.cpp #include #include #include "Student.h" #include using namespace std; Student::Student(string fName, string lName, float gpa, string adTerm): Person(fName, lName){ setGPA(gpa); admissionTerm=adTerm; } bool Student::setGPA(float gpa){ if(gpa<0 || gpa>4){ gpa=0; return false; } else this->gpa=gpa; } float Student::getGPA(){ return gpa; } string Student::getAdmissionTerm(){ return admissionTerm; } void Student::Print(){ cout< #include #include "Person.h" using namespace std; class Faculty : public Person{ private: string year; public: Faculty(string fName, string lName,string year); string getYear(); void Print(); }; #endif Faculty.cpp #include #include #include"Faculty.h" #include using namespace std; Faculty::Faculty(string fName, string lName, string year) : Person(fName, lName){ this->year=year; } string Faculty::getYear(){ return year; } void Faculty::Print(){ cout<
Hello, I am having trouble with this code in c++ for my advance data structure course . I am using the onlinegdb.com complier and get this small issue. I have provided both the snip of the result as well as the code.
main.cpp
#include<iostream>
#include"Student.h"
#include<iostream>
#include "Student.h"
#include "Faculty.h"
using namespace std;
int main()
{
Student std("John","Smith",3.75,"Spring 2019");
Faculty faculty("Mary","Smith","2019");
cout<<"===========================================\n";
faculty.Print();
cout<<"===========================================\n";
cout<<"\n\n\n";
cout<<"===========================================\n";
std.Print();
cout<<"===========================================\n";
return 0;
}
Person.h
ifndef PERSON_H
#define PERSON_H
#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
int personID;
string firstName;
string lastName;
public:
Person(string fName, string lName);
string getFirstName();
string getLastName();
int getID();
virtual void Print() = 0;
static int nextID;
};
#endif
Person.cpp
#include<iostream>
#include "Person.h"
using namespace std;
int Person::nextID = 0;
Person::Person(string fName, string lName){
nextID=nextID+1;
personID=nextID;
this->firstName=fName;
this->lastName=lName;
}
string Person::getFirstName(){
return firstName;
}
string Person::getLastName(){
return lastName;
}
int Person::getID(){
return personID;
}
Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include<string>
#include "Person.h"
using namespace std;
class Student : public Person
{
private:
float gpa;
string admissionTerm;
public:
Student(string fName, string lName, float gpa, string adTerm);
bool setGPA(float gpa);
float getGPA();
string getAdmissionTerm();
void Print();
};
#endif
Student.cpp
#include<iostream>
#include<iomanip>
#include "Student.h"
#include<string>
using namespace std;
Student::Student(string fName, string lName, float gpa, string adTerm): Person(fName, lName){
setGPA(gpa);
admissionTerm=adTerm;
}
bool Student::setGPA(float gpa){
if(gpa<0 || gpa>4){
gpa=0;
return false;
}
else
this->gpa=gpa;
}
float Student::getGPA(){
return gpa;
}
string Student::getAdmissionTerm(){
return admissionTerm;
}
void Student::Print(){
cout<<fixed<<setprecision(2);
cout<<left<<setw(20)<<"Student First Name "
<<":"<<setw(20)<<getFirstName()<<endl;
cout<<left<<setw(20)<<"Student Last Name "
<<":"<<setw(20)<<getLastName()<<endl;
cout<<left<<setw(20)<<"Student ID "
<<":"<<setw(20)<<getID()<<endl;
cout<<left<<setw(20)<<"Student GPA "
<<":"<<setw(20)<<getGPA()<<endl;
cout<<left<<setw(20)<<"Student Admit Term "
<<":"<<setw(20)<<getAdmissionTerm()<<endl;
}
Faculty.h
#ifndef FACULTY_H
#define FACULTY_H
#include<iostream>
#include<string>
#include "Person.h"
using namespace std;
class Faculty : public Person{
private:
string year;
public:
Faculty(string fName, string lName,string year);
string getYear();
void Print();
};
#endif
Faculty.cpp
#include<iostream>
#include<iomanip>
#include"Faculty.h"
#include<string>
using namespace std;
Faculty::Faculty(string fName, string lName, string year) : Person(fName, lName){
this->year=year;
}
string Faculty::getYear(){
return year;
}
void Faculty::Print(){
cout<<fixed<<setprecision(2);
cout<<left<<setw(20)<<"Faculty First Name "
<<":"<<setw(20)<<getFirstName()<<endl;
cout<<left<<setw(20)<<"Faculty Last Name "
<<":"<<setw(20)<<getLastName()<<endl;
cout<<left<<setw(20)<<"Faculty ID "
<<":"<<setw(20)<<getID()<<endl;
cout<<left<<setw(20)<<"Faculty Hire Year "
<<":"<<setw(20)<<getYear()<<endl;
}
![Student.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
17 | }
|
Faculty First Name
Faculty Last Name
Faculty ID
Faculty Hire Year
:Mary
:Smith
:2
:2019
=====
====== =====
====
=====
====== ================ =========== ==========
Student First Name
:John
Student Last Name
:Smith
Student ID
:1
Student GPA
:3.75
Student Admit Term
:Spring 2019
====== ================ ========
==== ====
...Program finished with exit code 0
Press ENTER to exit console. |](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F86bfc21f-7304-4d6a-8ae3-de059a5180e7%2Fde05ee48-5d13-4027-9103-210712bf3603%2Fgly5yag_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)