Programación C++ - Oldemar Rodríguez Rojas

Anuncio
Programación C++ (2°Parte)
Dr. Oldemar Rodríguez Rojas
Escuela De Informática
Universidad Nacional
<EjemploP2-3B> Otra implementación de “Persona”
class Persona {
string Nombre;
int Edad;
public:
Persona(string Nom, int Ed);
void Muestra();
void SetNombre(string NuevoNom);
void SetEdad(int NuevaEdad);
string GetNombre();
int GetEdad();
};
<EjemploP2-4> Uso del puntero this
bool Compare(CBox& xBox)
{
return this->Volume() > xBox.Volume();
}
Miembros Estáticos en una Clase
<EjemploP2-5>
<EjemploP2-6> Punteros a Objetos
bool Compare(CBox* pBox) const
{
if(!pBox)
return 0;
return this->Volume() > pBox->Volume();
}
<EjemploP2-7> Programación C++/CLI : value class
value class Height
{
private:
int feet;
int inches;
public:
Height(int ins)
{
feet = ins/12;
inches = ins%12;
}
Height(int ft, int ins) : feet(ft), inches(ins) {}
};
<EjemploP2-8> C++/CLI  Método ToString
#include "stdafx.h"
#include <iostream>
using std::cin;
using namespace System;
int main(array<System::String ^> ^args)
{
char ch;
double pi=3.142;
Console::WriteLine(pi.ToString());
cin >> ch;
return 0;
}
<EjemploP2-9> C++/CLI  Método ToString
// Create a string representation of the object
virtual String^ ToString() override
{
return feet + L" feet "+ inches + L" inches";
}
GRACIAS…
Descargar