Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 4
- Rimas 2.5 13.0 -5.0
- Robertas 18.7 -13.95 -25.0
- Jurgis -205.0 -36.0 -0.5
- Matas 58.45 50.16 14.45
- */
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- const char duomF[] = "1.txt";
- const char rezF[] = "rez1.txt";
- const int CPav = 15;
- const int CMax = 51;
- struct mokesciai
- {
- string vardas;
- double siluma;
- double telefonas;
- double vanduo;
- double suma;
- };
- void skaitymas(mokesciai A[], int &n)
- {
- char eil[CPav+1];
- ifstream df(duomF);
- df >> n;
- for (int i = 0; i < n; i++)
- {
- df.ignore(80, '\n');
- df.get(eil, CPav);
- A[i].vardas = eil;
- df >> A[i].siluma >> A[i].telefonas >> A[i].vanduo;
- }
- df.close();
- }
- void sprendimas(mokesciai A[], int n)
- {
- double siluma = 0, telefonas = 0, vanduo = 0;
- for (int i = 0; i < n; i++) // Silumos suma
- {
- if (A[i].siluma >= 0)
- {
- siluma += A[i].siluma;
- A[i].suma += A[i].siluma;
- }
- }
- for (int i = 0; i < n; i++) // Telefono suma
- {
- if (A[i].telefonas >= 0)
- {
- telefonas += A[i].telefonas;
- A[i].suma += A[i].telefonas;
- }
- }
- for (int i = 0; i < n; i++) // Vandens suma
- {
- if (A[i].vanduo >= 0)
- {
- vanduo += A[i].vanduo;
- A[i].suma += A[i].vanduo;
- }
- }
- cout << " " << endl;
- cout << " ----------------------------------------- " << endl;
- cout << " Uz siluma turi buti sumoketa: " << siluma << endl;
- cout << " Uz telefona turi buti sumoketa: " << telefonas << endl;
- cout << " Uz vandeni turi buti sumoketa: " << vanduo << endl;
- cout << " ----------------------------------------- " << endl;
- cout << " Vardas Turi sumoketi " << endl;
- cout << " ----------------------------------------- " << endl;
- for (int i = 0; i < n; i++)
- {
- if (A[i].suma != 0) cout << " " << A[i].vardas << " " << A[i].suma << endl;
- }
- cout << " ----------------------------------------- " << endl;
- cout << " " << endl;
- }
- void reset (mokesciai A[])
- {
- for (int i = 0; i < CMax; i++)
- {
- A[i].suma = 0;
- }
- }
- int main ()
- {
- mokesciai A[CMax];
- int n;
- reset(A);
- skaitymas(A, n);
- sprendimas(A, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement