C++ help with some programming homework can you please help THANK YOU!! #include
ID: 646023 • Letter: C
Question
C++ help with some programming homework can you please help THANK YOU!!
#include <iostream>
#include <string>
using namespace std;
// Add an overloaded << operator to this class to print the student record
// in the following format (no newline at the end).
// (In this example, the student is "John Doe" with a netID of jdoe123:
// Doe, John (jdoe13)
class Student
{
private:
string last;
string first;
string netID;
public:
// Constructor
Student(const string lastName, const string firstName, const string ID);
// Here is the prototype for the overloaded << operator
friend ostream& operator<<(ostream& out, Student& s);
};
Student::Student(const string lastName, const string firstName,
const string ID)
{
last = lastName;
first = firstName;
netID = ID;
}
////////////// IMPLEMENT operator<< HERE ///////////////////
////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
// Here's the example student
Student jd("Doe", "John", "jdoe123");
// And here's how it's output
cout << jd << endl;
return 0;
}
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
// Add an overloaded << operator to this class to print the student record
// in the following format (no newline at the end).
// (In this example, the student is "John Doe" with a netID of jdoe123:
// Doe, John (jdoe13)
class Student
{
private:
string last;
string first;
string netID;
public:
// Constructor
Student(const string lastName, const string firstName, const string ID);
// Here is the prototype for the overloaded << operator
friend ostream& operator<<(ostream& out, Student& s);
};
Student::Student(const string lastName, const string firstName,
const string ID)
{
last = lastName;
first = firstName;
netID = ID;
}
////////////// IMPLEMENT operator<< HERE ///////////////////
ostream &operator<<(ostream& out, Student& s){
out << s.last << ", " << s.first << " (" << s.netID << ")" << endl;
return out;
}
////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
// Here's the example student
Student jd("Doe", "John", "jdoe123");
// And here's how it's output
cout << jd << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.