Advertisement
Guest User

Untitled

a guest
May 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <string>
  4. #include <vector>
  5. #include <cstring>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. class Student{
  10. private:
  11. char *nume;
  12. int varsta;
  13. int anStudiu;
  14. bool bursa;
  15. public:
  16. Student(const char *,int,int,bool);
  17. friend ostream& operator <<(ostream & f, Student & s);
  18.  
  19. bool get_bursier();
  20. char* get_nume();
  21. int get_anstudiu();
  22. int get_varsta();
  23. };
  24.  
  25. Student::Student(const char *nume, int varsta, int anStudiu, bool bursa)
  26. {
  27. if(nume!=NULL)
  28. {
  29. this->nume=new char[strlen(nume)+1];
  30. strcpy(this->nume,nume);
  31. }
  32. this->varsta=varsta;
  33. this->anStudiu=anStudiu;
  34. this->bursa=bursa;
  35. }
  36.  
  37. ostream & operator <<(ostream & f, Student & s)
  38. {
  39. cout<<s.get_nume()<<" "<<s.get_varsta()<<" "<<s.get_anstudiu()<<" "<<s.get_bursier()<<endl;
  40. return f;
  41. }
  42.  
  43. bool Student::get_bursier()
  44. {
  45. return this->bursa;
  46. }
  47.  
  48. char* Student::get_nume()
  49. {
  50. return this->nume;
  51. }
  52.  
  53. int Student::get_anstudiu()
  54. {
  55. return this->anStudiu;
  56. }
  57.  
  58. int Student::get_varsta()
  59. {
  60. return this->varsta;
  61. }
  62.  
  63. int main()
  64. {
  65. std::vector<Student> myvector;
  66. myvector.emplace_back(Student("Popa",20,2,1));
  67. myvector.emplace_back(Student("Ion",21,3,0));
  68. myvector.emplace_back(Student("Alin",21,1,1));
  69. myvector.emplace_back(Student("Elena",19,1,0));
  70. for_each(myvector.begin(),myvector.end(),[](Student & m){cout<<m;});
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement