SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 09 Jan 2018 My Price 10.00

Copy and modify the solution from problem 5.2

Finished program 6.1 and have attached.  just need a double check to see if it was done properly. runs fine

  • /*

    Winter 2017
    Lab 6
    Problem 6.1
    Description of problem:
    Copy and modify the solution from problem 5.2
    */


    /* ************************************************************Beginning of Global Area********************************************************************* */
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    #include <iomanip>
    #include<cstring>
    #include <string>
    #include <fstream>

    using namespace std;

    enum Kind { business, maintenance, other, box, tank, flat, hopper, otherFreight, chair, sleeper, otherPassenger };
    const string KIND_ARRAY[] = { "business", "maintenance", "other", "box", "tank", "flat", "hopper" , "otherFreight", "chair", "sleeper", "otherPassenger" };


    /* *************** START of Class Car ****************************** */
    class Car
    {
        protected:
            static const int FIELD_WIDTH = 22;
            std::string reportingMark;
            int carNumber;
            Kind kind;
            bool loaded;
        public:
            std::string destination;
            friend bool operator==(const Car &carA, const Car &carB);


        /* ******* default constructor ***** */
        Car()
        {
            setUp("", 0, "other", false, "NONE");
        }


        /* *** copy constructor ************ */
        Car(const Car &oldCar)
        {
            setUp(oldCar.reportingMark, oldCar.carNumber, KIND_ARRAY[oldCar.kind], oldCar.loaded, oldCar.destination);
            kind = oldCar.kind;
        }


        /* *** input constructor *********** */
        Car(const string &reportingMark, const int &carNumber, const string &kind, const bool &loaded, const string &destination)
        {
            setUp(reportingMark, carNumber, kind, loaded, destination);
        }



        int getCarNum()
        {
            return carNumber;
        }



        string getRepMark()
        {
            return reportingMark;
        }


        /* ******* destructor ************* */
        virtual ~Car() {};


        /* ************** Output *****************
        -Prints Data to the console by calling
         the object
        */
        void output()
        {
        std::cout << std::setw(FIELD_WIDTH) << std::left << "Reporting Mark: " << std::setw(FIELD_WIDTH) << reportingMark << std::endl;
        std::cout << std::setw(FIELD_WIDTH) << "Car Number: "<< std::setw(FIELD_WIDTH) << carNumber<< std::endl;
        std::cout << std::setw(FIELD_WIDTH) << "Kind: "<< std::setw(FIELD_WIDTH) << KIND_ARRAY[kind]<< std::endl;
        std::cout << std::setw(FIELD_WIDTH) << "Loaded: "<< std::setw(FIELD_WIDTH);
            if(loaded)
            {
                std::cout << "true" << std::endl;
            }
            else
            {
                std::cout << "false" << std::endl;
            }
        std::cout << std::setw(FIELD_WIDTH) << "Destination: "<< std::setw(FIELD_WIDTH) << destination<< std::endl;
        std::cout << std::endl;
        }


        /* ************ setKind ***********************
        -will set the correct kind
        */
        virtual void setKind(const string & stringKind)
        {
            if (stringKind == "business")
            {
                kind = business;
            }
            else if (stringKind == "maintenance")
            {
                kind = maintenance;
            }
            else
            {
                kind = other;
            }
        }


        /* ************ setUp ***********************
        -takes in information given by the user
        -it then stores the information in the car
        objects variables
        */
        void setUp(string rMark, int carNum, string carKind, bool isLoaded, string dest)
        {
            reportingMark = rMark;
            carNumber = carNum;
            setKind(carKind);
            loaded = isLoaded;
            destination = dest;
        }


        /* ************ Operator= ********************
        -overload member function that returns the
         left hand operator by reference
        */
        Car & operator=(const Car & carB)
        {
            setUp(carB.reportingMark, carB.carNumber, KIND_ARRAY[carB.kind], carB.loaded, carB.destination);
            return *this;
        }
    };
    /* *************** END of Class Car ********************************* */


    /* *************** START of Derived Class FreightCar **************** */
    class FreightCar : public Car
     {
     public:
         /* ******* default constructor ***** */
         FreightCar()
         {
             setUp("", 0, "other", false, "NONE");
         }


         /* *** copy constructor ************ */
         FreightCar(const FreightCar &ofFrght)
         {
             setUp(ofFrght.reportingMark, ofFrght.carNumber, KIND_ARRAY[ofFrght.kind], ofFrght.loaded, ofFrght.destination);
         }


         /* *** input constructor *********** */
         FreightCar(const string &rpmrk, const int &cNumber, const string &knd, const bool &lded, const string &des)
         {
             setUp(rpmrk, cNumber, knd, lded, des);
         }


        /* ************** FreightCar::setKind *******
        -Takes in data and assigns to variable kind
        */
        void setKind(const string & stringKind)
        {
            if (stringKind == "box")
            {
                kind = box;
            }
            else if (stringKind == "tank")
            {
                kind = tank;
            }
            else if (stringKind == "flat")
            {
                kind = flat;
            }
            else if (stringKind == "hopper")
            {
                kind = hopper;
            }
            else
            {
                kind = otherFreight;
            }
        }
    };
    /* *************** END of Derived Class FreightCar ******************** */


    /* *************** START of Derived Class PassengerCar **************** */
     class PassengerCar : public Car
     {
     public:
         /* ******* default constructor ***** */
         PassengerCar()
         {
             setUp("", 0, "other", false, "NONE");
         }


         /* *** copy constructor ************ */
         PassengerCar(const PassengerCar &oldPas)
         {
             setUp(oldPas.reportingMark, oldPas.carNumber, KIND_ARRAY[oldPas.kind], oldPas.loaded, oldPas.destination);
         }


         /* *** input constructor *********** */
         PassengerCar(const string &rm, const int &cNumber, const string &knd, const bool &lded, const string &des)
         {
             setUp(rm, cNumber, knd, lded, des);
         }


         /* ************** PassengerCar::setKind *******
        -Takes in data and assigns to variable kind
        */
        void setKind(const string & stringKind)
        {
            if (stringKind == "chair")
            {
                kind = chair;
            }
            else if (stringKind == "sleeper")
            {
                kind = sleeper;
            }
            else
            {
                kind = otherPassenger;
            }
    }
    };
    /* *************** END of Derived Class PassengerCar **************** */


    /* ********************** START of Class Node ********************** */
    class Node
    {
    private:
        Node * nxt;
        Car * data;


        /* ******* default constructor ***** */
        Node()
        {
            nxt = nullptr;
            data = nullptr;
        }
    public:
        friend class StringOfCars;

    };
    /* ******************** END of Class Node *************************** */


    /* *************** START of Class StringOfCars ********************** */
    class StringOfCars
    {
        private:
            Node * head;
            Node * tail;
        public:
            StringOfCars()
            {
                head = nullptr;
                tail = nullptr;
            }

        StringOfCars(const StringOfCars & oldstrngCar)
        {
            Node * currentNodePtr = oldstrngCar.head;
            head = nullptr;
            tail = nullptr;

        if (oldstrngCar.head != nullptr)
        {
            while (currentNodePtr != nullptr)
            {
                push(*currentNodePtr->data);
                currentNodePtr = (*currentNodePtr).nxt;
            }
        }
        }


        /* ********* Destructor ***********/
        ~StringOfCars() {}


        /* ******************** output ********************
        prints the cars inside the string of cars along with its heading.
        */
        void output()
        {
            Node * currentNodePtr;
            if (head == nullptr)
            {
                cout << "No cars\n";
            }
            else
            {
                currentNodePtr = head;
                int currentCarNumber = 0;
                while (currentNodePtr != nullptr)
                {
                    cout << "Car Number " << ++currentCarNumber << endl;
                    (*currentNodePtr->data).output();
                    currentNodePtr = (*currentNodePtr).nxt;
                }
            }
        }


        /* ******************** push ********************
        adds a car to the string of cars
        */
        void push(const Car & tempCar)
        {
        Car* currentCarPtr = new Car(tempCar);
        Node* currentNodePtr = new Node;

        (*currentNodePtr).data = currentCarPtr;

            if (head == nullptr)
            {
                head = currentNodePtr;
                tail = currentNodePtr;
            }
            else
            {
                (*tail).nxt = currentNodePtr;
                tail = currentNodePtr;
            }
        }
    };
    /* *************** END of Class StringOfCars ********************************* */


    /* ************************* START Function Prototypes *********************** */
    void input(StringOfCars & carArray);
    void buildCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray);
    void buildFreightCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray);
    void buildPassengerCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray);
    /* ************************* END Function Prototypes ************************ */


    /* ***************** operator == *****************
    -tests for equality between two Car objects based
     on the input for variables reportingMark and carNumber
    */
    bool operator==(const Car &carA, const Car &carB)
    {
        bool temp;
        if (carA.reportingMark == carB.reportingMark && carA.carNumber == carB.carNumber)
        {
            temp = true;
        }
        else
        {
            temp = false;
        }
    return temp;
    }


    /* ******************** input ********************
    -takes the carType, reportingMark, carNumber, kind, loaded
     and destination from file
    -Pushes car data to String Of Cars
    */
    void input(StringOfCars & carArray)
    {
        string type;
        string order;
        string rMark;
        int carNum;
        string carKind;
        bool isLoaded;
        string dest;
        ifstream inputFile;

        inputFile.open("cardata61.txt");

        if (!inputFile)
        {
            cerr << "Error while opening the file. Error code 1" << endl;
            exit(1);
        }

        while (inputFile.peek() != EOF)
        {
            inputFile >> type;
            inputFile >> order;
            inputFile >> rMark;
            inputFile >> carNum;
            inputFile >> carKind;

            string temp;
            inputFile >> temp;
            if (temp == "true")
            {
                isLoaded = true;
            }
            else if (temp == "false")
            {
                isLoaded = false;
            }

            while (inputFile.peek() == ' ')
            {
                inputFile.get();

                getline(inputFile, dest);

                if (type == "Car")
                {
                    buildCar(rMark, carNum, carKind, isLoaded, dest, carArray);
                }
                else if (type == "FreightCar")
                {
                    buildFreightCar(rMark, carNum, carKind, isLoaded, dest, carArray);
                }
                else if (type == "PassengerCar")
                {
                    buildPassengerCar(rMark, carNum, carKind, isLoaded, dest, carArray);
                }
            }
        }
        inputFile.close();
    }


    /* ******************** buildCar ********************
    -builds an object of type car using the car constructor
    */
    void buildCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray)
    {
        Car obj = Car(rMark, carNum, carKind, isLoaded, dest);
        carArray.push(obj);
    }


    /* ******************** buildFreightCar ********************
    -builds an object of type FreightCar using the FreightCar constructor
    */
    void buildFreightCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray)
    {
        FreightCar obj = FreightCar(rMark, carNum, carKind, isLoaded, dest);
        carArray.push(obj);
    }


    /* ******************** buildPassengerCar ********************
    -builds an object of type PassengerCar using the PassengerCar constructor
    */
    void buildPassengerCar(string rMark, int carNum, string carKind, bool isLoaded, string dest, StringOfCars & carArray)
    {
        PassengerCar obj = PassengerCar(rMark, carNum, carKind, isLoaded, dest);
        carArray.push(obj);
    }
    /* *****************************************************End of Global Area******************************************************** */


    /* **************** Main ******************* */
    int main()
    {
        StringOfCars stringOfCars1;
        input(stringOfCars1);

        StringOfCars stringOfCars2(stringOfCars1);
        stringOfCars2.output();
    }

Attachments:

Answers

(5)
Status NEW Posted 09 Jan 2018 11:01 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)