Ajutatima in c++ nu inteleg cum trebuie de facut
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("corpgeo.in");
ofstream fout("corpgeo.out");
struct corp{int CodPar,a,b,c; char Material; int arie; }v[1000], temp;
int n,i,j,k;
int main()
{
k=0;
while (fin>>v[k].CodPar>>v[k].a>>v[k].b>>v[k].c>>v[k].Material )
{
v[k].arie=2*(v[k].a*v[k].c+v[k].b*v[k].c+v[k].a*v[k].b);
++k;
}
n=k;
cout << n << "\n";
for (i=0; i<n-1; ++i)
{
for (j=i+1; j<n; ++j)
{
if ((v[i].Material=='p') && (v[j].Material=='p') && (v[i].arie>v[j].arie))
{
temp=v[i]; v[i]=v[j]; v[j]=temp;
cout << "schimb \n";
}
}
}
for (i=0; i<n; ++i)
if (v[i].Material=='p')
fout << v[i].CodPar << " " << v[i].a << " " << v[i].b << " " << v[i].c << " " << v[i].Material << " " << v[i].arie << endl;
}