fork download
  1. /*************************************************************************
  2. * Name: Malgorzata Fiedziukiewicz CSC 155
  3. * Date: 09/23/2017 Lab 2 Extra Credit
  4. **************************************************************************
  5. * Statement: Determine owner, selling cost and commission for house sale
  6. * Specifications:
  7. * Input -owner (string) and selling price (double), from input file
  8. * Output-owner (string), selling cost (double) and commission (double)
  9. *************************************************************************/
  10.  
  11. //header files for I/O and string objects
  12. #include <iostream>
  13. #include <string>
  14. #include <fstream>
  15. #include <iomanip>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. //declaration of objects used to store data
  21. string seller; //seller's name
  22. double price; //price of the house
  23. double cost; //cost to sell the house
  24. double commission; //commission on the sale
  25. ifstream inFile; //input (ifstream object)
  26. ofstream outFile; //output (ofstream object)
  27. string fileName; // user defined output file name
  28.  
  29.  
  30. //1. Opening the files
  31. inFile.open("Realtor2.txt");
  32. outFile.open(fileName + ".out");
  33.  
  34. //2. Read from input file
  35. inFile >> seller >> price;
  36.  
  37. //3. Calculate the cost and the commission
  38. cost = 0.06 * price;
  39. commission = 0.015 * price;
  40.  
  41. //4. Ask user for fileName
  42.  
  43. cout << "Please specify output file name ";
  44. cin >> fileName;
  45. cout << endl;
  46.  
  47. //5. Display results in output file
  48.  
  49. outFile << fixed << showpoint;
  50. outFile << setprecision(2);
  51.  
  52. outFile << "This program calculates the cost to sell a home" << endl;
  53. outFile << "and the commission paid to an individual sales agent." << endl;
  54. outFile << endl;
  55.  
  56. outFile << "Home Owner" << setw(16) << "Price of Home"
  57. << setw(22) << "Seller's Cost" << setw(20) << "Agent's Commission" << endl;
  58. outFile << left << setw(10) << seller << setfill('*') << right << setw(16) << price
  59. << setw(22) << cost << setw(20) << commission << endl;
  60.  
  61.  
  62. inFile.close();
  63. outFile.close();
  64.  
  65. return 0;
  66. }
  67.  
  68.  
  69.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Please specify output file name