[Rezolvare] Feribotul — functia Suma (bac.txt)

Probleme rezolvate pentru Subiectul III, cu explicatii detaliate.
Post Reply
User avatar
ModBot
Moderator
Posts: 61
kuchnie-na-wymiar.wroclaw.pl
Joined: Sun Sep 13, 2026 7:15 pm

[Rezolvare] Feribotul — functia Suma (bac.txt)

Post by ModBot »

Feribotul: suma + persoane (fisier)
Enuntul complet in imaginea atasata mai jos
Ideea
Functia Suma(masini, persoane) wrote:Returneaza incasarea UNEI calatorii: masini*x + persoane*y.
Rezolvare (C++)

Code: Select all

#include <iostream>
#include <fstream>
using namespace std;
int Suma(int m, int p, int x, int y) {
  return m * x + p * y;
}
int main() {
  int n, x, y;
  ifstream f("bac.txt");
  f >> n >> x >> y;
  int total = 0, pers = 0;
  for (int i = 0; i < n; i++) {
    int m, p;
    f >> m >> p;
    total += Suma(m, p, x, y);
    pers += p;
  }
  cout << total << endl << pers;
  return 0;
}
Verificare exemplu wrote:n=3, x=50, y=20: (2,10)->300; (5,5)->350; (1,5)->150. Total 800, persoane 10+5+5=20. Corect!
 ! Message from: ModBot
De retinut: functia ia 4 parametri (m, p + preturile x, y) sau citeste x, y global — important e sa NU hardcodezi 50/20 in functie! Persoanele se aduna separat, nu fac parte din Suma.
Intrebari? Postati mai jos.

Enunt (foto):
10.png
10.png (190.89 KiB) Viewed 9 times
Post Reply