Descargar la presentación
La descarga está en progreso. Por favor, espere
1
Introducción a C++ Sistemas Operativos
Universidad Tecnológica Nacional Facultad Regional Buenos Aires Ingeniería en Sistemas de Información Sistemas Operativos Introducción a C++
2
Compiladores Windows – Visual Studio Linux / Solaris – gcc
3
C++ - Un C con “clase” #include <iostream> using namespace std;
class complejo { private: int real, imag; public: void Asignar(int a2, int b2) { real = a2; imag = b2; } void Leer(int &a2, int &b2) { a2 = real; b2 = imag; };
4
C++ - Un C con “clase” Valor del complejo c1 = 1+2i ... int main() {
int x, y; c1.Asignar(1, 2); c1.Leer(x, y); cout << "c1 = " << x << “+" << y << “i" << endl; return 0; } Valor del complejo c1 = 1+2i
5
Sobrecarga #include <iostream> using namespace std;
int doble(int x); float doble(float x); int main() { int x = 2; float y = 5.5; cout << "El doble de x es: " << doble(x) << endl; cout << "El doble de y es: " << doble(y) << endl; return 0; } int doble(int x) { return x * x; } float doble(float x) {
6
Constructores int main() { complejo c1(1,5); public: complejo() {}
complejo(int a, int b) { real = a; imag = b; } ... }; int main() { complejo c1(1,5);
7
Asignación dinámica #include <iostream.h>
#include <string.h> void main() { char* Nombre; Nombre = new char[sizeof(char)*50+1]; cout << "Introduzca su Nombre:"; cin >> Nombre; cout << “El nombre ingresado es: ” << Nombre <<endl; delete [] Nombre; }
8
Destructores #include <iostream> using namespace std;
class persona { private: char* nombre; char* apellido; int edad; public: persona() nombre = new char[sizeof(char)*50]; apellido = new char[sizeof(char)*50]; edad = 0; } ~persona() delete [] nombre; delete [] apellido;
9
Sobrecarga - operadores
#include <iostream> using namespace std; class persona { private: char nombre[]; char apellido[]; int dni; public: int operator== (const persona& p1, const persona& p2) If (strcmp(p1.nombre, p2.nombre)==0) && (strcmp(p1.apellido, p2.apellido)==0) && (p1.dni = p2.dni) { return 1; } else { return 0; } };
10
STL - Vector #include <iostream>
#include <vector> #include <string> using namespace std; main() { vector<string> SS; SS.push_back("The number is 10"); SS.push_back("The number is 20"); SS.push_back("The number is 30"); cout << "Loop by index:" << endl; int ii; for(ii=0; ii < SS.size(); ii++) cout << SS[ii] << endl; } cout << endl << "Constant Iterator:" << endl; cout << SS[2] << endl; swap(SS[0], SS[2]); }
Presentaciones similares
© 2024 SlidePlayer.es Inc.
All rights reserved.