1answer.
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
sleet_krkn [62]
3 years ago
8

Write a C++ program to define an abstract class in polymorphism?

Computers and Technology
1 answer:
statuscvo [17]3 years ago
7 0

Answer:

Following are the program to this question:

#include <iostream>//header file

using namespace std;//namespace

class Val //defining abstract class

{

  public://use access specifier

     virtual int squ()=0;//declaring a method squ  

     void setval(int x) //defining a method setval

     {

        a=x;//holding value in a variable

     }

  protected://use access specifier

     int a;//defining integer variable

};

class square: public Val //defining a class square that inherit abstract class

{

  public://use access specifier

   int squ() //defining squ method

   {  

   return (a*a); //return square value

   }

};

int main() //main method

{

 square s;//creating class object

 s.setval(5);//calling setval method

 cout << "The square value is: " << s.squ() << endl;//print value by calling squ method

}

Output:

The square value is: 25

Explanation:

In the above code a two-class "Val and square" is declared, in which val is abstract class, in a method squ is declared, and setval is used to set the value.

In the next step, the square class inherits Val and defines the squ method, and uses the return keyword to return its calculated value.

In the main method square class object is created and set the setval value and call the squ method and print its value.    

You might be interested in
The ---------------initiates a message by encoding theidea (or a thought) in words or symbols and sends it to areceiver.ChannelS
saw5 [17]

Answer:

None of the given options

Explanation:

The sender initiates a message by encoding theidea (or a thought) in words or symbols and sends it to a receiver.

8 0
3 years ago
(100 points ASAP PLease) Type the correct answer in the box. Spell all words correctly.
Katena32 [7]

Answer:

Maria can ensure that the video is recording correctly by checking the _____. 1. See answer.

8 0
2 years ago
Which of the following is an example of a logic error?
rusak2 [61]

Answer:

Receiving unexpected results from a program

Explanation:

Logic errors are due to the program not producing a desired result.

6 0
3 years ago
Read 2 more answers
A software program that includes tools for entering, editing, and formatting text and graphics is called a word processing progr
shtirl [24]

i think the answer is true

7 0
3 years ago
Which process refers to starting up a computer
lisabon 2012 [21]
The process is called booting
4 0
4 years ago
Read 2 more answers
Other questions:
  • Identify a major drawback of browsing web pages on mobile devices.
    15·1 answer
  • What is the opportunity cost of computers when moving from point A to point B? -15 DVDs b. What is the opportunity cost of compu
    13·1 answer
  • Consider the relation Courses(C, T, H, R, S, G), whose attributes can be thought of informally as course (C), teacher (T), hour
    10·1 answer
  • And there you go <br> sorry its saying my thing is tooo small
    14·2 answers
  • Why did artists use pinhole cameras during the renaissance?
    8·1 answer
  • Which technology is predominately used for contactless payment systems?
    11·1 answer
  • Wireless networks use radio frequency (RF) or radio techniques, which allows wireless transmissions to reach out in all directio
    6·1 answer
  • What constructs break or bend the normal Syntax patterns of scheme?
    15·1 answer
  • Write a paragraph about ICT in personal life?
    12·1 answer
  • I need help NOW with my java script!! 1. What will the code below output to the console and why? const person = {
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!