943,879 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 746
  • C++ RSS
Aug 31st, 2009
0

Using control breaks to subtotal inputfile data

Expand Post »
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.
C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jko2326 is offline Offline
19 posts
since Jul 2009
Aug 31st, 2009
0

Re: Using control breaks to subtotal inputfile data

You should pay attention to how you have divided your problem into functions.

A function like computeCommission(int price) can be useful...
Reputation Points: 72
Solved Threads: 26
Posting Whiz in Training
GDICommander is offline Offline
209 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Question
Next Thread in C++ Forum Timeline: Problem with subexpression in regex





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC