Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #define SIZE 50
- using namespace std;
- class Student {
- private:
- char* name;
- int course;
- bool gender;
- public:
- string s_gender;
- Student() {
- name = new char[SIZE];
- }
- Student(char* _name, int _course, bool _gender) : Student() {
- strcpy(name, _name);
- course = _course;
- gender = _gender;
- }
- ~Student() {
- delete[] name;
- }
- void set() {
- cout << "Student information:" << endl;
- cout << "Enter name: ";
- cin >> name;
- cout << "Enter course: ";
- cin >> course;
- cout << "Enter gender (male or female): ";
- cin >> gender;
- if (s_gender == "male") {
- gender = false;
- }
- else if (s_gender == "female") {
- gender = true;
- }
- else {
- cout << "error";
- exit(1);
- }
- cout << endl;
- }
- void get() {
- cout << "Student information:" << endl;
- cout << "Name: " << name << endl;
- cout << "Course: " << course << endl;
- cout << "Gender: " << gender << endl << endl;
- }
- friend istream& operator >> (istream& is, Student& x);
- friend ostream& operator << (ostream& os, Student& x);
- };
- istream& operator >> (istream& is, Student& x) {
- //string s_gender;
- cout << "Student information:" << endl;
- cout << "Enter name: ";
- is >> x.name;
- cout << "Enter course: ";
- is >> x.course;
- cout << "Enter gender (male or female): ";
- is >> x.gender;
- if (s_gender == "male") {
- gender = false;
- }
- else if (s_gender == "female") {
- gender = true;
- }
- else {
- cout << "error";
- exit(1);
- }
- cout << endl;
- return is;
- }
- ostream& operator << (ostream& os, Student& x) {
- os << "Student information:" << endl;
- os << "Name: " << x.name << endl;
- os << "Course " << x.course << endl;
- os << "Gender: " << x.gender<< endl;
- os << endl;
- }
- int main() {
- Student x;
- cin >> x;
- cout << "Test by cout: " << endl;
- cout << x;
- cout << "Test by get(): " << endl;
- x.get();
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement