Quantum redactiones paginae "C++" differant
Content deleted Content added
Linea 54:
=== Classes et obiecta ===
C++ ad C syntaxim [[lingua obiecta spectans|linguarum obiecta spectantium]] introduxit. Classibus cum definiuntur praebentur : abstractio, incapsulatio, hereditas, polymorphismus, et superpositio. Classis ita cogitari potest ut forma ex qua obiecta individua cudantur cum programma operatur. Classis definita idem ac int aut float in programmate fungit, et obiecta declarata idem ac variabiles huius classis. Classes igitur sinunt programmatores omnino nova genera variabilium definire et adhibere quae similia sunt int, float, etc.
<source lang="cpp">
#include <iostream>
#include <cstring>
using namespace std;
class persona()
{
public: //haec data et functiones publice commutari et haberi possunt
string nomen;
int aetasData();
private: //haec data et functiones sola per methodos huius classis commutari et haveri possunt
int annusPraesens = 2013;
int annusNatalis;
int aetas;
void aetatemPonere();
};
void persona::aetatemPonere() //Sola hac methodo aetas personae poni potest
{
cout<<"Quo anno natus est?"
cin>>annusNatalis;
aetas= 2013-annusNatalis;
}
int persona::aetasData() //Sola hac methodo aetas personae dari potest
{
return aetas;
}
void persona::persona() //Hic est classis constructor
{
cout<<"Nomen?";
cin>>nomen;
aetatemPonere();
}
int main()
{
persona Maria;
persona *Caesar = new Persona;
cout<<Maria.nomen<<" "<<Maria.aetasData()<<endl;
cout<<Caesar->nomen<<" "<<Caesar->aetasData()<<endl;
}
</source>
<!--
Encapsulation
The OO principle is that all of the functions (and only the functions) that access the internal representation of a type should be encapsulated within the type definition. C++ supports this (via member functions and friend functions), but does not enforce it: the programmer can declare parts or all of the representation of a type to be public, and is allowed to make public entities that are not part of the representation of the type. Because of this, C++ supports not just OO programming, but other weaker decomposition paradigms, like modular programming.
|