aprsc7

structure

Dec 12th, 2019 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. struct CityPollution
  6. {
  7.     string name;
  8.     int id;
  9.     float pollution[5], totalPollution=0;
  10. };
  11.  
  12. void displayAllData(CityPollution);
  13.  
  14. int main()
  15. {
  16.     CityPollution city0;
  17.  
  18.     cout << "Area name: ";
  19.     cin >> city0.name;
  20.     cout << "ID number: ";
  21.     cin >> city0.id;
  22.  
  23.     for (int i=0; i<5; i++)
  24.     {
  25.         cout << "Pollution reading " << i+1 << " : ";
  26.         cin >> city0.pollution[i];
  27.         city0.totalPollution += city0.pollution[i];
  28.     }
  29.  
  30.     displayAllData(city0);
  31.  
  32.     ofstream dataFile("pollutionData.txt");
  33.     dataFile << "City name: " << city0.name << endl;
  34.     dataFile << "City ID: " << city0.id << endl;
  35.     dataFile << "Total pollution: " << city0.totalPollution;
  36.     dataFile.close();
  37. }
  38.  
  39. void displayAllData(CityPollution city0)
  40. {
  41.     cout << "\nCity name: " << city0.name << endl;
  42.     cout << "City ID: " << city0.id << endl;
  43.     cout << "Total pollution: " << city0.totalPollution;
  44. }
Add Comment
Please, Sign In to add comment