What will the following
#include <iostream>
using namespace std;
class First
{
protected:
int a:
public:
First(int x = 1)
{ a = x; }
virtual void twist()
{ a * = 2; }
int getVal ()
{ twist(); return a; }
}:
class Second : public First
{
private:
int b:
public:
Second(int y = 5)
{ b = y; }
virtual void twist()
{ b *= 10: }
};
int main()
{
First object-1;
Second object2;
cout ≪ object1.getVal () ≪ endl;
cout ≪ object2.getVal() ≪ endl;
return 0;
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
STARTING OUT WITH C++ REVEL >IA<
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out With Visual Basic (8th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Python (4th Edition)
C How to Program (8th Edition)
Starting Out with Java: Early Objects (6th Edition)
- Computer Science In Java, create a class Die representing a die to roll randomly. -Give Die a public final static int FACES, representing how many faces all dice will have for this run of the program. -In a static block, choose a value for FACES that is randomly chosen from the options 4, 6, 8, 10, 12, and 20. -Give Die an instance variable current, representing the last value it rolled. (cannot be less than 1 or more than FACES) -Give Die int instance variables maxCount and minCount. (cannot be negative) -Give Die a method roll that randomly sets current to a value between 1 and FACES. If the die rolls a 1, increase minCount, if the die rolls FACES, increase maxCount. -Give Die a static method sumDice, which takes a variable length parameter list of Dies and returns the sum of all their current values. -Give Die a static method sameDice, which takes a variable length parameter list of Dies, and returns true only if all of them have the same current value. Do not compare…arrow_forwardReuse 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_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
- Use the following partial class definitions to answer the questions a-c 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; ... } a) Which of the following is true with respect to A1, A2 and A3? Group of answer choices A1 is a subclass of A2 and A2 is a subclass of A3 A3 is a subclass of A2 and A2 is a subclass of A1 A1 and A2 are both subclasses of A3 A2 and A3 are both subclasses of A1 A1, A2 and A3 are all…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_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
- Please answer the question and explain why. 3. What is wrong with the following program and how should it be fixed? 1 public class MyClassD { 2 public static void main (String args []) { 3 MyClassC m = new MyClassC (23); 4 } // end main 5 } // end class MyClassD 6 7 class MyClassC { 8 int v = 12; 9 10 public MyClassC (int pV) { 11 int v = pV; 12 } 13 14 } // end class MyClassCarrow_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_forwardTake this the Java Gringrots problem below turn it into a running program. where the main should find out how many galleons are from 100,000 knuts. : " Write a Java program using a class identified as Gringots.This Java class has a main, and the following protected member functions: Member function galleons2Sickles has an integer parameter value, and returns an integer value*17Member function sickles2galleons has an integer parameter value, and returns an integer value / 17Member function sickles2nuts has an integer parameter value, and returns an integer value*29Member function knuts2sickles has an integer parameter value, and returns an integer value/29 Member function Galleons2Knuts has an integer parameter value, and then uses member functions Galleons2Sickles and Sickles2Knuts to convert, and then returns the integer. Member function Knuts2Galleons has an integer parameter value, and then uses member functions Knuts2Sickles and Sickles2Galleons to convert, an dthen returns the…arrow_forward
- Which of the following statements about Python is true? A. Python does not support inheritance. B. Python does not support private attributes. C. Python does not support garbage collection. D. Python does not support function overloading. Which of the follow statements calls the constuctor method for the Rectangle class? A. myRectangle = constructor(self).Rectangle B. myRectangle = Rectangle() C. myRectangle = Rectangle().constructor(self) D. constructor(self) = Rectangle() Which of the following statements about Python is true? A. Python does not support inheritance. B. Python does not support operator overloading. C. Python supports garbage collection. D. Python does not support function overloading.arrow_forwardBuild a class Pet having the following data membersa. Name (String)b. Gender (char)c. Type (String)d. Age (int)e. Weight (float)f. healthCondition (int)Imagine this class Pet represents your pet as a virtualobject. Provide constructors with arguments for name,gender, type, age and weight. Initialize healthCondition to 5(which means healthy). Provide getter for each of these but setter for only weight. Provide a function eat(String food). This function represents the action of eating thatwould increase the weight of the pet according to following rulesFood Increase In WeightRed Meat 0.14 kgChicken 0.12 kgPet Food 0.17 kgSupplement 0.1 kgFish 0.09 kgThe eat function returns the new Weight of the pet object.Provide another function fallSick() that reduces the healthCondition of the pet 1 but it cannot gobelow 0. Provide a function bool isDead() this function returns true if the healthCondition of a pet is 0and false otherwise. Add another function recover(). This function increases…arrow_forwardPlease code in C++ and U can take time for this one and please follows all the instruction. Thank you so much. A. Create an abstract base class called Currency with two integer attributes, both of which are non-public (Python programmers - it is understood that there is nothing private in Python but try to not access the attributes directly from outside the classes). The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. B. Create two derived classes - Dollar and Pound - with one additional non-public string attribute which will contain the name of the currency (Dollar or Pound) respectively. DO NOT add this attribute to the base Currency class. C. In your base Currency class, add public methods for the following, where appropriate (C++ students are allowed to use friend methods as long as a corresponding class method is defined as well): Default Construction (i.e. no…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