Question

I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT.

Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas.

Part II: PA3: Car Dealership (40 points)

For Programming Assignment 3 you will be creating a program to manage cars in a dealership. This will again be a menu driven system. You will make a vector of Dealers (there can be zero to many dealers). Each dealer can have zero to many cars on the lot, represented by not by a vector, but by a dynamic array. The following is your menu:

Read Dealers and Cars from file

Display Dealers

Choose a Dealer Number, Display Cars

Choose a Dealer Number, Add Car

Choose a Dealer, Sort cars by VIN (EXTRA CREDIT)

Write Dealers and Cars to file (EXTRA CREDIT)

Exit

Your program will be object oriented (using classes) with the following UML representing the classes (See Chapter 13 for UML Access Specification information):

Dealer

+ Dealer ( )

// Don’t forget to add a new car pointer when you use the Dealer default / constructor

+ Dealer ( dName:string, dNumber:int)

- dealerName: string

- dealerNumber: int

- carArrayPtr: pointer to a Dynamic Car Array (Note: make sure this is set to nullptr)

- numberOfCars: int

+ setDealerName ( _dealerName:string): void

+ setDealerNumber (_dealerNumber:int ): void

+setCarArrayPtr (_carArrayPtr: Car *): void //(This is where you use the new)

+setNumberOfCars ( int _numberOfCars): void

+ getDealerName ( ): string

+ getDealerNumber ( ): int

+ getCarArrayPtr ( ): Car *

+getNumberOfCars: int

+ friend operator << (out: ostream &, Dealer: _dealer):ostream &
   //Print the Dealer Name and Number and Blank line for a specific dealer.

Car

- VIN:string

- make:string

- model:string

- year:int

- price:double

+ Car( )

+ Car(vVIN:string, vMake:string, vModel:string, vYear:int, vPrice:double)

+ getVIN( ):string

+ getMake( ):string

+ getModel( ):string

+ getYear( ):int

+ getPrice( ):double

+ setVIN(_VIN:string):void

+ setMake(_make:string):void

+ setModel(_model:string):void

+ setYear(_year:int):void

+ setPrice(_price:double):void

+ friend operator << (out: ostream &, Car: _car):ostream &
   //Print the VIN, Make, Model, Year, Price and Blank line for a specific car.

You will have four files for your program (Use these file names!): main.cpp, functions.h, Dealer.h, Dealer.cpp. Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to canvas

main.cpp: this will be your driver file.

functions.h: this will contain your functions for each of the menu items.

Dealer.h: this will contain the class declarations for car and dealer including the operator <<.

Dealer.cpp: this will contain the class implementations for car and dealer.

You will be storing your dealer objects in a vector. In the main function, you will create a vector of Dealers with an initial size of zero (0). When the menu are called, you will have to check your vector and ensure that it is not empty before referring to the index number of the vector. Your Dealer vector points to a dynamic array of cars. Again, when you access the cars class you should verify that it is not set to nullptr.

You will not have any global variables.

Each menu item will have a corresponding function, and the definition of the function will be found in the file functions.h. All input/output will be done in the functions and not in main (expect asking for what menu option the user wants).

The following are the details for each of your menu options:

Read Dealers and Cars from file

Display Dealers

Choose a Dealer Number, Display Cars

Choose a Dealer Number, Add Car

Choose a Dealer, Sort cars by VIN (EXTRA CREDIT)

Write Dealers and Cars to file (EXTRA CREDIT)

Exit

Pass the vector of dealers (from main) into the function by reference. Each Dealer will have a name and number followed by the number of cars in the dealership (on separate lines). Then you will read in a Vin, Make, Model, Year and Price for each car (on separate lines). You can assume that the number of cars as well as the Vin, Make, Model, Year and Price will be complete for each car. Each dealer can have Your file format will be as follows:

