Operaciones Básicas:
Veamos estos métodos programados en C++:
- Incluir un objeto en el vector
- Saber el tamaño del vector
- Borrar el ultimo objeto incluido en el vector
- Saber cual fue el primer objeto incluido en el vector
- Saber cual fue el ultimo objeto incluido en el vector
- Salir
#include iostream#include vector#include "Persona.h"using namespace std;int main(){vectorPersona Vec_Persona;Persona ObjetoPersona;int opcion;//Variables a usar en los métodos de inserciónstring nombre, cedula;int edad;//////////////////////////////////////////////do{cout "\n\n=========OPERACIONES BASICAS CON VECTORES==========\n";cout "==============Menu de opciones ====================\n";cout "1 Incluir un objeto en el vector \n";cout "2 Saber el tamaño del vector \n";cout "3 Borrar el ultimo objeto incluido en el vector \n";cout "4 Saber cual fue el primer objeto incluido en el vector \n";cout "5 Saber cual fue el ultimo objeto incluido en el vector \n";cout "6 Salir \n";cin opcion;switch(opcion){case 1: cout "Ingrese el nombre de la persona: \n"; cin nombre; ObjetoPersona.SetNombre(nombre); cout "Ingrese la cedula de la persona: \n"; cin cedula; ObjetoPersona.SetCedula(cedula); cout "Ingrese la edad de la persona: \n"; cin edad; ObjetoPersona.SetEdad(edad); Vec_Persona.push_back(ObjetoPersona);break;case 2: cout "El vector contiene: " Vec_Persona.size() " objetos en total \n";break;case 3: if(Vec_Persona.empty()) //La funcion empty nos indica mediante un valor booleano true o false si el vector esta vacio o no cout "No se pueden eliminar objetos por que el vector esta vacio \n"; else{ cout "Se ha eliminado a " Vec_Persona[Vec_Persona.size() - 1].GetNombre() endl; Vec_Persona.pop_back(); }break;case 4: if(Vec_Persona.empty()) cout "Ingrese un objeto antes de elegir esta opcion \n"; else cout "El primer objeto agregado es: " Vec_Persona.front().GetNombre() endl;break;case 5: if(Vec_Persona.empty()) cout "Ingrese un objeto antes de elegir esta opcion \n"; else cout "El último objeto incluido es: " Vec_Persona.back().GetNombre() endl;break;}}while(opcion != 6);}
Explicación:
Veamos la ejecución del programa:
#ifndef PERSONA_H_#define PERSONA_H_#include iostreamusing namespace std;class Persona {private: string nombre, cedula; int edad;public: Persona(); void SetNombre(string nom); string GetNombre(); void SetCedula(string ced); string GetCedula(); void SetEdad(int eda); int GetEdad();};#endif /* PERSONA_H_ */
#include "Persona.h"Persona::Persona() { // TODO Auto-generated constructor stub}void Persona::SetNombre(string nom) { nombre = nom;}string Persona::GetNombre() { return nombre;}void Persona::SetCedula(string ced) { cedula = ced;}string Persona::GetCedula() { return cedula;}void Persona::SetEdad(int eda) { edad = eda;}int Persona::GetEdad() { return edad;}
- Elemento menor de un vector en C++ (min_element)
- Elemento mayor de un vector en C++ (max_element)
- Algoritmo - Factorial de un número en C++
- Matriz de la relación predecesor inmediato en c++
- Matriz de accesibilidad de un Digrafo en c++
- Elevar un número a una potencia en C++
- 4 Ejercicios Básicos de Programación Orientada a Objetos en c++
forensics online course Donate car to charity California verizon sip Service business software truck accident attorney los angeles Online Motor Insurance Quotes mesothelioma lawyer massachusetts Cheap auto insurance in VA best structured settlement companies Live casino Social media tools california motorcycle accident lawyer Casino reviews Make money online Australia accident attorneys orange county Online casino houston mesothelioma attorney structured settlement buyers mesothelioma rates Data Recovery Raid structure settlements CHEAP CAR INSURANCE IN VIRGINIA Online Classes Hire php developer Bankruptcy lawyer car accident lawyer in san diego VIRTUAL DATA ROOMS business voice mail service mesothelioma law firm Donating Used Cars to Charity Hire php developers mesothelioma lawsuits Casino Motor Replacements Cheap Auto Insurance in VA Mobile casino Gas/Electricity semi truck accident lawyers criminal defense attorneys florida Futuristic Architecture Social media platforms mesothelioma drug DUI lawyer windows phone for business Hire php programmers Cheap car insurance in Virginia Auto Mobile Shipping Quote PhD in counseling education personal injury attorney torrance los angeles motorcycle accident lawyer caraccidentlawyer Social media examiner DONATING A CAR IN MARYLAND Html email ANNUITY SETTLEMENT New social media platforms DALLAS MESOTHELIOMA ATTORNEYS Online Christmas cards mesothelioma attorney directory personal injury law firm online motor insurance quotes google affiliate mesothelioma claims Dwi lawyer Donate Old Cars to Charity Php programmers business voip solutions mesothelioma attorney Criminal lawyer Health Records Personal Health Record Massage School Dallas Texas Donate Your Car for Kids personal injury solicitor LOW CREDIT LINE CREDIT CARDS Dallas mesothelioma attorneys car insurance quotes colorado Criminal defense lawyer attorney lawyer mesothelioma Php programmers for hire benchmark lending Seo services register free domains all about mesothelioma Computer science classes online Seo companies best accident attorneys Best social media platforms for business buy gift card Best Seo company PAPERPORT PROMOTIONAL CODE Best social media platforms CAR INSURANCE QUOTES UTAH Sell Annuity Payment Business finance group holland michigan college Social media platforms for business buying structured settlements Custom WordPress theme designer federal criminal defense attorney integrated ehr Personal Injury Lawyers mesothelioma ct Motor Insurance Quotes Business management software CHEAP AUTO INSURANCE IN VA boca raton personal injury attorney Donate Cars in MA Seo company Paperport Promotional Code ROYALTY FREE IMAGES STOCK Custom Christmas cards Photo Christmas cards buy structured settlements Cheap Domain Registration Hosting how to donate a car in california Donate a Car in Maryland WordPress themes for designers data recovery raid WordPress hosting Annuity Settlements mesothelioma attorneys WordPress theme designers Psd to WordPress Criminal defense attorneys Florida Social media management baltimore mesothelioma attorneys Asbestos Lawyers seattle mesothelioma lawyer Online colledges webex costs Dallas Mesothelioma Attorneys Tech school Car Insurance Companies mesothelioma information personal injury firm arizona auto accident attorney home phone internet bundle Donate Cars Illinois Mortgage adviser Cheap car insurance for ladies google adsense asbestos lawyers Mesothelioma Law Firm Forensics Online Course Dayton Freight Lines Donate your car for kids refinance with bad credit low credit line credit cards Christmas cards CAR INSURANCE QUOTES PA Proud Italian cook MORTGAGE ADVISER Car Insurance Quotes MN Psd to html Italian cooking school Donate Car To Charity CALIFORNIA CRIMINAL DEFENSE ATTORNEYS FLORIDA peritoneal mesothelioma CHEAP DOMAIN REGISTRATION HOSTING Donating a Car in Maryland MET AUTO Adobe illustrator classes mesotheloma Social media strategies Learning adobe illustrator Best Criminal Lawyers in Arizona Life Insurance Co Lincoln Social media campaigns Donate Car to Charity California domains yahoo georgia truck accident lawyer Donate Car for Tax Credit structured settlement purchasers Royalty Free Images Stock Donate Your Car Sacramento Donating a car in Maryland How to Donate A Car in California world trade center footage Donate old cars to charity Structures Annuity Settlement Holland Michigan College Car Insurance Quotes Colorado Nunavut Culture Hard drive Data Recovery Services virtual data rooms Life insurance co Lincoln houston motorcycle accident lawyer HOW TO DONATE A CAR IN CALIFORNIA mesothelioma lawyer chicago DAYTON FREIGHT LINES Automobile Accident Attorney Hard drive data recovery services Criminal Defense Attorneys Florida Car Insurance Quotes Utah auto accident lawyer san francisco ONLINECLASSES Met Auto Online Colleges mesothelioma litigation World Trade Center Footage mesothelioma lawyer asbestos cancer lawsuit diagnosed with mesothelioma Psychic for Free Low Credit Line Credit Cards Royalty free images stock Futuristic architecture Donate your Car for Money Virtual Data Rooms Car Donate Home Phone Internet Bundle auto insurance cost by state Register Free Domains Business VOIP Solutions mesothelioma lawyer texas mesothelioma trial attorney PHD on Counseling Education Neuson Car Insurance Quotes PA compare small business phone systems online criminal justice degree NUNAVUT CULTURE primary pulmonary hypertension Car Insurance in South Dakota Email Bulk Service Webex Costs Cheap Car Insurance for Ladies Cheap Car Insurance in Virginia broward county dui lawyer Online classes Better Conference Calls HOME PHONE INTERNET BUNDLE utah mesothelioma lawyer Personal Injury Law Firm Mortgage Adviser buyers of structured settlements orlando criminal attorney CAR ACCIDENT LAWYERS Online College Course tucson car accident attorney auto accident attorney best criminal lawyer in arizona Auto Accident Attorney auto insurance yuba city ca BETTER CONFERENCING CALLS Car Accident Lawyers Criminal lawyer Miami DONATE CARS IN MA Car Insurance Quotes Asbestos Lung Cancer compare life assurance
