Advertisement
Guest User

main.cpp

a guest
Apr 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. /*
  2.  
  3. NOTE TO SELF: DO NOT FORGET HEADER COMMENT!
  4.  
  5. Also, do not need to return from void functions!
  6.  
  7. */
  8.  
  9. /*
  10. ================================
  11. ========== TEST CASES ==========
  12. ================================
  13.  
  14. ======== TEST CASE 1 ========
  15.  
  16. Input:
  17. M:/data.txt
  18. k
  19.  
  20. Expected output:
  21. Prompt for place to read data from
  22. Successfully open and read file,
  23. printing the two lines to verify I've
  24. correctly coded line-reading.
  25.  
  26. "press any key to continue..." so I
  27. have time to read and make sure it worked,
  28. then I press a key to close it.
  29.  
  30. Actual output:
  31. Success!
  32.  
  33.  
  34.  
  35. ======== TEST CASE 2 ========
  36.  
  37. Input:
  38. M:/data.txt
  39.  
  40. Expected output:
  41. Same as test case 1
  42.  
  43. I've advanced the code to using a vector
  44. of grabbed lines so that it can work for
  45. a file of any size. Making sure it still
  46. works.
  47.  
  48. Actual output:
  49. Feelin' real slick with it workin' like this!
  50.  
  51.  
  52.  
  53. ======== TEST CASE 3 ========
  54.  
  55. Input:
  56. D:/data.txt (working from another laptop)
  57.  
  58. Expected output:
  59. Should print out the ToString functions
  60. for a residential class and a commercial
  61. class, even though the pointers are
  62. *Property.
  63.  
  64. Actual output:
  65. It's using the ToString() function from
  66. the Property class...
  67. */
  68.  
  69. #include <iomanip>
  70. #include <iostream>
  71. #include <fstream>
  72. #include <string>
  73. #include <vector>
  74. #include "Property.h"
  75. #include "Residential.h"
  76. #include "Commercial.h"
  77. #include <sstream>
  78.  
  79. using namespace std;
  80.  
  81. int main() {
  82.  
  83. cout << "starting..." << endl;
  84.  
  85. ifstream inFS;
  86. ofstream outFS;
  87.  
  88. int const DISPLAY_PRECISION = 2;
  89. int const DISPLAY_WIDTH = 15;
  90.  
  91. string const RESIDENTIAL = "Residential";
  92. string const COMMERCIAL = "Commercial";
  93. string const NO = "no";
  94. string const YES = "yes";
  95.  
  96. string fileAddress = "";
  97.  
  98. int indexFound = -1;
  99. double maxFound = 0;
  100. vector<Property*> sortedPropertyPointers(0);
  101.  
  102. string readIn = "";
  103. bool isResidential = false;
  104. bool isRental = false;
  105. double propertyValue = -1.1;
  106.  
  107. bool secondBool = false;
  108. double discountRate = -1.1;
  109. string propertyId = "";
  110.  
  111. vector<Commercial> commercialProperties(0);
  112. vector<Residential> residentialProperties(0);
  113.  
  114. vector<Property*> propertyPointers(0);
  115.  
  116. cout << "Where should I read the data from: ";
  117.  
  118. getline(cin, fileAddress);
  119.  
  120. inFS.open(fileAddress);
  121.  
  122. cout << endl << endl;
  123.  
  124. if (inFS.is_open()) {
  125.  
  126. while (!inFS.eof()) {
  127.  
  128. inFS >> readIn;
  129.  
  130. if (readIn == RESIDENTIAL) {
  131. isResidential = true;
  132.  
  133. inFS >> readIn;
  134.  
  135. if (readIn == YES) {
  136. isRental = true;
  137. }
  138. else {
  139. isRental = false;
  140. }
  141.  
  142. inFS >> propertyValue;
  143.  
  144. inFS >> readIn;
  145.  
  146. if (readIn == YES) {
  147. secondBool = true;
  148. }
  149. else {
  150. secondBool = false;
  151. }
  152.  
  153. inFS >> propertyId;
  154.  
  155. Residential newResidential(secondBool, isRental, propertyValue, propertyId);
  156. residentialProperties.push_back(newResidential);
  157.  
  158. Property* propertyPointer = &(*(residentialProperties.end() - 1));
  159. propertyPointers.push_back(propertyPointer);
  160.  
  161. }
  162.  
  163. else {
  164. isResidential = false;
  165.  
  166. inFS >> readIn;
  167.  
  168. if (readIn == YES) {
  169. isRental = true;
  170. }
  171. else {
  172. isRental = false;
  173. }
  174.  
  175. inFS >> propertyValue;
  176.  
  177. inFS >> readIn;
  178.  
  179. if (readIn == YES) {
  180. secondBool = true;
  181. }
  182. else {
  183. secondBool = false;
  184. }
  185.  
  186. inFS >> discountRate;
  187.  
  188. inFS >> propertyId;
  189.  
  190. Commercial newCommercial(secondBool, discountRate, isRental, propertyValue, propertyId);
  191. commercialProperties.push_back(newCommercial);
  192.  
  193. Property* propertyPointer = &(*(commercialProperties.end() - 1));
  194. propertyPointers.push_back(propertyPointer);
  195. }
  196. }
  197.  
  198. inFS.close();
  199.  
  200. cout << "All properties:" << endl;
  201.  
  202. for (int i = 0; i < propertyPointers.size(); i++) {
  203. cout << propertyPointers.at(i)->ToString() << endl;
  204. }
  205.  
  206. cout << endl;
  207. cout << "TAX REPORT:" << endl;
  208.  
  209. for (int i = 0; i < propertyPointers.size(); i++) {
  210. cout << "** Taxes due for the property at: " << propertyPointers.at(i)->GetId() << endl;
  211. cout << " This property has an estimated value of:";
  212. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->GetValue() << endl;
  213. cout << " Taxes due on this property are:";
  214. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->ComputeTax() << endl;
  215. cout << endl;
  216. }
  217.  
  218. cout << "Where should I write the report (just press return to skip): ";
  219.  
  220. getline(cin, fileAddress);
  221.  
  222. if (fileAddress == "") {
  223. }
  224. else {
  225. outFS.open(fileAddress);
  226.  
  227. for (int i = 0; i < propertyPointers.size(); i++) {
  228. outFS << "** Taxes due for the property at: " << propertyPointers.at(i)->GetId() << endl;
  229. outFS << " This property has an estimated value of:";
  230. outFS << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->GetValue() << endl;
  231. outFS << " Taxes due on this property are:";
  232. outFS << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->ComputeTax() << endl;
  233. outFS << endl;
  234. }
  235. }
  236.  
  237. outFS.close();
  238.  
  239. cout << endl << endl;
  240.  
  241. //WIP of the "sorted version" code.
  242. /* cout << "SORTED VERSION:" << endl;
  243. cout << endl;
  244. cout << "TAX REPORT:" << endl;
  245.  
  246. maxFound = (*propertyPointers.at(0)).ComputeTax();
  247.  
  248. while (sortedPropertyPointers.size() < propertyPointers.size()) {
  249.  
  250. vector<Property*> tempVector(0);
  251.  
  252. for (int i = 0; i < propertyPointers.size(); i++) {
  253. *tempVector.at(i) = *propertyPointers.at(i);
  254. }
  255.  
  256. for (int i = 0; i < tempVector.size(); i++) {
  257. cout << "** Taxes due for the property at: " << tempVector.at(i)->GetId() << endl;
  258. cout << " This property has an estimated value of:";
  259. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << tempVector.at(i)->GetValue() << endl;
  260. cout << " Taxes due on this property are:";
  261. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << tempVector.at(i)->ComputeTax() << endl;
  262. cout << endl;
  263. }
  264.  
  265. for (int i = 0; i < tempVector.size(); i++) {
  266.  
  267. if ((*tempVector.at(i)).ComputeTax() > maxFound) {
  268. maxFound = (*tempVector.at(0)).ComputeTax();
  269. indexFound = i;
  270. }
  271.  
  272. }
  273.  
  274. sortedPropertyPointers.push_back(tempVector.at(indexFound));
  275. tempVector.erase(tempVector.begin() + indexFound);
  276.  
  277. }
  278.  
  279. for (int i = 0; i < sortedPropertyPointers.size(); i++) {
  280. cout << "** Taxes due for the property at: " << sortedPropertyPointers.at(i)->GetId() << endl;
  281. cout << " This property has an estimated value of:";
  282. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << sortedPropertyPointers.at(i)->GetValue() << endl;
  283. cout << " Taxes due on this property are:";
  284. cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << sortedPropertyPointers.at(i)->ComputeTax() << endl;
  285. cout << endl;
  286. }
  287.  
  288. // ========== BEGIN TESTS ==========
  289. //system("pause");
  290. // ========== END TESTS ==========
  291. */
  292. }
  293.  
  294. else if (!inFS.is_open()) {
  295. cout << "ERROR ON OPENING" << endl;
  296. return 1;
  297. }
  298.  
  299. inFS.close();
  300.  
  301. return 0;
  302.  
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement