Question

C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

C++ Visul Studio
Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to display the field values. [Note: Sale tax is 10%, sale tax = Unit price * saleTax) Create a subclass named VehicleOrder that overrides computePrice() function by adding a shipping and handling charge of $12.00. Write an application named UseVehicle that instantiates an object of each of these classes. Prompt the user for data for the Vehicle object, and display the results, then prompt the user for data for the VehicleOrder object, and display the results.

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

HI, Please find my implementation.

please let me know in case of any issue.

########### Vehicle.h ###########


#include <iostream>
using namespace std;

#ifndef VEHICLE_H
#define VEHICLE_H
class Vehicle{

private:
   string vehicleName;
   int vehicleNumber;
   float saleTax;
   float unitPrice;
protected:
   float totalPrice;

public:

   // setters

   void setVehicleName();
   void setVehicleNumber();
   void setSalesTax();
   void setUnitPrice();

   // getters
   string getVehicleName();
   int getVehicleNumber();
   float getSalesTax();
   float getUnitPrice();

   virtual void computePrice();

   void displayTotalPrice();
};
#endif

################ Vehicle.cpp ############

#include "Vehicle.h"
#include <iostream>
using namespace std;

// setters

void Vehicle::setVehicleName(){
   cout<<"Enter vehicle name: ";
   cin>>vehicleName;
}
void Vehicle::setVehicleNumber(){
   cout<<"Enter number of vehicle: ";
   cin>>vehicleNumber;
}
void Vehicle::setSalesTax(){
   cout<<"Enter sale tax: ";
   cin>>saleTax;
}
void Vehicle::setUnitPrice(){
   cout<<"Enter unit price: ";
   cin>>unitPrice;
}

// getters
string Vehicle::getVehicleName(){
   return vehicleName;
}
int Vehicle::getVehicleNumber(){
   return vehicleNumber;
}
float Vehicle::getSalesTax(){
   return saleTax;
}
float Vehicle::getUnitPrice(){
   return unitPrice;
}


void Vehicle::computePrice(){

   float price = (unitPrice*vehicleNumber);
   totalPrice = price + (price*saleTax);
}

void Vehicle::displayTotalPrice(){
   cout<<"Total price: "<<totalPrice<<endl;
}

############### VehicleOrder.h ################

#include "Vehicle.h"

class VehicleOrder : public Vehicle{

public:
   void computePrice();
};

############### VehicleOrder.cpp ################

#include "VehicleOrder.h"

void VehicleOrder::computePrice(){
   float price = getUnitPrice()*getVehicleNumber();
   totalPrice = price + (price*getSalesTax()) + 12;
}

############### UseVehicle.cpp #################

#include "VehicleOrder.h"
#include <iostream>
using namespace std;

int main(){

   // creating object of VehicleOrder
   VehicleOrder vehicle;

   vehicle.setVehicleName();
   vehicle.setVehicleNumber();
   vehicle.setSalesTax();
   vehicle.setUnitPrice();

   vehicle.computePrice();

   vehicle.displayTotalPrice();

   return 0;
}

thirdweek thirdweek thirdweek g++ UseVehicle.cpp VehicleOrder.cpp Vehicle.cpp thirdweek ./a.out Enter vehicle name: Maruti En

Add a comment
Know the answer?
Add Answer to:
C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...
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
  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • Question 1 (Marks: 35) Create a class named Customer that will determine the monthly repayment amount...

    Question 1 (Marks: 35) Create a class named Customer that will determine the monthly repayment amount due by a customer for a product bought on credit. The class has five fields: customer name, contact number, product price, number of months and the monthly repayment amount. Write get and set methods for each field, except for the monthly repayment amount field. The set methods must prompt the user to enter the values for the following fields: customer name, contact number, product...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • 7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables...

    7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables : lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables . Next, design a class  named CustomerData, which is derived from the PersonData class . The CustomerData class should have the following member variables : customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool....

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Graded Exercise Create a class named Student. A Student has fields for an ID number, number...

    Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...

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