answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AysviL [449]
2 years ago
10

What is printed by the following program provided all necessary standard header files are included? Explain each line of the out

put by stating which member function generates the result and why to justify your answer.#include iostream> using namespace std; class A { public: virtual void f1() cout<<("fl in A/n") voidf2 () { cout << "f2 in A/n";} }class B: public A {public: void f1() cout <<"fl in B/n"; void f2() cout <<"f2 in B/n }void g(A &x){ x.f1(); x.f2(); int main(){A;aB:bg(a);g(b);a.f1();a.f2();b.f1();b.f2();}
Computers and Technology
1 answer:
Ostrovityanka [42]2 years ago
8 0

<u>Output:</u>

f1 in A

f2 in A

f1 in B

f2 in A

f1 in A

f2 in A

f1 in B

f2 in B  

<u>Explanation:</u>

In this snippet, the code makes use of virtual functions. A virtual function is defined as a function that is defined in the base class and redefined in the derived class. If the derived function accesses the virtual function, the program will get executed with the derived class’s version of the function.

In this code, we define the virtual function f1() in class A and also redefine it in class B which is the derived class of A. While executing the program, the function g which takes the object b (class B’s object) as a parameter. It will print class B’s version of f1() rather than class A’s version. This is working off the virtual function.

You might be interested in
Which organization supports professionals who assist families in making informed choices about products and services?
Naily [24]
The organisation that would best aid families and choose the right products to buy would be the American Association of Family and Consumer Sciences. In addition, the institution is primarily composed of home economists wherein these professionals promote efficient consumer consumption of goods.
6 0
2 years ago
Read 2 more answers
How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
fomenos

Answer:

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

if num1 < 1 or num2<1:

     print("Input must be greater than 1")

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

Explanation

The next two lines prompts the user for two numbers

<em>num1 = int(input("Numerator: "))</em>

<em>num2 = int(input("Denominator: "))</em>

The following if statement checks if one or both of the inputs is not positive

<em>if num1 < 1 or num2<1:</em>

<em>      print("Input must be greater than 1")-> If yes, the print statement is executed</em>

If otherwise, the quotient and remainder is printed

<em>else:</em>

<em>      print("Quotient: "+str(num1//num2))</em>

<em>      print("Remainder: "+str(num1%num2))</em>

<em />

3 0
2 years ago
Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argum
Nata [24]

Answer:

// importing the necessary libraries

import java.util.Scanner;

public class BackwardString {

public static void main(String[] args) {

String input;

// Scanner object to read string from user input

Scanner scanner = new Scanner(System.in);

System.out.print("Enter String here : ");

input=scanner.next();

// calling backward method to reverse passed string

backward(input);

// closing Scanner object

scanner.close();

}

// Method to Reverse the input string

private static void backward(String source) {

int i, len = source.length();

StringBuilder dest = new StringBuilder(len);

for (i = (len - 1); i >= 0; i--){

dest.append(source.charAt(i));

}

System.out.println("Reversed String : "+dest);

}

}

Explanation:

// importing the necessary libraries

import java.util.Scanner;

public class BackwardString {

public static void main(String[] args) {

String input;

// Scanner object to read string from user input

Scanner scanner = new Scanner(System.in);

System.out.print("Enter String here : ");

input=scanner.next();

// calling backward method to reverse passed string

backward(input);

// closing Scanner object

scanner.close();

}

// Method to Reverse the input string

private static void backward(String source) {

int i, len = source.length();

StringBuilder dest = new StringBuilder(len);

for (i = (len - 1); i >= 0; i--){

dest.append(source.charAt(i));

}

System.out.println("Reversed String : "+dest);

}

}

The program above accepts a String object as an argument and displays its contents backward.

It reverses the any string inputed while producing the output.

6 0
2 years ago
If I execute the expression x &lt;- 4L in R, what is the class of the object `x' as determined by the `class()' function?
FinnZ [79.3K]

Answer:

integer

Explanation:

The expression can be implemented as follows:

x <- 4L

class(x)

Here x is the object. When this expression is executed in R, the class "integer" of object 'x' is determined by the class() function. R objects for example x in this example have a class attribute determines the names of the classes from which the object inherits. The output of the above expression is:

"integer"

Here function class prints the vector of names of class i.e. integer that x inherits from. In order to declare an integer, L suffix is appended to it. Basically integer is a subset of numeric. If L suffix is not appended then x<-4 gives the output "numeric". Integers in R are identified by the suffix L while all other numbers are of class numeric independent of their value.

7 0
2 years ago
Terry came into work and turned on his computer. During the boot process, the computer shut down. When he tried again, the compu
Svetllana [295]

Answer:

SATA Cable

Explanation:

SATA (Serial Advanced Technology Attachment) Cable is a connection made between Computer hard drives and the motherboard. When a computer gives an error on startup that OS not found, there's a possibility that the drive containing the OS is not well connected to the motherboard. Making sure it is well connected to the motherboard will possibly fix the issue.

6 0
2 years ago
Other questions:
  • Which of the following is not a benefit of active listening?
    8·1 answer
  • You are given an array x of string elements along with an int variable n that contains the number of elements in the array. You
    11·1 answer
  • Find a 95% confidence interval for the mean failure pressure for this type of roof panel.The article "Wind-Uplift Capacity of Re
    7·1 answer
  • A contact list is a place where you can store a specific contact with other associated information such as a phone number, email
    9·1 answer
  • An attacker distributes hostile content on Internet-accessible Web sites that exploit unpatched and improperly secured client so
    11·2 answers
  • You realize your computer has been infected with malware. It seems as if someone is controlling your computer from a remote loca
    5·1 answer
  • 1. Discuss why it is so important for all application builders to always check data received from unknown sources, such as Web a
    12·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • Write an expression that continues to bid until the user enters 'n'.
    9·1 answer
  • Which of the following statements is true regarding input and output?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!