Using control breaks to subtotal inputfile data

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 14
Reputation: jko2326 is an unknown quantity at this point 
Solved Threads: 0
jko2326 jko2326 is offline Offline
Newbie Poster

Using control breaks to subtotal inputfile data

 
0
  #1
Aug 31st, 2009
For this project I am suppose to create a data file which includes this info:

Miller Ford Mustang 28000
Miller Ford Escape 23000
Miller Ford Van 32000
Sam_Car Ford Focus 17000
Sam_Car Ford Ranger 18250
Sam_Car Chev Impala 31500
Tina_Sells Chev Camero 33000
Tina_Sells Chev SUV 38000

Then I am suppose to create a program that reads in all the data but uses a control break, one that subtotals each salespersons sales. then it it suppose to display the read data including the subtotal, and earned commission which is 4% of the total sales (subtotal).
This is what I have so far, it read all the data and displays it. I just need help on how to start on the subtotaling for each seller? Can anyone show me an example or lead me in the direction to a solution for my program? Thanks.
  1. ///Preprocessive directives
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <fstream>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. //Prototypes
  9. void initialization();
  10. void process ();
  11. void eoj ();
  12. void openIt();
  13. void readIt();
  14. void writeIt();
  15. void calculateIt();
  16. void accumulateIt();
  17.  
  18. //Input Records
  19. ifstream inputFile;
  20. char sSalesPerson[15];
  21. char sMake[10];
  22. char sModel [10];
  23. int iSellingPrice;
  24.  
  25. //Program Variables
  26. int iEarnedCommission;
  27.  
  28.  
  29. int main()
  30. {
  31. cout << "\n\t\tWeekly Car Sales Report\n\n";
  32. cout << "Salesperson Make Model Selling Price\n";
  33. cout << "-------------------------------------------------\n";
  34. initialization();
  35.  
  36. if (!inputFile.fail())
  37. {
  38. process();
  39.  
  40. }
  41.  
  42. eoj();
  43.  
  44. return 0;
  45. }
  46.  
  47. void initialization()
  48. {
  49. openIt();
  50.  
  51. return;
  52. }
  53. void process ()
  54. {
  55. readIt();
  56. while (!inputFile.eof())
  57. {
  58. calculateIt();
  59. accumulateIt();
  60. writeIt();
  61. readIt();
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. return;
  69. }
  70. void eoj ()
  71. {
  72. inputFile.close();
  73. return;
  74. }
  75. void openIt()
  76. {
  77. inputFile.open("c:\\auto.dat");
  78. if (inputFile.fail())
  79. cout << "AUTO file open failed" << endl;
  80. return;
  81.  
  82. }
  83. void readIt()
  84. {
  85.  
  86. inputFile >> sSalesPerson >> sMake >> sModel >> iSellingPrice;
  87.  
  88.  
  89. return;
  90. }
  91. void calculateIt()
  92. {
  93.  
  94. return;
  95.  
  96. }
  97. void accumulateIt()
  98. {
  99.  
  100.  
  101. return;
  102. }
  103. void writeIt()
  104. {
  105. cout << left << setw(15) << sSalesPerson << setw(12)<< sMake << setw(12) << sModel << setw(12)
  106. << iSellingPrice << endl;
  107.  
  108.  
  109.  
  110.  
  111. return;
  112. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: Using control breaks to subtotal inputfile data

 
0
  #2
Aug 31st, 2009
You should pay attention to how you have divided your problem into functions.

A function like computeCommission(int price) can be useful...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC