Question

write C++ program Create a class named Bicycle with one public pure virtual function showFeatures(). Create...

write C++ program

Create a class named Bicycle with one public pure virtual function showFeatures(). Create the two classes MountainBike and BeachCruiser that both publicly inherit from Bicycle. Please add necessary member variables and functions to each class. The showFeatures() function shows the details about a bicycle.

should have main.cpp Bicycle.h Bicycle.cpp  MountainBike .h  MountainBike.cpp  BeachCruiser.h  BeachCruiser.cpp

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

/*
 *  Main.cpp
 */

#include <iostream>
using namespace std;

#include "MountainBike.h"
#include "BeachCruiser.h"

int main () {

  Bicycle bic;
  MountainBike mntBik;
  BeachCruiser brchCrus;

  Bicycle *biPtr = &bic;
  Bicycle *biPtr2 = &mntBik;
  Bicycle *biPtr3 = &brchCrus;

  biPtr->setValues("ASM", "Red", 900);
  biPtr2->setValues("Bana", "Black", 3000);
  biPtr3->setValues("Nibbi", "White", 15000);

  biPtr->showFeatures();
  biPtr2->showFeatures();
  biPtr3->showFeatures();

  return 0;
}

/*  Main.cpp ends here*/





/*
 *  Bicycle.h file
 */

#pragma once

#include <iostream>
#include <string>
using namespace std;

class Bicycle
{
  protected:
    string model;
    string color;
    double price;

  public:
    void setValues(string m, string c, double p);

    virtual void showFeatures()
    {
      cout << "Features of bicycle -" << endl;
      cout << "Model: " << model << " ";
      cout << "Color: " << color << " ";
      cout << "Price: " << price << endl << endl;
    }

};

/*  Bicycle.h file ends here  */





/*
 *  Bicycle.cpp
 */

#include "Bicycle.h"

void Bicycle :: setValues(string m, string c, double p)
{
  model = m;
  color = c;
  price = p;
}

/*  Bicyle.cpp ends here  */





/*
 *  MountainBike.h file
 */

#pragma once

#include "Bicycle.h"

class MountainBike : public Bicycle
{
  public:
    virtual void showFeatures()
    {
      cout << "Features of mountain bike -" << endl;
      cout << "Model: " << model << " ";
      cout << "Color: " << color << " ";
      cout << "Price: " << price << endl << endl;
    }
};

/*  MountainBike.h ends here  */





/*
 *  MountainBike.cpp file
 */


#include "MountainBike.h"

//  Include more function here


/*  MountainBike.cpp ends here  */





/*
 *  MountainBike.h file
 */

#pragma once

#include "Bicycle.h"

class BeachCruiser : public Bicycle
{
  public:
    virtual void showFeatures()
    {
      cout << "Features of breach cruiser -" << endl;
      cout << "Model: " << model << " ";
      cout << "Color: " << color << " ";
      cout << "Price: " << price << endl << endl;
    }
};

/*  MountainBike.h ends here  */






/*
 *  MountainBike.cpp file
 */


#include "BeachCruiser.h"

//  Include more function here


/*  MountainBike.cpp ends here  */

Add a comment
Know the answer?
Add Answer to:
write C++ program Create a class named Bicycle with one public pure virtual function showFeatures(). Create...
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
  • Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class...

    Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class named Building with one public pure virtual function computerEnergyConsumption() that returns a double value of the instance variable which stores the energy consumed by the building. Create the two classes SolarBuilding and WindMill that both publicly inherit from Building. SolarBuilding has an instance variable that stores the energy generated by the solar panels. WindMill has...

  • Help with this coding assignment for C++! Add any comments for better understanding. Create a class...

    Help with this coding assignment for C++! Add any comments for better understanding. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • Create a class named Game using the following UML class diagram. GAME -gameName : string +Game()...

    Create a class named Game using the following UML class diagram. GAME -gameName : string +Game() +setGameName(in name : string) : void +getGameName() : string +displayMessage() : void This class has 2 member variables namely playerName and playerScore. The class contain following member functions: Constructor, set function, get functions, display function. Code write in 3 files: Game.h header file, funtion.cpp file and main.cpp file. The output should be: Player John has scored 50 points.

  • Create a class called Pair that has two public integer member variables named "a" and "b",...

    Create a class called Pair that has two public integer member variables named "a" and "b", and a public member function named sum() that has no arguments but adds the two member variables together and returns their sum.

  • Car Class Background: Write a class named Car that will be used to store information and...

    Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - an int that holds the car's year model • make-A string that holds the make of the car • speed - an int that holds the car's current speed 2. In addition the class should have the following member...

  • Create a program that calculates the area of various shapes. Console Specifications Create an abstract class...

    Create a program that calculates the area of various shapes. Console Specifications Create an abstract class named Shape. This class should contain virtual member function named get_area() that returns a double type. Create a class named Circle that inherits the Shape class and contains these constructors and member functions: Circle(double radius) double get_radius() void set_radius(double radius) double get_area() Create a class named Square that inherits the Shape class and contains these constructors and member functions: Square(double width) double get_width() void...

  • Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate...

    Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate headers) Define a base class named "Venue" that holds the following member variables and functions: Type of venue (string), e.g. public venue, private venue, community venue Year opened (int) Capacity (int) Base price (float), holds the average ticket price for the venue Potential revenue (float), a function returning capacity * base price Next, define a class named "Theater" that is derived from the "Venue"...

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