Polecenie - Napisz program, który pobierze z pliku dane.txt trzy liczby całkowite (plik dane.txt tworzymy ręcznie z poziomu systemu operacyjnego) wyliczy pole trapezu i wynik zapisze w pliku pole.txt.
Tu mój kod:
#include <iostream>
#include <fstream>
#include <math.h>
#include <cstdlib>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
int main()
{
int Pt = 0;
string mn, mn2, mn3;
ifstream odczyt("dane.txt");
ofstream zapis("pole.txt");
odczyt >> mn >> mn2 >> mn3;
int a, b, h;
istringstream(mn) >> a;
istringstream(mn2) >> b;
istringstream(mn3) >> h;
odczyt.close();
{
Pt = (a + b) * h / 2;
zapis << Pt;
cout << Pt << endl;
}
zapis.close();
return 0;
}