Dealer Name
Dealer Number
2
Car1 Vin
Car1 Make
Car1 Model
Car1 Year
Car1 Price
Car2 Vin
Car2 Make
Car2 Model
Car2 Year
Car2 Price
Dealer Name
Dealer Number
1
Car1 Vin
Car1 Make
Car1 Model
Car1 Year
Car1 Price

Here is an example file:

John Elway Dodge

1

2

VIN123

Dodge

Ram 1500 Quad Cab

2017

45186.00

VIN456

Chevrolet

Traverse Premier SUV

2017

47868.00

Tesla Cherry Creek

25

1

VIN789

Tesla

Model X

2017
105200

2. Pass the vector of dealers (from main) into the function by reference. Display the Dealer Name and Number for each dealer (put a blank line between dealers). Use the << operator with cout (cout << dealer[x];)

3. Pass the vector of dealers (from main) into the function by reference. Display the Dealer Names and Numbers (menu #2). Ask the user for the dealer number, display all of the cars by using a for loop (from zero to size of the car array) using the << operator with cout ( cout << dealer[x].carArrayPtr[x];)

4. Pass the vector of dealers (from main) into the function by reference. a) Display the Dealer Names and Numbers (menu #2). b) Ask the user for the dealer number then the new car information. Follow the steps found in CSCI 1411 Lab 09 to increase the dynamic array. (Essentially you will make a new array, one bigger than the previous car array. Then you will copy everything over from the old car array to the new one. Then you will point the car pointer to the new array)

You can earn up to 20% extra credit (48/40) if 1-4 and 7 work properly and you get 5 and 6 working properly.

5. Pass the vector of dealers (from main) into the function by reference. Display the Dealer Names and Numbers (menu #2).6. Ask the user for the dealer number. Sort the cars by vin and display them (with blank lines between each car

6. Pass the vector of dealers (from main) into the function by reference. Also pass in the filestream (from main) by reference. (Use a different file than your original OR make sure to close the files before overwriting). Write all of the Dealers and Cars to a separate output file in the same format as in item #1

7. Exit out of the program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//main.cpp
#include <iostream>
#include "dealer.h"
#include "functions.h"
#include <vector>
#include <string>


using namespace std;

int main(){
    int userInput;

    vector <Dealer> dealersVector;

    do {

        cout << "Welcome to car dealer program. Please select an option below.\n\n";
        cout << "Enter 1 to read dealers and cars from a file.\n";
        cout << "Enter 2 to display dealers.\n";
        cout << "Enter 3 to choose a dealer number, display cars.\n";
        cout << "Enter 4 to choose a dealer number, add a car.\n";
        cout << "Enter 5 to choose a dealer and sort cars by VIN.\n";
        cout << "Enter 6 to write dealers and cars to a file.\n";
        cout << "Enter 7 to exit.\n";
        cin >> userInput;

        switch (userInput) {
            case 1 :
                //load vector with info from dealers.txt
                loadVector(dealersVector);
                break;

            case 2 :
                //display dealers
                showDealers(dealersVector);
                break;

            case 3 :
                //pick a dealer and display their cars
                displayCars(dealersVector);
                break;

            case 4 :
                //add a car to a specific dealer
                addCar(dealersVector);
                break;

            case 5 :
                //sort cars by VIN in ascending order
                bubbleSort(dealersVector);
                break;

            case 6 :
                //send vector of Dealers to new file
                sendFileout(dealersVector);
                break;

            case 7 :
                return 0;//exit program
                break;

            default :
                cout << "Invalid entry, please enter a valid value\n" << endl; //catch bad input from user
                break;
        }//switch

    } while (userInput != 7);

    return 0;
}
----------------------------------------------------------------------------------------------------
//Dealer.cpp
#include "dealer.h"
Dealer::Dealer(){
    name = "";
    number = -1;
    numOfCars = -1;
    CarArrayPtr = nullptr;
}

Car::Car(){
    vin = "";
    make = "";
    model = "";
    year = -1;
    price = -1.0;
}

Dealer::Dealer(std::string dName, int dNumber, int dNumCars, Car *carPtr){
    name = dName;
    number = dNumber;
    numOfCars = dNumCars;
    CarArrayPtr = carPtr;
}

Car::Car(std::string cVin, std::string cMake, std::string cModel, int cYear, double cPrice){
    vin = cVin;
    make = cMake;
    model = cModel;
    year = cYear;
    price = cPrice;
}

std::ostream& operator<<(std::ostream& out, Dealer dDealer){
    out << "Dealer name: " << dDealer.getDealerName() << std::endl << "Dealer number: " << dDealer.getDealerNumber() << std::endl
        << "Dealer's number of cars: " << dDealer.getNumOfCars() << std::endl;

    return out;
}
std::ostream& operator<<(std::ostream& out, Car cCar){

    out << cCar.getVin() << std::endl;
    out << cCar.getMake() << std::endl;
    out << cCar.getModel() << std:: endl;
    out << cCar.getYear() << std::endl;
    out << "$" << cCar.getPrice() << std:: endl;

    return out;
}


-----------------------------------------------------------------------------------------------------------
//Dealer.h
#ifndef dealer_h
#define dealer_h
#include <string>
#include <iostream>

class Car
{
private:
    std::string vin;
    std::string make;
    std::string model;
    int year;
    double price;
public:
    Car();//default constructor
    Car(std::string cVin, std::string cMake, std::string cModel, int cYear, double cPrice);//constructor
    void setVin(std::string cVin){vin = cVin;}
    void setMake(std::string cMake){make = cMake;}
    void setModel(std::string cModel){model = cModel;}
    void setYear(int cYear){year = cYear;}
    void setPrice(double cPrice){price = cPrice;}
    std::string getVin() const
    { return vin;}
    std::string getMake() const
    { return make;}
    std::string getModel() const
    { return model;}
    int getYear() const
    { return year;}
    double getPrice() const
    { return price;}
    friend std::ostream& operator<<(std::ostream& out, Car cCar);
};

class Dealer
{
private:
    std::string name;
    int number;
    int numOfCars;
    Car *CarArrayPtr;
public:
    Dealer();//default constructor
    Dealer(std::string dName, int dNumber, int dNumCars, Car *carPtr);//constructor
    void setDealerName(std::string dName){name = dName;}
    void setDealerNumber(int dNumber){number = dNumber;}
    void setCarArrayPtr(Car *dCarArrayPtr){CarArrayPtr = dCarArrayPtr;}
    void setNumOfCars(int pNumOfCars){numOfCars = pNumOfCars;}
    std::string getDealerName() const
    { return name;}
    int getDealerNumber() const
    { return number;}
    Car* getCarArrayPtr() const
    { return CarArrayPtr;}
    int getNumOfCars() const
    { return numOfCars;}
    friend std::ostream& operator<<(std::ostream& out, Dealer dDealer);
};

#endif /* dealer_h */
--------------------------------------------------------------------------------
//functions.h
#ifndef functions_h
#define functions_h
#include "dealer.h"
#include <vector>
#include <fstream>
#include <string>

//option 1 in main, pass empty vector by reference to change its contents
void loadVector(std::vector<Dealer> &dealers){

    //temp Car object and its associated data
    Car tempCar;
    std::string tempVin;
    std::string tempMake;
    std::string tempModel;
    int tempYear;
    double tempPrice;

    //temp Dealer object and its associated data
    Dealer tempDealer;
    Car *carPtr;
    std::string dealerName;
    int dealerNum, numOfCars;

    std::fstream inFile;
    //open dealers.txt and pass info into vector
    inFile.open("dealers.txt");
    while(inFile.good()){

        //get Dealer info from dealers.txt
        getline(inFile, dealerName);
        inFile >> dealerNum;
        inFile >> numOfCars;
        inFile.ignore();

        //set temp Dealer object data to file data
        tempDealer.setDealerName(dealerName);
        tempDealer.setDealerNumber(dealerNum);
        tempDealer.setNumOfCars(numOfCars);

        //use empty Car object pointer to create dynamic array of Car objects
        carPtr = new Car[numOfCars];

        //loop through the Dealer object's number of cars, and store each Car object in the dynamic array
        for (int i = 0; i < numOfCars; i++) {
            getline(inFile, tempVin);
            getline(inFile, tempMake);
            getline(inFile, tempModel);
            inFile >> tempYear;
            inFile >> tempPrice;
            inFile.ignore();

            tempCar.setVin(tempVin);
            tempCar.setMake(tempMake);
            tempCar.setModel(tempModel);
            tempCar.setYear(tempYear);
            tempCar.setPrice(tempPrice);

            carPtr[i] = tempCar;
        }

        tempDealer.setCarArrayPtr(carPtr);

        dealers.push_back(tempDealer);

    }//while
    std::cout << "Load successful.\n";
    std::cout << "Read in " << dealers.size() << " dealers." << std::endl;

    inFile.close();
}

//option 2, display dealers
void showDealers(std::vector<Dealer> dealers){

    for (int i = 0; i < dealers.size() ; i++) {
        std::cout << dealers[i];
    }
}

//option 3, choose a dealer and display that dealer's cars
void displayCars(std::vector<Dealer> dealers){

    int dealerNum, dealerIndex = 0;
    Car *carArrayPtr;
    bool found = false;

    //search for dealer number
    std::cout << "Enter the dealer number whos cars you would like to see.\n";
    std::cin >> dealerNum;
    std::cin.ignore();
    for (int i = 0; i < dealers.size(); i++) {
        if (dealers[i].getDealerNumber() == dealerNum ) {
            dealerIndex = i;
            found = true;
        }
    }
    if (!found) {
        std::cout << "Sorry, that dealer is not found.\n";
    }
    else
    {
        //set dummy pointer to the dealer's pointer
        carArrayPtr = dealers[dealerIndex].getCarArrayPtr();

        //display dealer's cars
        for (int i = 0; i < dealers[dealerIndex].getNumOfCars(); i++) {
            std::cout << carArrayPtr[i];
        }
    }
}

//option 4, choose dealer and add a car
void addCar(std::vector<Dealer> &dealers){

    int dealerNum, dealerIndex = 0;
    Car *carArrayPtr;
    Car carToAdd;
    bool found = false;

    std::string vin;
    std::string make;
    std::string model;
    int year;
    double price;

    //find out what dealer the user wants to add to
    std::cout << "Enter the dealer number that you'd like to add a car to.\n";
    std::cin >> dealerNum;
    std::cin.ignore();
    for (int i = 0; i < dealers.size(); i++) {
        if (dealers[i].getDealerNumber() == dealerNum ) {
            dealerIndex = i;
            found = true;
        }
    }
    if (!found) {
        std::cout << "Sorry, that dealer is not found.\n";
    }
    else
    {
        //get new car info from user
        std::cout << "Enter the car VIN.\n";
        getline(std::cin, vin);
        std::cout << "Enter the car make.\n";
        getline(std::cin, make);
        std::cout << "Enter the car model.\n";
        getline(std::cin, model);
        std::cout << "Enter the car year.\n";
        std::cin >> year;
        std::cout << "Enter the car price.\n";
        std::cin >> price;
        std::cin.ignore();
        carToAdd.setVin(vin);
        carToAdd.setMake(make);
        carToAdd.setModel(model);
        carToAdd.setYear(year);
        carToAdd.setPrice(price);

        int setFlag = (dealers[dealerIndex].getNumOfCars() + 1);
        carArrayPtr = new Car[setFlag];

        //copy Dealer object's dynamic array info
        for (int i = 0; i < dealers[dealerIndex].getNumOfCars(); i++) {
            carArrayPtr[i] = dealers[dealerIndex].getCarArrayPtr()[i];
        }

        carArrayPtr[setFlag - 1] = carToAdd;

        dealers[dealerIndex].setCarArrayPtr(carArrayPtr);
        int newNumCars = (dealers[dealerIndex].getNumOfCars() + 1);
        dealers[dealerIndex].setNumOfCars(newNumCars);

    }
}

//option 5, sort cars by VIN in ascending order
void bubbleSort(std::vector<Dealer> &dealers){

    Car tempCar;
    int dealerNum, dealerIndex;
    bool found = true;
    Car *carArrayPtr = nullptr;
    std::string maxElement;

    std::cout << "Enter the dealer number that you'd like to sort the cars by VIN.\n";
    std::cin >> dealerNum;
    std::cin.ignore();
    for (int i = 0; i < dealers.size(); i++) {
        if (dealers[i].getDealerNumber() == dealerNum ) {
            dealerIndex = i;
            found = true;
        }
    }
    if (!found) {
        std::cout << "Sorry, that dealer is not found.\n";
    }
    else
    {
        carArrayPtr = new Car[dealers[dealerIndex].getNumOfCars()];

        for (int i = 0; i < dealers[dealerIndex].getNumOfCars(); i++) {
            carArrayPtr[i] = dealers[dealerIndex].getCarArrayPtr()[i];
        }

        int flag;

        for (int j = 0; j < dealers[dealerIndex].getNumOfCars() - 1; j++) {
            for (flag = 0; flag < dealers[dealerIndex].getNumOfCars() - 1 - j; flag++) {
                if (carArrayPtr[flag].getVin() > carArrayPtr[flag + 1].getVin()) {
                    std::swap(carArrayPtr[flag], carArrayPtr[flag + 1]);
                }
            }
        }
    }
    dealers[dealerIndex].setCarArrayPtr(carArrayPtr);
}

//used for bubble sort in option 5
void swap(Car &a, Car &b){
    Car temp = a;
    a = b;
    b = temp;
}

//option 6, write vector of dealer object's and their cars to new file
void sendFileout(std::vector<Dealer> &dealers){


    std::ofstream outFile;

    outFile.open("newDealers.txt", std::fstream::app);

    for (int i = 0; i < dealers.size(); i++) {

        outFile << dealers[i].getDealerName() << std::endl;
        outFile << dealers[i].getDealerNumber() << std::endl;
        outFile << dealers[i].getNumOfCars() << std::endl;


        for (int j = 0; j < dealers[i].getNumOfCars(); j++) {
            outFile << dealers[i].getCarArrayPtr()[j];
        }
    }

    outFile.close();
}

#endif /* functions_h */
CarDealer CLionProjects/CarDealer] - .main.cpp CarDealer | DebugQ ーCarDealer main.cpp 郋Project ▼ ▼-CarDealer ~/CLionProjects/

Add a comment
Know the answer?
Add Answer to:
I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car...

    Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...

  • For Programming Assignment 3 you will be creating a program to manage cars in a dealership....

    For Programming Assignment 3 you will be creating a program to manage cars in a dealership. This will again be a menu driven system. The following is your menu: 1. Display Inventory 2. Add a vehicle 3. Update a vehicle 4. Delete a vehicle 5. Sort inventory by VIN 6. Search inventory by Model 7. Read inventory from file 8. Write inventory to file and exit our program will be class based with the following UML representing the classes: Dealer...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

  • QUESTION 18 According to class materials, the program is allowed to overload operators only if at...

    QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...

  • C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that...

    C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...

  • Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design:...

    Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design: You will create a class and then use the provided test program to make sure it works. This means that your class and methods must match the names used in the test program. Also, you need to break your class implementation into multiple files. You should have a car.h that defines the car class, a list.h, and a list.cpp. The link is a struct...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT