Professional Documents
Culture Documents
Приклад створення класу
Приклад створення класу
#include "pch.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
}
Cat(string _name, int _year_of_birth, double _lenght)
{
cout << "Parametrized constructor run" << endl;
name = _name;
year_of_birth = _year_of_birth;
Length = _lenght;
}
~Cat()
{
cout << "Destructor run" << endl;
}
double GetLenght()
{
return Length;
}
void SetLenght(double _lenght)
{
Length = _lenght;
}
}; // кінець оголошення класу
int main()
{
Cat cat1, cat2("Barsic", 2016, 25);
cat1.GetInfo();
cat2.GetInfo();
cat1.SetLenght(30);
cat1.GetInfo();
_getch();
}