Answer to Question #212021 in C++ for zain ul abdeen

Question #212021

A typical company has many cars for transportation of their employees. You have to design and implement a system to show live location of all company cars along with driver names. For a company based in Lahore, make a fleet of 10 cars of different make and models (honda city model 2006 x1, model 2011 x3, model 2020 x2, corolla model 2015 x2, model 2020 x2, and 6 drivers (name them of your choice), assign each driver to one of the 10 cars and move those cars to multan, islamabad, karachi, mardan, landi kotal, and sahiwal. Then show the status of all 10 cars on the screen.


1.City 2006 - Landi Kotal (3.232323445,1.2357823633) - Maqsood Ahmad


2.…...


Classes detail.


CAR


.make


.model


.engine


.tyre[4]


.seats


.driver


.SetDriver(Driver)


.Move(Location)


ENGINE


.valves


.hoursepower


.fueltype


.type


TYRE


.diameter


.width


.height


.type


DRIVER


.first_name


.last_name


.employee_code


.age


.gender


.salary


.AssignCar(CAR)


Location


.longitude


.latitude


.LonLatToPlace() returns city


1
Expert's answer
2021-06-30T06:06:57-0400
#include <iostream>
#include <string>
using namespace std;
class Driver{
    string first_name, last_name;
    int employee_code, age;
    public:
    Driver(){}
    Driver(string fn, string ln){
        first_name = fn;
        last_name = ln;
    }
    string name(){
        return first_name + " " + last_name;
    }
};
class Engine{
    string fueltype, type;
    int horsepower, valves;
    public:
    Engine(){}
};
class Tyre{
    float diameter, width, height;
    string type;
    public:
    Tyre(){}
};
class Car{
    string make, model, loc;
    Tyre tyre[4];
    Engine engine;
    int seats;
    Driver driver;
    float location[2];
    public:
    Car(){}
    Car(string make, string model){
        this->make = make;
        this->model = model;
    }
    void setDriver(string fn, string ln){
        this->driver = Driver(fn, ln);
    }
    void move(float *location, string loc){
        for(int i = 0; i < 2; i++)
            this->location[i] = location[i];
        this->loc = loc;
    }
    void show(){
        cout<<make<<" "<<model<<" "<<loc<<" ("<<location[0]<<", "<<location[1]<<") - "<<driver.name()<<endl;
    }
};
int main(){
    string makes[10] = {"City", "Corolla", "Honda", "Tesla", "VW", "BMW", "Nissan", "Harrier", "Porche", "Toyota"}, 
        models[10] = {"2006", "2011", "2020", "S", "Beetle", "X6", "FUGA", "2021", "911", "RAV4"},
        driversfn[10] = {"Maqsood", "Diallo", "Kshmir", "Amar", "Rashid", "Hassan", "Bashir", "Nassir", "Micki", "Bakari"},
        driversln[10] = {"Amad", "Abdul", "Hakim", "Khalid", "Abdalla", "Iman", "Abubakar", "Abdi", "Rhaoul", "Mohammed"}, 
        locs[6] = {"multan", "islamabad", "karachi", "mardan", "landi kotal", "sahiwal"};
    float location[6][2] = {{30.1575, 71.5249}, {33.6844, 73.0479}, {24.8607, 67.0011}, {34.1989, 72.0231}, {34.1186, 71.1567}, {30.66882, 73.1114}};
    Car cars[10];
    for(int i = 0; i < 10; i++){
        cars[i] = Car(makes[i], models[i]);
        cars[i].setDriver(driversfn[i], driversln[i]);
    }
    for(int i = 0; i < 6; i++){
        for(int j = 0; j < 10; j++) cars[j].move(location[i], locs[i]);
        for(int j = 0; j < 10; j++){
            cout<<j+1<<" "; cars[j].show();
        }
        cout<<endl;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS