Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- class Student{
- protected:
- string imie;
- string nazwisko;
- public:
- Student();
- Student(string,string);
- string getImie(){
- return this->imie;
- }
- string getNazwisko(){
- return this->nazwisko;
- }
- void zapisz(string src){
- fstream file;
- file.open(src.c_str(),ios::out); // .c_str() zwraca łańcuch tylko do odczytu
- file<<this->imie<<endl;
- file<<this->nazwisko<<endl;
- file.close();
- }
- void wczytaj(string src){
- fstream file;
- file.open(src.c_str(),ios::in);
- getline(file,this->imie);
- getline(file,this->nazwisko);
- file.close();
- }
- };
- Student::Student(){
- nazwisko="";
- imie="";
- }
- Student::Student(string imie,string nazwisko){
- this->nazwisko=nazwisko;
- this->imie=imie;
- }
- class StudentKierunek : public Student {
- protected:
- string kierunek;
- public:
- StudentKierunek(string,string,string);
- StudentKierunek();
- void wczytaj(string src){
- fstream file;
- file.open(src.c_str(),ios::in);
- getline(file,this->imie);
- getline(file,this->nazwisko);
- getline(file,this->kierunek);
- file.close();
- }
- void zapisz(string src){
- fstream file;
- file.open(src.c_str(),ios::out); // .c_str() zwraca łańcuch tylko do odczytu
- file<<this->imie<<endl;
- file<<this->nazwisko<<endl;
- file<<this->kierunek<<endl;
- file.close();
- }
- string getKierunek(){
- return this->kierunek;
- }
- };
- StudentKierunek::StudentKierunek(string imie,string nazwisko,string kierunek){
- this->nazwisko=nazwisko;
- this->imie=imie;
- this->kierunek=kierunek;
- }
- StudentKierunek::StudentKierunek(){
- imie="";
- nazwisko="";
- kierunek="";
- }
- int main()
- {
- string plik = "plik.txt";
- StudentKierunek s1("Imie","Nazwisko","Kierunek");
- s1.zapisz(plik);
- StudentKierunek s2;
- s2.wczytaj(plik);
- cout<< s2.getImie() << endl << s2.getNazwisko()<< endl << s2.getKierunek();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement