Advertisement
eimkasp

C++ Two dimensional array

Nov 26th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6.     int V[10][10];
  7.     int V2[10][10];
  8.     int K[10][10];
  9.     void Ilg (int i);
  10. using namespace std;
  11.    
  12. int main () {
  13.     ifstream fd("Duomenys.txt");
  14.     ofstream fr("Rezultatai.txt", ios::app);
  15.    
  16.     int i = 1, n = 1;
  17.     char a[256];
  18.     string temp;
  19.     while (!fd.eof()){
  20.         fd >> V[i][1] >> V[i][2] >> V[i][3] >> V[i][4];
  21.         Kord(i);
  22.         //cout << V[i][1] << V[i][2] << V[i][3] << V[i][4] << endl;
  23.         i++;
  24.     }
  25.     Ilg(i);
  26.     return 0;
  27. }
  28.  
  29. void Kord(int i) {
  30.     ifstream fd("Duomenys.txt");
  31.     ofstream fr("Rezultatai.txt", ios::app);
  32.     //cout << "labas";
  33.     for (int j = 1; j <= i; j++) {
  34.     // iekau x1 y1
  35.     V2[j][1] = V[j][3];
  36.     V2[j][2] = V[j][2];
  37.     // ieskau x3 y3
  38.     V2[j][3] = V[j][1];
  39.     V2[j][4] = V[j][4];
  40.     cout << "X1 Y1 - " << V2[j][1] << " "  << V2[j][2] << endl;
  41.     cout << "X2 Y2 - " << V[j][1] << " " << V[j][2] << endl;
  42.     cout << "X3 Y3 - " << V2[j][3] << " " << V2[j][4] << endl;
  43.     cout << "X4 Y4 - " << V[j][3] << " " << V2[j][4] << endl;
  44.     Ilg(i);
  45.     fr << j << " Trikampio kooridinates" << endl;
  46.     fr << "X1 Y1 - " << V2[j][1] << " "  << V2[j][2] << endl;
  47.     fr << "X2 Y2 - " << V[j][1] << " " << V[j][2] << endl;
  48.     fr << "X3 Y3 - " << V2[j][3] << " " << V2[j][4] << endl;
  49.     fr << "X4 Y4 - " << V[j][3] << " " << V2[j][4] << endl;
  50.     }
  51. }
  52.     void Ilg(int i) {
  53.     ofstream fr("Rezultatai.txt", ios::app);
  54.         for (int j = 1; j < i; j++) {
  55.         K[j][1] = sqrt(pow((double)V[j][1]-(double)V2[j][1],2) + (pow((double)V[j][2] - (double)V2[j][2],2)));
  56.         K[j][2] = sqrt(pow((double)V[j][3]-(double)V2[j][1],2) + (pow((double)V[j][4] - (double)V2[j][2],2)));
  57.         cout << j << " trikampio krastiniu ilgiai " << K[j][1] << " " << K[j][1] <<  endl;
  58.         fr << j << " trikampio krastiniu ilgiai" << endl;
  59.         fr << K[j][1] << " " << K[j][2] << endl;
  60.         fr << "perimetras = " << K[j][1]*2 + K[j][2]*2;
  61.         }
  62.         fr.close();
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement