Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- NOTE TO SELF: DO NOT FORGET HEADER COMMENT!
- Also, do not need to return from void functions!
- */
- /*
- ================================
- ========== TEST CASES ==========
- ================================
- ======== TEST CASE 1 ========
- Input:
- M:/data.txt
- k
- Expected output:
- Prompt for place to read data from
- Successfully open and read file,
- printing the two lines to verify I've
- correctly coded line-reading.
- "press any key to continue..." so I
- have time to read and make sure it worked,
- then I press a key to close it.
- Actual output:
- Success!
- ======== TEST CASE 2 ========
- Input:
- M:/data.txt
- Expected output:
- Same as test case 1
- I've advanced the code to using a vector
- of grabbed lines so that it can work for
- a file of any size. Making sure it still
- works.
- Actual output:
- Feelin' real slick with it workin' like this!
- ======== TEST CASE 3 ========
- Input:
- D:/data.txt (working from another laptop)
- Expected output:
- Should print out the ToString functions
- for a residential class and a commercial
- class, even though the pointers are
- *Property.
- Actual output:
- It's using the ToString() function from
- the Property class...
- */
- #include <iomanip>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include "Property.h"
- #include "Residential.h"
- #include "Commercial.h"
- #include <sstream>
- using namespace std;
- int main() {
- cout << "starting..." << endl;
- ifstream inFS;
- ofstream outFS;
- int const DISPLAY_PRECISION = 2;
- int const DISPLAY_WIDTH = 15;
- string const RESIDENTIAL = "Residential";
- string const COMMERCIAL = "Commercial";
- string const NO = "no";
- string const YES = "yes";
- string fileAddress = "";
- int indexFound = -1;
- double maxFound = 0;
- vector<Property*> sortedPropertyPointers(0);
- string readIn = "";
- bool isResidential = false;
- bool isRental = false;
- double propertyValue = -1.1;
- bool secondBool = false;
- double discountRate = -1.1;
- string propertyId = "";
- vector<Commercial> commercialProperties(0);
- vector<Residential> residentialProperties(0);
- vector<Property*> propertyPointers(0);
- cout << "Where should I read the data from: ";
- getline(cin, fileAddress);
- inFS.open(fileAddress);
- cout << endl << endl;
- if (inFS.is_open()) {
- while (!inFS.eof()) {
- inFS >> readIn;
- if (readIn == RESIDENTIAL) {
- isResidential = true;
- inFS >> readIn;
- if (readIn == YES) {
- isRental = true;
- }
- else {
- isRental = false;
- }
- inFS >> propertyValue;
- inFS >> readIn;
- if (readIn == YES) {
- secondBool = true;
- }
- else {
- secondBool = false;
- }
- inFS >> propertyId;
- Residential newResidential(secondBool, isRental, propertyValue, propertyId);
- residentialProperties.push_back(newResidential);
- Property* propertyPointer = &(*(residentialProperties.end() - 1));
- propertyPointers.push_back(propertyPointer);
- }
- else {
- isResidential = false;
- inFS >> readIn;
- if (readIn == YES) {
- isRental = true;
- }
- else {
- isRental = false;
- }
- inFS >> propertyValue;
- inFS >> readIn;
- if (readIn == YES) {
- secondBool = true;
- }
- else {
- secondBool = false;
- }
- inFS >> discountRate;
- inFS >> propertyId;
- Commercial newCommercial(secondBool, discountRate, isRental, propertyValue, propertyId);
- commercialProperties.push_back(newCommercial);
- Property* propertyPointer = &(*(commercialProperties.end() - 1));
- propertyPointers.push_back(propertyPointer);
- }
- }
- inFS.close();
- cout << "All properties:" << endl;
- for (int i = 0; i < propertyPointers.size(); i++) {
- cout << propertyPointers.at(i)->ToString() << endl;
- }
- cout << endl;
- cout << "TAX REPORT:" << endl;
- for (int i = 0; i < propertyPointers.size(); i++) {
- cout << "** Taxes due for the property at: " << propertyPointers.at(i)->GetId() << endl;
- cout << " This property has an estimated value of:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->GetValue() << endl;
- cout << " Taxes due on this property are:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->ComputeTax() << endl;
- cout << endl;
- }
- cout << "Where should I write the report (just press return to skip): ";
- getline(cin, fileAddress);
- if (fileAddress == "") {
- }
- else {
- outFS.open(fileAddress);
- for (int i = 0; i < propertyPointers.size(); i++) {
- outFS << "** Taxes due for the property at: " << propertyPointers.at(i)->GetId() << endl;
- outFS << " This property has an estimated value of:";
- outFS << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->GetValue() << endl;
- outFS << " Taxes due on this property are:";
- outFS << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << propertyPointers.at(i)->ComputeTax() << endl;
- outFS << endl;
- }
- }
- outFS.close();
- cout << endl << endl;
- //WIP of the "sorted version" code.
- /* cout << "SORTED VERSION:" << endl;
- cout << endl;
- cout << "TAX REPORT:" << endl;
- maxFound = (*propertyPointers.at(0)).ComputeTax();
- while (sortedPropertyPointers.size() < propertyPointers.size()) {
- vector<Property*> tempVector(0);
- for (int i = 0; i < propertyPointers.size(); i++) {
- *tempVector.at(i) = *propertyPointers.at(i);
- }
- for (int i = 0; i < tempVector.size(); i++) {
- cout << "** Taxes due for the property at: " << tempVector.at(i)->GetId() << endl;
- cout << " This property has an estimated value of:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << tempVector.at(i)->GetValue() << endl;
- cout << " Taxes due on this property are:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << tempVector.at(i)->ComputeTax() << endl;
- cout << endl;
- }
- for (int i = 0; i < tempVector.size(); i++) {
- if ((*tempVector.at(i)).ComputeTax() > maxFound) {
- maxFound = (*tempVector.at(0)).ComputeTax();
- indexFound = i;
- }
- }
- sortedPropertyPointers.push_back(tempVector.at(indexFound));
- tempVector.erase(tempVector.begin() + indexFound);
- }
- for (int i = 0; i < sortedPropertyPointers.size(); i++) {
- cout << "** Taxes due for the property at: " << sortedPropertyPointers.at(i)->GetId() << endl;
- cout << " This property has an estimated value of:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << sortedPropertyPointers.at(i)->GetValue() << endl;
- cout << " Taxes due on this property are:";
- cout << setw(DISPLAY_WIDTH) << fixed << setprecision(DISPLAY_PRECISION) << sortedPropertyPointers.at(i)->ComputeTax() << endl;
- cout << endl;
- }
- // ========== BEGIN TESTS ==========
- //system("pause");
- // ========== END TESTS ==========
- */
- }
- else if (!inFS.is_open()) {
- cout << "ERROR ON OPENING" << endl;
- return 1;
- }
- inFS.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement