Está en la página 1de 4

2 DE MAYO DE 2022

EJERCICIO 1
FUNCIONES AMIGAS

YAHIR MARIN BERNAL 2EM2


ESCUELA SUPERIOR DE INGENIERIA MECANICA Y LECTRICA
#include <iostream>

#include <conio.h>

using namespace std;

class camion;

class carro {

int pasajeros;

int velocidad;

public:

carro(int p,int v) {pasajeros=p;velocidad=v;}

int sp_greater(camion t);

int sp_greater2(camion p);

};

class camion {

int pasajeros;

int velocidad; public:

camion (int p,int v) {pasajeros=p;velocidad=v;}

friend int carro::sp_greater(camion t);

friend int carro::sp_greater2(camion p);

};

int carro::sp_greater(camion t)

{ return velocidad - t.velocidad;

int carro::sp_greater2(camion p)

return pasajeros-p.pasajeros;

int main() {

int t,p;

carro c1(6,55),c2(2,130);
camion t1(30,55), t2(20,72);

cout << "Comparando el carro y el camion:\n";

t=c1.sp_greater(t1);

if(t<0)

cout <<"El camion es mas rapido. \n";

else

if(t==0)

cout << "La velocidad del coche y del camion es la misma.\n";

else

cout << "El coche es mas rapido.\n";

cout << "\nComparando carro 2 y camion 2:\n";

t=c2.sp_greater(t2);

if(t<0)

cout << "El camion es mas rapido.\n";

else if(t==0)

cout << "La velocidad del coche y del camion es la misma.\n"; else

cout << "El coche es mas rapido.\n";

cout << "\nComparando carro y camion :\n";

p=c1.sp_greater2(t1);

if(p<0)

cout << "El camion tiene mas capacidad.\n";

else if(p==0)

cout << "La capacidad del coche y del camion es la misma.\n"; else

cout << "El coche es tiene mas capacidad.\n";

cout << "\nComparando carro y camion 2:\n";

p=c2.sp_greater2(t2);

if(p<0)

cout << "El camion tiene mas capacidad.\n";

else if(p==0)
cout << "La capacidad del coche y del camion es la misma.\n"; else

cout << "El coche es tiene mas capacidad.\n";

char ch=getch();

return 0;

También podría gustarte