Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- using namespace std;
- class persona{
- protected:
- string nombre;
- int edad;
- public:
- persona(){}
- persona(string nom , int ed){
- nombre = nom;
- edad = ed;
- }
- ~persona(){}
- virtual string tostring(){
- stringstream stm;
- stm << nombre << " : " << edad;
- return stm.str();
- }
- };
- class estudiante : public persona{
- private:
- string ID;
- double c1 , c2;
- public:
- estudiante();
- estudiante(string nombre , int edad , string id , double ac1, double ac2 ) : persona(nombre,edad){
- ID = id;
- c1 = ac1;
- c2 = ac2;
- }
- ~estudiante(){}
- double calcularpromedio(double c1 , double c2){
- return (c1+c2)/2;
- }
- virtual string tostring(){
- stringstream tmd;
- tmd << nombre << " : " << edad << endl
- <<"Id estudiante: " << ID << " Promedio total " << calcularpromedio(c1,c2) ;
- return tmd.str();
- }
- };
- int main(){
- vector<persona*> pers;
- persona mipersona("tito",16);
- estudiante miestudiante("Josue",29,"25558",89,77);
- pers.push_back(&mipersona);
- pers.push_back(&miestudiante);
- for(unsigned int i =0; i<pers.size(); i++){
- cout << pers[i]->tostring() << endl;
- }
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement