Está en la página 1de 9

SEDE: CEUTEC CENTRAL SPS

ASIGNATURA:

ESTRUCTURA DE DATOS 1

TEMA:

TAREA SEMANA 1

SECCIÓN: 1116

CATEDRÁTICO:

INGENIERO CLAUDIO GUTIERREZ

ALUMNO:

CARLOS DAVID ZEPEDA RODRIGUEZ

NUMERO DE CUENTA:

62111620
R// El punto y coma no iría dentro de los paréntesis. El puntero está mal colocado, está en char y
debería ser []. La variable cursor daría un error lógico ya que arriba está declarada como int y
daría conflicto con int long.

R// public static void main(String[] args) {


Vector3d[] v1 = new Vector3d[2];
int vc1[] = new int[2], vc2[] = new int[2];
for (int i = 0; i < v1.length; i++) {
v1[i] = new Vector3d();
v1[i].introducirDatos();
}
for(int i=0; i<v1.length; i++){
v1[i].devolverDatos();
}
}
}
package ejercicio16;
import java.util.Scanner;
public class Vector3d {
private int x, y, z;
Vector3d() {
x = 0;
y = 0;
z = 0;
}
public void introducirDatos() {
Scanner teclado;
teclado = new Scanner(System.in);
System.out.println("Introduce la x: ");
x = teclado.nextInt();
System.out.println("Introduce la y: ");
y = teclado.nextInt();
System.out.println("Introduce la z: ");
z = teclado.nextInt();
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public void devolverDatos(){
System.out.println(x+" "+y+" "+z);
}
public void igual() {
}
}
public static void main(String[] args) {
Complejo c1 = new Complejo(1.0, 1.0);
Complejo c2 = new Complejo(2.0, 2.0);
Complejo c3;
c3 = c1.sumar(c2);
System.out.println(c1 + " + " + c2 + " = " + c3);
c3 = c1.restar(c2);
System.out.println(c1 + " - " + c2 + " = " + c3);
c3 = c1.dividir(c2);
System.out.println(c1 + " / " + c2 + " = " + c3);
c3 = c1.multiplicar(c2);
System.out.println(c1 + " * " + c2 + " = " + c3);
c3 = c1.multiplicar(3.5);
System.out.println(c1 + " * 3.5 = " + c3);
if (c2.equals(c3)) {
System.out.println(c2 + " igual que " + c3);
} else {
System.out.println(c2 + " distinto que " + c3);
}
}

public class Complejo {


private double real;
private double imag;
public Complejo() {
}
public Complejo(double real, double imag) {
this.real = real;
this.imag = imag;
}
public double getImag() {
return imag;
}
public void setImag(double imag) {
this.imag = imag;
}
public double getReal() {
return real;
}
public void setReal(double real) {
this.real = real;
}
public Complejo sumar(Complejo c){
Complejo aux = new Complejo();
aux.real = real + c.real;
aux.imag = imag + c.imag;
return aux;
}
public Complejo restar(Complejo c){
Complejo aux = new Complejo();
aux.real = real - c.real;
aux.imag = imag - c.imag;
return aux;
}
public Complejo multiplicar(Complejo c){
Complejo aux = new Complejo();
aux.real = real * c.real - imag * c.imag;
aux.imag = real * c.imag + imag * c.real;
return aux;
}

public Complejo multiplicar(double n){


Complejo aux = new Complejo();
aux.real = real * n;
aux.imag = imag * n;
return aux;
}

public Complejo dividir(Complejo c){


Complejo aux = new Complejo();
aux.real = (real * c.real + imag * c.imag)/(c.real * c.real + c.imag * c.imag);
aux.imag = (imag * c.real - real * c.imag)/(c.real * c.real + c.imag * c.imag);
return aux;
}

@Override
public String toString() {
return "(" + real + ", " + imag + ")";
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Complejo other = (Complejo) obj;
if (this.real != other.real) {
return false;
}
if (this.imag != other.imag) {
return false;
}
return true;
}
}
main()
{
Hora ht;
Hora hx();
int h,m,s;
cout<<"-----------------------------Ejercicio #5--------------------------\n\n";
ht.Imprimir();
cout<<"\n\n";
cout<<"Ingrese nueva hora: ";
cin>>h;
cout<<"Ingrese los minutos: ";
cin>>m;
cout<<"Ingrese los segundos: ";
cin>>s;

ht.Imprimir();
cout<<"Ingrese el numero de horas adelantar: ";
cin>>h;
cout<<"Ingrese el numero de minutos adelantar: ";
cin>>m;
cout<<"Ingrese el numero de segundos adelantar: ";
cin>>s;
ht.Imprimir();
cout<<"Ingrese la nueva hora para reiniciar el reloj: ";
cin>>h;
cout<<"Ingrese los minutos para reiniciar el reloj: ";
cin>>m;
cout<<"Ingrese los segundos para reiniciar el reloj: ";
cin>>s;

ht.Imprimir();
cout<<"\n\n"
}

También podría gustarte