summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Studenten/Student.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Prog2/Studenten/Student.cpp')
-rw-r--r--Bachelor/Prog2/Studenten/Student.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Studenten/Student.cpp b/Bachelor/Prog2/Studenten/Student.cpp
new file mode 100644
index 0000000..d8f0b00
--- /dev/null
+++ b/Bachelor/Prog2/Studenten/Student.cpp
@@ -0,0 +1,49 @@
+// Student.cpp: Implementation of class Student.
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::istream;
+using std::ostream;
+
+#include <string>
+using std::string;
+using std::getline;
+
+#include "Student.h"
+
+Student::Student()
+{
+}
+
+Student::~Student()
+{
+}
+
+void Student::set( string n, int m, int a )
+{
+ name = n;
+ matNr = m;
+ age = a;
+}
+
+void Student::print()
+{
+ cout << name << ", Matrikelnummer: " << matNr << ", Alter: " << age << endl;
+}
+
+ostream& Student::write( std::ostream& os ) const
+{
+// os.write( ( char* )&matNr, sizeof matNr ); // stores '578111' as an int in 4 Bytes
+// os << matNr; // stores '578111' as ASCII-Code in 6 Bytes!
+ os << name << '\0'; // write string
+ os.write( ( char* ) &matNr, 2 * sizeof( int ) ); // write 2 int starting at address of matNr
+ return os;
+}
+
+istream& Student::read( std::istream& is )
+{
+ getline( is, name, '\0' ); // read string
+ is.read( ( char* ) &matNr, 2 * sizeof( int ) ); // read 2 int starting at address of matNr
+ return is;
+} \ No newline at end of file