jueves, 3 de junio de 2010

Practica 12 Problema 1

Escritura
using System;
using System.IO;

namespace practica_12_prob_1
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 0;
double[,] puntos = new double[3, 4] { { 6.3, 8.2, 18.25, 24.32 }, { 4.0, 4.0, 10.0, -5.0 }, { -2.0, 5.0, 4.0, 5.0 } };
FileStream flujo = new FileStream("E:\\puntos.dat", FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(flujo);
Console.WriteLine("\n\tPuntos");
Console.WriteLine("");
for (i = 0; i < 3; i = i + 1)
{
for (j = 0; j < 4; j = j + 1)
{
bw.Write(puntos[i, j]);
Console.WriteLine("\t"+ puntos[i, j]);
}

}
bw.Close();
Console.ReadKey();
}
}
}


Lectura
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace practica_12_problema_1_abrir
{
class Program
{
static void Main(string[] args)
{
double media;
double mediay;
double pendente;
int i = 0;
int j = 0;
double x1, x2, y1, y2;
FileStream flujo = new FileStream("E:\\puntos.dat", FileMode.Open, FileAccess.Read);
BinaryReader bw = new BinaryReader(flujo);
double[,] puntos = new double[3, 4];
for (i = 0; i < 3; i = i + 1)
{
for (j = 0; j < 4; j = j + 1)
{
(puntos[i, j]) = bw.ReadDouble(); ;
Console.Write(puntos[i, j] + ",");

}


}
for (i = 0; i < 3; i = i + 1)
{
x1 = puntos[i, 0];
y1 = puntos[i, 1];
x2 = puntos[i, 2];
y2 = puntos[i, 3];
x1 = puntos[i, 0];
y1 = puntos[i, 1];
x2 = puntos[i, 2];
y2 = puntos[i, 3];
x1 = puntos[i, 0];
y1 = puntos[i, 1];
x2 = puntos[i, 2];
y2 = puntos[i, 3];
media = (x1 + x2) / 2;
mediay = (y1 + y2) / 2;
pendente = (y2 - y1) / (x2 - x1);
Console.WriteLine("\nPendiente={0:f2} ", pendente);
Console.WriteLine("Punto medio X= " + media);
Console.WriteLine("Punto medio Y= " + mediay);
bw.Close();
}

Console.ReadKey();
}
}
}

No hay comentarios:

Publicar un comentario