SHARE
TWEET

Fctii friend Elev Profesor

madalinaradu Mar 26th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdlib.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<conio.h>
  5.  
  6. using namespace std;
  7.  
  8. class Elev;
  9. class Profesor{
  10.     private:
  11.         char nume[30];
  12.     public:
  13.         Profesor(char*nume){
  14.         strcpy (this->nume,nume);  
  15.         };//C cu parametri
  16.        
  17.        
  18.     void afisare(){
  19.         cout<<"nume profesor"<<this->nume<<endl;
  20.         }
  21.     void setMedia(Elev &e, float media);
  22.        
  23. };
  24.  
  25. class Elev{
  26.     private:
  27.         char nume[30];
  28.         float media;
  29.         void setMedia(float media);
  30.     public:
  31.         Elev(char *nume, float media){
  32.             strcpy(this->nume,nume);
  33.             this->media=media;
  34.         }
  35.         void afisare(){
  36.             cout<<"Nume elev:"<<" "<<endl;
  37.         }
  38.         friend void Profesor::setMedia(Elev &e, float media);
  39. };
  40. void Profesor::setMedia(Elev &e, float media){
  41.     if(media>=0 && media<=10)
  42.             e.media=media;
  43.     cout<<"Eroare"<<endl;
  44.         }
  45.  
  46.  
  47. Elev::Elev(char *nume, float media=0){
  48.     strcpy(this->nume, nume);
  49.     this->media=media;
  50.     }
  51.     Elev::afisare(){
  52.         cout<<"nume elev"<<this->nume<<endl;
  53.         cout<<"media:"<<this->media<<endl;
  54.        
  55.     }
  56.     void Elev::setMedia(float media){
  57.         this->media=media;
  58.     }
  59.     int main(){
  60.         Elev e1("X", 9);
  61.         e1.afisare();
  62.         Profesor p1("Y");
  63.    
  64.         p1.afisare();
  65.         cout<<"se schimba media"<<endl;
  66.         p1.setMedia(e1, 10);
  67.         e1.afisare();
  68.         _getch();
  69.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top