
convertir de java a c++
Publicado por hazael (2 intervenciones) el 29/07/2021 04:22:50
como puedo convertir mis siguientes programas a c++?
program 1:
class Cliente:
def __init__(self,nombre):
self.nombre=nombre
self.monto=0
def depositar(self,monto):
self.monto=self.monto+monto
def extraer(self,monto):
self.monto=self.monto-monto
def retornar_monto(self):
return self.monto
def imprimir(self):
print(self.nombre,"tiene depositado la suma de",self.monto)
class Banco:
def __init__(self):
self.cliente1=Cliente("Hazael")
self.cliente2=Cliente("Lilia")
self.cliente3=Cliente("Roberto")
def operar(self):
self.cliente1.depositar(100)
self.cliente2.depositar(150)
self.cliente3.depositar(200)
self.cliente3.extraer(150)
def depositos_totales(self):
total=self.cliente1.retornar_monto()+self.cliente2.retornar_monto()+self.cliente3.retornar_monto()
print("El total de dinero del banco es:",total)
self.cliente1.imprimir()
self.cliente2.imprimir()
self.cliente3.imprimir()
# bloque principal
banco1=Banco()
banco1.operar()
banco1.depositos_totales()
programa 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Colaboracion3
{
class Socio
{
private string nombre;
private int antiguedad;
public Socio()
{
Console.Write("Ingrese el nombre del socio:");
nombre = Console.ReadLine(); ;
Console.Write("Ingrese la antiguedad:");
string linea = Console.ReadLine();
antiguedad=int.Parse(linea);
}
public void Imprimir()
{
Console.WriteLine(nombre+" tiene una antiguedad de "+antiguedad);
}
public int RetornarAntiguedad()
{
return antiguedad;
}
}
class Club
{
private Socio socio1, socio2, socio3;
public Club()
{
socio1=new Socio();
socio2=new Socio();
socio3=new Socio();
}
public void MayorAntiguedad()
{
Console.Write("Socio con mayor antiguedad:");
if (socio1.RetornarAntiguedad() > socio2.RetornarAntiguedad() &&
socio1.RetornarAntiguedad() > socio3.RetornarAntiguedad())
{
socio1.Imprimir();
}
else
{
if (socio2.RetornarAntiguedad() > socio3.RetornarAntiguedad())
{
socio2.Imprimir();
}
else
{
socio3.Imprimir();
}
}
}
static void Main(string[] args)
{
Club club1 = new Club();
club1.MayorAntiguedad();
Console.ReadKey();
}
}
}
program 1:
class Cliente:
def __init__(self,nombre):
self.nombre=nombre
self.monto=0
def depositar(self,monto):
self.monto=self.monto+monto
def extraer(self,monto):
self.monto=self.monto-monto
def retornar_monto(self):
return self.monto
def imprimir(self):
print(self.nombre,"tiene depositado la suma de",self.monto)
class Banco:
def __init__(self):
self.cliente1=Cliente("Hazael")
self.cliente2=Cliente("Lilia")
self.cliente3=Cliente("Roberto")
def operar(self):
self.cliente1.depositar(100)
self.cliente2.depositar(150)
self.cliente3.depositar(200)
self.cliente3.extraer(150)
def depositos_totales(self):
total=self.cliente1.retornar_monto()+self.cliente2.retornar_monto()+self.cliente3.retornar_monto()
print("El total de dinero del banco es:",total)
self.cliente1.imprimir()
self.cliente2.imprimir()
self.cliente3.imprimir()
# bloque principal
banco1=Banco()
banco1.operar()
banco1.depositos_totales()
programa 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Colaboracion3
{
class Socio
{
private string nombre;
private int antiguedad;
public Socio()
{
Console.Write("Ingrese el nombre del socio:");
nombre = Console.ReadLine(); ;
Console.Write("Ingrese la antiguedad:");
string linea = Console.ReadLine();
antiguedad=int.Parse(linea);
}
public void Imprimir()
{
Console.WriteLine(nombre+" tiene una antiguedad de "+antiguedad);
}
public int RetornarAntiguedad()
{
return antiguedad;
}
}
class Club
{
private Socio socio1, socio2, socio3;
public Club()
{
socio1=new Socio();
socio2=new Socio();
socio3=new Socio();
}
public void MayorAntiguedad()
{
Console.Write("Socio con mayor antiguedad:");
if (socio1.RetornarAntiguedad() > socio2.RetornarAntiguedad() &&
socio1.RetornarAntiguedad() > socio3.RetornarAntiguedad())
{
socio1.Imprimir();
}
else
{
if (socio2.RetornarAntiguedad() > socio3.RetornarAntiguedad())
{
socio2.Imprimir();
}
else
{
socio3.Imprimir();
}
}
}
static void Main(string[] args)
{
Club club1 = new Club();
club1.MayorAntiguedad();
Console.ReadKey();
}
}
}
Valora esta pregunta


0