Alx09

Lab 1 POO

Sep 28th, 2020 (edited)
742
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Sofer {
  6. private:
  7.     char *name, *cnp, *adresa;
  8.     int age;
  9.  
  10. public:
  11.     void Read();
  12.     void Show();
  13.  
  14. };
  15.  
  16.  
  17. void Sofer::Read() {
  18.  
  19.     char name[20], cnp[20], adresa[40];
  20.     unsigned short age;
  21.     cout << "name Sofer= "; cin >> name;
  22.     cout << "CNP = "; cin >> cnp;
  23.     cout << "Adresa = "; cin >> adresa;
  24.  
  25.     cout << "age = "; cin >> age;
  26.     cout << endl;
  27.     this->name = new char[strlen(name) + 1];
  28.     strcpy(this->name, name);
  29.  
  30.     this->cnp = new char[strlen(cnp) + 1];
  31.     strcpy(this->cnp, cnp);
  32.  
  33.     this->adresa = new char[strlen(adresa) + 1];
  34.     strcpy(this->adresa, adresa);
  35.     this->age = age;
  36.  
  37. }
  38.  
  39. void Sofer::Show() {
  40.     cout << "name Sofer: " << name << "\n";
  41.     cout << "CNP: " << cnp << "\n";
  42.     cout << "Adresa: " << adresa << "\n";
  43.     cout << "age: " << age << "\n\n";
  44. }
  45.  
  46. class Masina : public Sofer {
  47. private:
  48.     char *model, *producator;
  49.     int an_Fab;
  50.     Sofer Driver;
  51. public:
  52.  
  53.     void Show();
  54.     void Read();
  55. };
  56. void Masina::Show() {
  57.     cout << "Producator: " << producator << "\n";
  58.     cout << "Model: " << model << "\n";
  59.     cout << "Adresa: " << an_Fab << "\n\n";
  60.     Driver.Show();
  61.  
  62. }
  63.  
  64. void Masina::Read() {
  65.     char model[20], producator[20];
  66.     cout << "Producator = "; cin >> producator;
  67.     cout << "Model = "; cin >> model;
  68.     cout << "An fabricate = "; cin >> an_Fab;
  69.  
  70.     cout << endl;
  71.     this->producator = new char[strlen(producator) + 1];
  72.     strcpy(this->producator, producator);
  73.     this->model = new char[strlen(model) + 1];
  74.     strcpy(this->model, model);
  75.     Driver.Read();
  76. }
  77.  
  78. class Dates {
  79. private:
  80.     char *name, *prename, *adresa, *nr_telefon;
  81.     int age;
  82. public:
  83.     void Read();
  84.     void Show();
  85. };
  86. void Dates::Read() {
  87.     char name[20], prename[20], adresa[40], nr_telefon[20];
  88.     int age;
  89.     cout << "name = "; cin >> name;
  90.     cout << "Prename = "; cin >> prename;
  91.     cout << "Adresa = "; cin >> adresa;
  92.     cout << "Numar de telefon  = "; cin >> nr_telefon;
  93.     cout << "age = "; cin >> age;
  94.     cout << endl;
  95.     this->name = new char[strlen(name) + 1];
  96.     strcpy(this->name, name);
  97.  
  98.     this->prename = new char[strlen(prename) + 1];
  99.     strcpy(this->prename, prename);
  100.  
  101.     this->adresa = new char[strlen(adresa) + 1];
  102.     strcpy(this->adresa, adresa);
  103.  
  104.     this->nr_telefon = new char[strlen(nr_telefon) + 1];
  105.     strcpy(this->nr_telefon, nr_telefon);
  106.  
  107.     this->age = age;
  108. }
  109.  
  110. void Dates::Show() {
  111.     cout << "name: " << name << "\n";
  112.     cout << "Prename: " << prename << "\n";
  113.     cout << "Adresa: " << adresa << "\n";
  114.     cout << "Numar telefon: " << nr_telefon << "\n";
  115.     cout << "age: " << age << "\n\n";
  116. }
  117.  
  118. int main() {
  119.     Dates Stud;
  120.     Stud.Read();
  121.     Stud.Show();
  122.     Masina Audi;
  123.         Audi.Read();
  124.     Audi.Show();
  125. }
RAW Paste Data