What will the following
#include <iostream.>
using namespace std;
class First
{
protected:
int a;
public:
First(int x = 1)
{ a = x; }
void twist()
{ a *= 2; }
int getVal()
{ twist(); return a; }
}:
class Second : public First
{
private:
int b;
public:
Second(int y = 5)
{ b = y; }
void twist()
{ b *= 10: }
}:
int main()
{
First object1;
Second object2;
cout ≪ object1.getVa˥ ()≪ end˥
cout ≪ object2.getVa˥ ()≪ end˥return 0:
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Software Engineering (10th Edition)
Modern Database Management (12th Edition)
Database Concepts (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Java: Early Objects (6th Edition)
- Reuse your Car class . In a main, build an object of that class, and print out the object using System.out.println(). Notice that this simply reports the memory address of the object in question, and we’d like to do something more useful. To replace (or override) the toString (or equals) function. Now, build a toString function that prints out the make, model, and odometer reading for a vehicle object. public class Car { //instance variables private int odometer; private String make; private String model; //overloading //constructors public Car(int odometer,String make, String model) { this.odometer = odometer; this.make = make; this.model = model; } public Car(String make, String model) { this.make = make; this.model = model; } public Car(String make) { this.make = make; } /* *getter & setter methods */ public int getOdometer() { return odometer; } public void…arrow_forwardIn Java, Write a line of code that performs each of the following tasks : (a) Call superclass Employee's toString method from subclass Pieceworker's toString method. (b)Specify that class Pieceworker inherits from class Employee. (c) Call superclass Employee's constructor from subclass Pieceworker's constructor - assume that the superclass constructor receives three strings representing the first name, last name and social security number.arrow_forwardPlease with interface Write a program in Java for the university consisting of the following categories: A mere Person classification contains the following variables:String name The person's name. 1int id id number. 2Write a constructor that receives the variables and a function (ID int , name String(add) whereYou receive the person's name and ID number and assign them. Write the Students class that inherits from the Person class containing the variablesnext:String Specialization The student's specialization. 1double gpa student average. 2Write a constructor that accepts the variables. (Two and a half degrees). Write the Employee class that inherits from the Person class containing the variablesnext:String jop The job name. 1int salary 2Write a constructor that accepts the variables. Create an interface for the program as shown in the following imagearrow_forward
- Hello, I am having trouble with this homework question for my c++ course. Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to create numerator/1 3) dual parameter constructor to create numerator/denominator 4) Use constructor delegation across all constructors. b) Accessors and Mutators for both data members. c) Static recursive GCD function using Euclid's algorithm. d) Static LCM function for two numbers. e) Reduce function simplify a rational number. This function modifies its calling object. f) Your program should work with the supplied driver program. Notes LCM (Least Common Multiple) This function returns the smallest multiple of a and b. Step 1: Multiply a and b to find a common multiple. Step 2: Divide the common multiple by the GCD of a and b. Step 3: Return the result of Step 2. Reduce: This function reduces a fraction to…arrow_forwardI need to know how to do this in python: The base class Pet has attributes name and age. The derived class Dog inherits attributes from the base class Pet class and includes a breed attribute. Complete the program to: Create a generic pet, and print the pet's information using print_info(). Create a Dog pet, use print_info() to print the dog's information, and add a statement to print the dog's breed attribute. Ex: If the input is: Dobby 2 Kreacher 3 German Schnauzer the output is: Pet Information: Name: Dobby Age: 2 Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzerarrow_forwardWrite a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry(). Opp Javaarrow_forward
- Do the following program in Java Eclipse. Java Class that can be used to create a Fruit object as described below: A fruit has - a: - Date of Harvest -Color -Weight -Number of seeds a. Add all instance variables. b. The class must have getters and setters for all instance variables. c. The class must have two constructors, a no-args and a constructor that receives input for each instance variables. d. The parent class is abstract. e. its 1 abstract method and has toString() method f. its 2 children (concrete) also have toString() methods.arrow_forwardUse the following partial class definitions to answer the question: public class A1 { public int x; private int y; protected int z; } public class A2 extends A1 { protected int a; private int b; } public class A3 extends A2 { private int q; } Which of the following lists of instance data are accessible in A3? Group of answer choices x, y, z, a, b, q a, b, q a, q x, z, a, q x, a, qarrow_forward8.. I need a program statement to create an object of the class Auto with a model of "Java" with a model year of 2021. public class Auto { String make="Unknown"; String model = "Unknown": int year = 0; float price = 0.0; public Auto0 { } public Auto(String given Model, int model Year) { model = givenModel; year = model Year, } public String getModelo { retum model: } public void setModel(String given Model) { model = givenModel; } public int gerYear { retum year }arrow_forward
- Python Code please Point of Sale Write a program that will manage the point of sale in a store. Build the ItemToPurchase class with the following: Attributes item_name (string) item_price (int) item_quantity (int) Default constructor Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Example of print_item_cost() output:Bottled Water 10 @ $1 = $10 Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Example of print_item_description() output:Bottled Water: Deer Park, 12 oz. Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor…arrow_forwardPlease help with the following: Change the code from JAVA to C# public class HealthProfile { private String firstName; private String lastName; private char gender; private int day; private int month; private int year; private double height; private double weight; // Constructor public HealthProfile(String firstName, String lastName, char gender, int day, int month, int year, double height, double weight) { super(); this.firstName = firstName; this.lastName = lastName; this.gender = gender; this.day = day; this.month = month; this.year = year; this.height = height; this.weight = weight; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public char…arrow_forward8- In the following code, where do you find overloading and where do you findoverriding? Why?public class HumanBeing{private String name;public HumanBeing(String myName){name = myName;}public String getInfo)({return "I am a human being " ;}}public class Student extends HumanBeing{private int id;private static int nextId = 0;public Student(String theName){super(theName);id = nextId;nextId;++}public int getId() {return id;}public void setId (int theId){ this.id = theId;}public void getInfo(){System.out.println( "I am a student " );}public String getInfo(){return "I am a student " ;}public String getInfo(int num){String s = "I am a student nr: " +num;return s;}}arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education