daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Oct 18th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void getData(float [][4]);
  7. void printHeader();
  8. void printData(float [][4]);
  9.  
  10. int main() {
  11.  
  12.     float sales[5][4] = {0.0};
  13.  
  14.     getData(sales);
  15.  
  16.     printHeader();
  17.  
  18.     printData(sales);
  19.  
  20.     return 0;
  21. }
  22.  
  23. void getData(float sales[][4]){
  24.  
  25.     int salesperson;
  26.     int product;
  27.     float value;
  28.     string temp;
  29.  
  30.     ifstream myFile("c:/users/patry/documents/oop/sales.txt");
  31.  
  32.     if(myFile.is_open()){
  33.         while(myFile >> salesperson >> product >> value){
  34.             sales[salesperson - 1][product - 1] += value;
  35.         }
  36.     }
  37.  
  38.     myFile.close();
  39.  
  40. }
  41.  
  42. void printHeader(){
  43.     cout << "\nAt the end of each row we display a total\n" <<
  44.             "amount of money earned by each salesperson.\n" <<
  45.             "At the end of each column we display a total\n" <<
  46.             "amount of money earned on each product.\n\n";
  47.     cout << "Person";
  48.     printf("%22s", "Products\n");
  49.     printf("%11d%8d%9d%8d%9s\n", 1, 2, 3, 4, "Total");
  50. }
  51.  
  52. void printData(float sales[][4]){
  53.  
  54.     float totalValue;
  55.     float productValues[4]; //to display total amount of money earned by selling each product
  56.  
  57.     for(int i = 0; i < 5; ++i){
  58.         totalValue = 0.0;
  59.         printf("%3d   ", i + 1);
  60.  
  61.         for(int j = 0; j < 4; ++j){
  62.             totalValue += sales[i][j];
  63.             productValues[j] += sales[i][j];
  64.             printf("%8.2f", sales[i][j]);
  65.         }
  66.  
  67.         printf("%8.2f\n", totalValue);
  68.     }
  69.  
  70.     cout << "Total:";
  71.  
  72.     for (float productValue : productValues)
  73.         printf("%8.2f", productValue);
  74.  
  75.     cout << endl;
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top