domingo, 22 de febrero de 2015

Herencia Visual C++



#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

//defino una clase vacia
class Advisor {};

class Student
{
public:

 Student( const char *pName = "no name" ) : name( pName ) , average( 0.0 ) , semesterHours( 0 )
 {
  cout << "Construyendo Student " << name << endl;
 }

 void addCourse( int hours , float grade )
 {
  cout << "Agregando grado a " << name << endl;
  average = semesterHours * average + grade;
  semesterHours += hours;
  average = average / semesterHours;
 }

 int hours()
 {
  return semesterHours;
 }

 double gpa()
 {
  return average;
 }

protected:
 string name;
 double average;
 int semesterHours;
};

class GraduateStudent : public Student
{
public:

 GraduateStudent( const char *pName , Advisor adv , double qG = 0.0 )
 {
  cout << "Construyendo graduate student " << pName << endl;
 }

 double qualifier()
 {
  return qualifierGrade;
 }

protected:
 Advisor advisor;
 double qualifierGrade;
};

int main( int argc , char *argv[] )
{
 Advisor adv;

 Student s1("Kenny");
 GraduateStudent s2("Dariana" , adv , 1.5 );

 s1.addCourse( 3 , 2.5 );
 s2.addCourse( 3 , 3.0 );

 cout << "Dariana grado de calificacion: " << s2.qualifier() << endl;

 system("pause");
 return 0;
}



No hay comentarios:

Publicar un comentario