Parašė 1941· 2014 Kov. 26 14:03:47
#1
Sveiki, šiuo metu mokausi funkciją void ir sprendžiuosi šiokius tokius uždavinius. Ką tik baigiau spręsti vieną "griozdišką" uždavinį ir iškilo klausimas ar eitų šią programą kaip nors optimatizuoti, padaryti mažiau griozdišką?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const char Cfr[]="Rezultatai.txt";
void vienas (int & m1, double & c1, double & p1, double & j1 )
{
m1=1;
c1=100/2.54;
p1=c1/12;
j1=p1/3;
}
void du (int & m2, double & c2, double & p2, double & j2 )
{
m2=2;
c2=200/2.54;
p2=c2/12;
j2=p2/3;
}
void trys (int & m3, double & c3, double & p3, double & j3 )
{
m3=3;
c3=300/2.54;
p3=c3/12;
j3=p3/3;
}
void keturi (int & m4, double & c4, double & p4, double & j4 )
{
m4=4;
c4=400/2.54;
p4=c4/12;
j4=p4/3;
}
void penki (int & m5, double & c5, double & p5, double & j5 )
{
m5=5;
c5=500/2.54;
p5=c5/12;
j5=p5/3;
}
void spausdinti (int m1, double c1, double p1, double j1, int m2, double c2, double p2, double j2, int m3, double c3, double p3, double j3, int m4, double c4, double p4, double j4, int m5, double c5, double p5, double j5)
{
ofstream fr (Cfr);
fr << m1 << " " << fixed << setprecision (2) << c1 << " "<< fixed << setprecision (2) << p1 << " "<< fixed << setprecision (2) << j1 << endl;
fr << m2 << " "<< fixed << setprecision (2) << c2 << " "<< fixed << setprecision (2) << p2 << " "<< fixed << setprecision (2) << j2 << endl;
fr << m3 << " "<< fixed << setprecision (2) << c3 << " "<< fixed << setprecision (2) << p3 << " "<< fixed << setprecision (2) << j3 << endl;
fr << m4 << " "<< fixed << setprecision (2) << c4 << " "<< fixed << setprecision (2) << p4 << " "<< fixed << setprecision (2) << j4 << endl;
fr << m5 << " " << fixed << setprecision (2) << c5 << " "<< fixed << setprecision (2) << p5 << " "<< fixed << setprecision (2) << j5 << endl;
fr.close ();
}
int main()
{
double c1, p1, j1, c2, p2, j2, c3, p3, j3, c4, p4, j4, c5, p5, j5;
int m1, m2, m3, m4, m5;
vienas (m1, c1, p1, j1);
du (m2, c2, p2, j2);
trys (m3, c3, p3, j3);
keturi (m4, c4, p4, j4);
penki (m5, c5, p5, j5);
spausdinti (m1, c1, p1, j1, m2, c2, p2, j2, m3, c3, p3, j3, m4, c4, p4, j4, m5, c5, p5, j5);
return 0;
}
Redagavo 1941· 2014 Kov. 26 14:03:29