Concept explainers
Create a base class called Vehicle that has the manufacturer’s name (type string), number of cylinders in the engine (type int), and owner (type Person, given below). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double since it may contain a fractional part) and towing capacity in pounds (type int). Be sure your classes have a reasonable complement of constructors, accessor, and mutator member functions, an overloaded assignmentoperator, and a copy constructor. Write a driver program that tests all your member functions.
The definition of the class Person follows. The implementation of the classis part of this
class Person { public: Person(); Person(string theName); Person(const Person& theObject); string getName() const; Person& operator = (const Person& rtSide); friend istream& operator >>(istream& inStream, Person& personObject); friend ostream& operator <<(ostream& outStream, const Person& personObject); private: string name; }; |
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Artificial Intelligence: A Modern Approach
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Concepts Of Programming Languages
- Every employee in a firm XYZ has attributes employeeid, name and salary. However the sales employees in firm XYZ has all the attributes of employees and also has an additional attribute named bonus. You are a software developer who has to the implement the relation between employee and sales employee. Write the code for classes employee and employee_sales. Write the constructors for both classes that set the attributes of both classes.arrow_forwardTake the following code snippets (see below) and put them into a class called Employee. Then create two concrete (non-abstract) classes: Cashier and Supervisor Set the base salary of cashiers to be $30,000. Set the base salaries of supervisors to be $60,000. (use their constructors to do this). Create different methods for getMontlySalary() for the Cashier and Supervisor classes. a) for the Cashier class, just divide the basic salary by 12 to get the monthly. b) for the Supervisor class, also add a 10% bonus. So a supervisor before any raises would earn $5500 per month. (60,000/12 + 10%) Create an employee tester class. Add an array of 10 employees. put 8 cashiers and 2 supervisors into the array. Print out the complete records of all 10 employees using a for loop. (Hint: Overload the toString() on all Employee class). abstract class Employee {private String name, address; private int basicSalary;public String getName(){ return name; }public String getAddress(){ return address;…arrow_forwardThe class "Car" has the following attributes: plate (String), mark (String), model (String), year (int), km (int).Write a constructor method for the "Car" class that takes values as parameters for all these attributes.arrow_forward
- For each statement, indicate if it is True or False by circling T or F. If you need to cross out an answer, be sure that your final answer is clear and unambigous-otherwise it will receive no credit. 1- An object of a derived class has access to the public methods of its base class T F 2- An object of a base class has access to the private helper methods of its derived class T F 3- Destructors are not inherited by derived classes T F T F T F u- An object of a derived class inherits the copy constructor of its base class 5- Operators are passed down inheritance hierarchies 6- Destructors in derived classes are called after their base class calls its destructor 7. Constructors of base classes are accessible by derived classes T T F Farrow_forwardComplete the code for the following program. You are provided with an abstract class called abst. Create a class that will be a child of abst and it will be called usesAbst. Your program will have an int variable called value, and all the appropriate methods, as well 2 constructors. The first constructor will simply set the variable value to 0. The second constructor will set the variable value to equal a passed in parameter. You do not have to comment your code. public abstract class abst{ public abst () { } //Outputs to the screen the message Hello public abstract void sayHello (); //returns the stored int value public abstract int getValue (); //sets the int value to x public abstract void setValue (int x); //Outputs to the screen the message Another method public void output () { System.out.println("Another method"); public String tostring () { return "This is an abstract class"; }arrow_forwardThe class "Plant" has the following attributes: name (String), family (String), lifeSpan (int). Write a constructor method for the "Plant" class that takes values as parameters for all these attributes. A- BI II !!arrow_forward
- Deeper Class Design - the Square Class In this section, your job will be to write a new class that will adhere to the methods and data outlined in the “members” section below (said another way, your classes will implement a specific set of functions (called an interface) that we’ll describe contractually, ahead of time). These classes will all be shapes, with actions (methods) that are appropriate to shape objects, such as “getArea()”, or “draw()”. First we build a Square class that contains the following data and methods listed below, and then later, we will copy it to quickly make a Circle class. Note: when considering each data item below, think about what type of data would best represent the concept we’re trying to model in our software. For example, all shapes will have a coordinate pair indicating their location in a Cartesian coordinate system. This x and y pair may be modeled as ints or floats, and you might choose between the two depending on what the client application will…arrow_forwardPart I Create Philosopher and Pasta classes. Write proper attributes, constructors, and get&set methods required for the rest of the questions. Part II Create a method for allowing the Philosopher to eat the Pasta. Part III Create a method for allowing multiple Philosophers to eat the same Pasta at the same time.arrow_forward3. Person and Customer Classes The Person and Customer Classes Write a class named Person with data attributes for a person’s name, address, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Demonstrate an instance of the Customer class in a simple program.arrow_forward
- Design a class named Person with properties for holding a person’s name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Demonstrate an object of the Customer class in a simple application.arrow_forwardLanguage is Java Write a Clothing class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "Doctor Who hoodie", "slacks") price (e.g., 19.99, 7) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 Clothing objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this:These work trousers are blue and cost $27.99.Don't hardcode the print statement for full credit, you must use the gettersarrow_forwardDesign 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 these values and the appropriate mutator and accessor methods for the class's fields. Demonstrate the Customer class in a program that prompts the user to enter values for the customer's name, address, phone number, and customer number, and then asks the user whether or not the customer wants to receive mail. Use this information to create a customer object and then print its information. Put all of your classes in the same file. To do this, do not declare them public. Instead, simply write: class Person…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,