Programacion Orientada A Objetos II
OBJETOS II
Facultad de Ciencias de la Computacion.
Eduardo Gallardo Perez
Miguel Rodriguez
201427701
Planteamiento del Problema (Documento).
Práctica No. 1. "ListasLigadas”
Objetivo: El alumno analiza, diseña e implementa listas ligadas que dan
solución a los problemas planteados.
Problem:
Define a class ListOfPersons, each of whose objects maintains theinformation
about a sequence of objects of a class Person (for each person, the information
of interest are the name, surname, age, and city of residence). The class
ListOfPersons should provide, besides themethods for insertion, deletion and
modification of a person, a method to print all persons in the list, a method to
count the number of persons in the list that live in a given city passed asparameter,
and a method that computes the average age of all persons in the list.
Develop a class diagram of the problem and implement the solution in C++
language programming.
Modelo star UML.
Código desolución.
#include
#include
using namespace std;
class Persona{
private:
string nombre;
string alias;
string ciudad;
int edad;
public:
Persona(){
nombre="";
alias="";
ciudad="";edad=0;
}
Persona(string n, string a, string c, int e){
nombre=n;
alias=a;
ciudad=c;
edad=e;
}
string getNombre(){
return nombre;
}
string getAlias(){
return alias;
}
string getCiudad(){
returnciudad;
}
int getEdad(){
return edad;
}
};
class Nodo{
public:
Persona person;
Nodo *sig;
//Nodo *ant;
Nodo(Persona p){
person=p;
sig=NULL;
}
};
class lista{
private:
Nodo *head;
Nodo *tail;
Nodo*aux;public:
lista(){
head=NULL;
tail=NULL;
}
~lista(){}
void Insertar(Persona p);
void Modificar();
void Eliminar();
int ContarElementos();
float PromedioEdades();
Nodo *Buscar();
void Listar();
intContarElementosCiudad(string ciudad);
};
void insertar()
{
string nombre[45],op;
string alias;
string ciudad;
int edad;
printf("
Escribe el nombre : ");
scanf("%s",&nombre);
printf("
scanf("...
Regístrate para leer el documento completo.