Computer Science, asked by gowsikkdgk, 8 months ago

write the code in c++ for below requirement. .....

Program : Vehicle Registration system

 

Requirements:

Base class : Vehicle (Ideally an abstract base class)

Derived class : Two_wheeler, Three_Wheeler, Four_Wheeler

 

Each vehicle should have:

·         Member variables : regNumber_m (int32),  owner_m(string : owner name) type_m (Should be enum, describes if it is 2/3/4 wheeler)

·         Default Constructor should set appropriate default values for members.

·         Parameterized constructor should take all member values

·         Copy Constructor should assign values for all members

·         Overloaded assignment operator should assign values for all members

·         void show() : should display all values

·         Note: Each method should display “method entry”.

Ex: Whenever Parameterized constructor is called, it should display “Parameterized constructor …” apart from its intended functionality.

 

·         displayVehicles() : This method prints each Vehicle (should use Vehicle::show()).

·         SearchVehicle(int num): Displays details of vehicle, if found using num. Otherwise displays “Vehicle not found with Registration number <num>”.

 

Main:

§  Read the number of vehicles 

§  Read type, number, owner_m for each vehicle

§  Dynamically create the object using type and other values (new operator).

§  Add the object to appropriate STL container

§  Call displayVehicles()

§  Prompt user to input a number and Call SearchVehicle() method 

  

Sample output:

 

Two Wheeler:

  Number : 9999

  Owner  : Aneesh

  

Four Wheeler:

  Number : 1234

  Owner  : Nikhil

Answers

Answered by ıtʑFᴇᴇʟɓᴇãᴛ
18

\mathcal{\huge{\fbox{\red{Answer:-}}}}

#Css

<Vehicle Registration system>

#ifndef VEHICLE_H

#include <iostream>

#include <fstream>

#include <iomanip>

#include <functional>

#include <algorithm>

#include <string>

#include <cstdlib>

#include <sstream>

using namespace std;

//Two_wheeler, Three_Wheeler, Four_Wheeler>

//Vehicle Class

class Vehicle {

protected:

Vehicle myVehicle[9];

string make; //make

string model; // model

string color; // color

int year; // year

int mileage; // miles on car

string type; //Type of vehicle public:

//Constructor that will set information for a new car

void New_vehicle (string a, string b, string c, int d, int e)

{make = a; model = b; color = c; year = d; mileage = e;}

a, b//regNumber_m (int32),  owner_m(string : owner name) type_m (Should be enum, describes if it is 2/3/4 wheeler)>

·        // Default Constructor should set appropriate default values for members.>

·         //Parameterized constructor should take all member values>

·         //Copy Constructor should assign values for all members>

·        // Overloaded assignment operator should assign values for all members>

·       <  void show() : should display all values/>

Vehicle(); //Default constructor

·         </ displayVehicles() : This method prints each Vehicle (should use Vehicle::show()).

·       {\  SearchVehicle(int num): Displays details of vehicle, if found using num. Otherwise displays “Vehicle not found with Registration number *> <num>”.

Vehicle(string, string, string, int, int, string);

//mutator and accessor functions

<\string getMake();

string getModel();

string getColor();

int getYear();

int getMileage();

string getType();

//Check mileage to see if valid

void valid_mileage(int);

//virtual function

virtual void details() {

}

};

//Sets to default values

Vehicle::Vehicle() {

make = " ";

model = " ";

color = " ";

year = 0;

mileage = 0;

type = " ";}

Vehicle::Vehicle(string make, string model, string color, int year, int mileage, string type) {

Vehicle::make = make;

Vehicle::model = model;

Vehicle::color = color;

Vehicle::year = year;

valid_mileage(mileage);

Vehicle::type = type;}

Prompt no. />

STL/>

void Vehicle::valid_mileage(int mileage) {

if (mileage>=0)

Vehicle::mileage=mileage;

else {

Vehicle::mileage=0;

cout << "WARNING! You have entered invalid mileage!\n";

}

Vehicle& getVehicle(int n) {

return myVehicle[n }};

__________________________________________

\mathcal{\huge{\</strong><strong>fbox</strong><strong>{\purple{</strong><strong>O</strong><strong>u</strong><strong>t</strong><strong>p</strong><strong>u</strong><strong>t</strong><strong>:-}}}}

  • Two Wheeler:

  •   Number : 9999

  •   Owner  : Aneesh

  • Four Wheeler:

  •   Number : 1234

  •   Owner  : Nikhil

_________________________________

Similar questions