Advertisement
Guest User

Revenue Recorder

a guest
Nov 21st, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <fstream>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8.  
  9. using namespace std;
  10.  
  11. class Revenue{
  12. private:
  13.     string divNum, divName;
  14.     int numEmployees;
  15.     double totalSales, totalCosts, profit, costPerEmp;
  16.  
  17. public:
  18.     static int numDiv, qtrNum;
  19.     void storeInfo(string dNum, int eNum, string dName, double tSales, double tCosts);
  20.     static void modifynumDiv(int totalDivisions);
  21.     static void modifyqtrNum(int qNum);
  22.  
  23. string setDivNum(string dNum){
  24.   divNum = dNum;
  25.     return divNum;
  26.     }
  27.    
  28. int setNumEmployees(int eNum){
  29.   numEmployees = eNum;
  30.     return numEmployees;
  31.     }
  32.  
  33. string setDivName(string dName){
  34.   divName = dName;
  35.     return divName;
  36.     }  
  37.  
  38. double setTotalSales(double tSales){
  39.   totalSales = tSales;
  40.     return totalSales;
  41.     }
  42.  
  43. double setTotalCosts(double tCosts){
  44.   totalCosts = tCosts;
  45.     return totalCosts;
  46.     }  
  47.    
  48. double getProfit(double tSales, double tCosts){
  49. double profit = ((tSales) - (tCosts));
  50. return profit;
  51. }
  52.  
  53. double getCostPerEmp(int eNum, double tCosts){
  54. double costPerEmp = ((tCosts) / (numEmployees));
  55. return costPerEmp;
  56. }
  57.  
  58. };
  59.  
  60. void Revenue::modifynumDiv(int totalDivisions){
  61.     numDiv = totalDivisions;
  62. }
  63. void Revenue::modifyqtrNum(int qNum){
  64.     qtrNum = qNum;
  65. }
  66.  
  67. void Revenue::storeInfo(string dNum, int eNum, string dName, double tSales, double tCosts){
  68. divNum = dNum;
  69. numEmployees = eNum;
  70. divName = dName;
  71. totalSales = tSales;
  72. totalCosts = tCosts;
  73. }
  74.  
  75. int Revenue::numDiv = 0;
  76. int Revenue::qtrNum = 0;
  77.  
  78. int main(){
  79.    
  80.     ofstream outputFile;
  81.     outputFile.open("cop2224_proj2.xml");
  82.     Revenue rev;
  83.     char proceed;
  84.      
  85.     int numDivisions, qNum, eNum, totalDivisions = 0;
  86.     string dNum, dName;
  87.     double tSales, tCosts;
  88.  
  89.     outputFile << "<Revenue>" << endl;
  90. //Intro
  91.     cout<< "Welcome to the Revenue Entry Program. \n";
  92.     cout<< "The next few prompts will ";
  93.     cout<< "take you though revenue entry based on desired number of reporting divisions. \n";
  94.     cout<< "After you enter one record you will ";
  95.     cout<< "have the option to enter another or exit." << endl;
  96.     cout<< "Would you like to continue?  Enter 'Y' or 'N': ";
  97.     cin >> proceed;
  98.     //  Exit if user chooses not to proceed
  99.     for (;(proceed =='Y') || (proceed == 'y');){   
  100. // Display the prompts and capture input
  101.     cout << "Revenue Entry.\n";
  102.     cout << "What Quarter are Your Recording Information for?: ";
  103.     cin >> qNum;
  104.     cout << "How Many Divisions would you like to process revenue for?: ";
  105.     cin >> numDivisions;
  106.     Revenue *divisions = new Revenue[numDivisions];
  107. //Get the Revenue information for each division.
  108.     cout << "Enter the Division information below. \n";
  109.     for (int count = 0; count < numDivisions; count++){
  110.         while(proceed =='Y' || proceed == 'y'){
  111.         cout << "Division Name: ";
  112.         cin >> dName;
  113.         rev.setDivName(dName);
  114.         cin.ignore();
  115.         cout << "Enter the 4 Digit Division Number: ";
  116.         cin >> dNum;
  117.         while (dNum.length() < 4 || dNum.length() >= 5){
  118.         cout << "Error, Division number must be 4 digits only, try again: ";
  119.         cin >> dNum;
  120.         }
  121.         rev.setDivNum(dNum);
  122.         cout << "Enter number of employees in the Division: ";
  123.         cin >> eNum;
  124.         while (eNum <= 0){
  125.             cout << "Error, no negative numbers may be entered and each Division must have at least one employee." << endl;
  126.             cout << "Enter number of employees in the Division: ";
  127.             cin >> eNum;
  128.             }
  129.         rev.setNumEmployees(eNum);
  130.         cout << "Enter total sales for this Division: ";
  131.         cin >> tSales;
  132.         while (tSales <= 0){
  133.             cout << "Negative numbers and 0 not accepted, try again: ";
  134.             cin >> tSales;
  135.             }
  136.         rev.setTotalSales(tSales);
  137.         cout << "Enter total costs for this Division: ";
  138.         cin >> tCosts;
  139.         while (tCosts <= 0){
  140.             cout << "Negative numbers not accepted, try again: ";
  141.             cin >> tCosts;
  142.             }
  143.         rev.setTotalCosts(tCosts);
  144.        
  145.         totalDivisions += 1;
  146.            
  147. //Output Entries
  148.         outputFile <<"<Division>" << endl
  149.             << "<DivisionName>" << dName << "</DivisionName>" << endl
  150.             << "<DivisionNumber>" << dNum << "</DivisionNumber>" << endl
  151.             << "<NumberofEmployees>" <<eNum << "</NumberofEmployees>" << endl
  152.             << "<TotalSales>" << fixed << setprecision(2)  << tSales << "</TotalSales>" << endl
  153.             << "<TotalCosts>" << fixed << setprecision(2) << tCosts << "</TotalCosts>" << endl
  154.             << "<Profit>" << fixed << setprecision(2) << rev.getProfit(tSales, tCosts) << "</Profit>" << endl
  155.             << "<CostPerEmployee>" << fixed << setprecision(2) << rev.getCostPerEmp(eNum, tCosts) << "</CostPerEmployee>" << endl
  156.             <<"</Division>" << endl;
  157.         cout << "Record Saved.\n";
  158.         cout << "Do You Want to enter another record? 'Y' or 'N': ";
  159.         cin >> proceed;
  160.     }
  161.     }
  162.     Revenue::modifyqtrNum(qNum);
  163.     Revenue::modifynumDiv(totalDivisions);
  164.     outputFile << "<Quarter>" << Revenue::qtrNum << "</Quarter>" << endl
  165.                 << "<TotalDivisionsRecorded>" << Revenue::numDiv << "</TotalDivisionsRecorded>" << endl
  166.                 << "</Revenue>";
  167.     }
  168.     cout << "No additional records added. \n";
  169.     outputFile.close();    
  170.     system("pause");
  171.    
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement