SlideShare a Scribd company logo
1 of 3
Download to read offline
C++ cOMPLETE CODE .. PLEASE DO WITH CORRECT OUTPUT FOR THUMBSUP
#include
usingnamespace std;
/**
*
* 1. Write a class Shape, which will have a public function draw(). The draw() function returns
no data and output "Drawing a shape."
*
* 2. Write a class Circle, which is a derived class of Shape class. It only has the public draw()
function overriding from Shape class.
* Use normal function overriding (without using virtual keyword in the base class function)
*
* (this will perform Function Hiding, which means if we have a derived type pointer pointing
to the derived object,
* the based class method is hidden by the derived class method, and the compiler will call the
derived class on because it
* does not see the one in the base class.)
*
* (However, if you use a pointer of the base class type, even if you are pointing to the derived
object,
* because you are using the baseClassTypePointer->function(), this will not hide the function
in the base,
* so in this case, the base class one will be called)
*
* 3. Write a class Animal, which will have a public function makeSound(). This makeSound()
function is a virtual function, which
* means it is designed to be overriden if it is called from the derived class objects. It returns no
data, and output the
* message "The animal makes a sound."
*
* 4-1. Write a class Bird, which is a derived class of Animal class. It only has the public
makeSound() function overriding from Animal
* class. Because we have already define the makeSound() function in the base class Animal as
a virtual function, so if we have a
* Bird class object to call makeSound(), it will always override the makeSound() in the base
class and run this one instead.
*
* 4-2. Write a class Dog, which is a derived class of Animal class. It only has the public
makeSound() function overriding from Animal
* class. Because we have already define the makeSound() function in the base class Animal as
a virtual function, so if we have a
* Dog class object to call makeSound(), it will always override the makeSound() in the base
class and run this one instead.
*
* (For a virtual function, the compiler will always call the most derived version of the method
that is appropriate for the object,
* if the object is of a derived type object, then the derived type class function will always
override the base class function)
*
* (So in this exercise, if we call from Animal class, as it is the base class itself, there is nothing
to override. But for the
* Bird type object, it always calls the Bird class definition makeSound(), and for the Dog type
object, it always calls the
* Dog class definition makeSound())
*
*/
int main() {
Shape* s = new Circle();
Circle* c = new Circle();
s->draw(); // calls Shape::draw() because it is not virtual, it is not based on the derived object
type, this case does not trigger Function Hiding
c->draw(); // calls Circle::draw() because it overrides Shape::draw() (Function Hiding)
Animal* a = new Animal();
Bird* b = new Bird();
Dog* d = new Dog();
a->makeSound(); // Animal::makeSound() because nothing to override
b->makeSound(); // Bird::makeSound() because virtual function always gets overriden by the
derived definition appropriate for the type object
d->makeSound(); // Dog::makeSound() because virtual function always gets overriden by the
derived definition appropriate for the type object
return 0;
}
Correct Output of the Program:

More Related Content

Similar to C++ cOMPLETE CODE .. PLEASE DO WITH CORRECT OUTPUT FOR THUMBSUP#in.pdf

please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
aggarwalopticalsco
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
aioils
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf
forwardcom41
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdf
archiesgallery
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 

Similar to C++ cOMPLETE CODE .. PLEASE DO WITH CORRECT OUTPUT FOR THUMBSUP#in.pdf (20)

Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Overloading
OverloadingOverloading
Overloading
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdf
 
Java2
Java2Java2
Java2
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 

More from info189835

Can someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdfCan someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdf
info189835
 
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdfCada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
info189835
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
info189835
 

More from info189835 (20)

Can someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdfCan someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdf
 
can someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdfcan someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdf
 
can someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdfcan someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdf
 
Can someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdfCan someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdf
 
can someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdfcan someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdf
 
Can anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdfCan anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdf
 
can anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdfcan anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdf
 
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdfCambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
 
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdfCalifornia condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
 
California continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdfCalifornia continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdf
 
Calculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdfCalculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdf
 
calculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdfcalculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdf
 
Calculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdfCalculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdf
 
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdfCalculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
 
Calculate the of total (portfolio weight) for eachStock A pr.pdf
Calculate the  of total (portfolio weight) for eachStock A pr.pdfCalculate the  of total (portfolio weight) for eachStock A pr.pdf
Calculate the of total (portfolio weight) for eachStock A pr.pdf
 
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdfCalculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
 
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdfCada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
 
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdfCada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
 
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdfC coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

C++ cOMPLETE CODE .. PLEASE DO WITH CORRECT OUTPUT FOR THUMBSUP#in.pdf

  • 1. C++ cOMPLETE CODE .. PLEASE DO WITH CORRECT OUTPUT FOR THUMBSUP #include usingnamespace std; /** * * 1. Write a class Shape, which will have a public function draw(). The draw() function returns no data and output "Drawing a shape." * * 2. Write a class Circle, which is a derived class of Shape class. It only has the public draw() function overriding from Shape class. * Use normal function overriding (without using virtual keyword in the base class function) * * (this will perform Function Hiding, which means if we have a derived type pointer pointing to the derived object, * the based class method is hidden by the derived class method, and the compiler will call the derived class on because it * does not see the one in the base class.) * * (However, if you use a pointer of the base class type, even if you are pointing to the derived object, * because you are using the baseClassTypePointer->function(), this will not hide the function in the base, * so in this case, the base class one will be called) * * 3. Write a class Animal, which will have a public function makeSound(). This makeSound() function is a virtual function, which * means it is designed to be overriden if it is called from the derived class objects. It returns no data, and output the * message "The animal makes a sound." * * 4-1. Write a class Bird, which is a derived class of Animal class. It only has the public makeSound() function overriding from Animal * class. Because we have already define the makeSound() function in the base class Animal as a virtual function, so if we have a
  • 2. * Bird class object to call makeSound(), it will always override the makeSound() in the base class and run this one instead. * * 4-2. Write a class Dog, which is a derived class of Animal class. It only has the public makeSound() function overriding from Animal * class. Because we have already define the makeSound() function in the base class Animal as a virtual function, so if we have a * Dog class object to call makeSound(), it will always override the makeSound() in the base class and run this one instead. * * (For a virtual function, the compiler will always call the most derived version of the method that is appropriate for the object, * if the object is of a derived type object, then the derived type class function will always override the base class function) * * (So in this exercise, if we call from Animal class, as it is the base class itself, there is nothing to override. But for the * Bird type object, it always calls the Bird class definition makeSound(), and for the Dog type object, it always calls the * Dog class definition makeSound()) * */ int main() { Shape* s = new Circle(); Circle* c = new Circle(); s->draw(); // calls Shape::draw() because it is not virtual, it is not based on the derived object type, this case does not trigger Function Hiding c->draw(); // calls Circle::draw() because it overrides Shape::draw() (Function Hiding) Animal* a = new Animal(); Bird* b = new Bird(); Dog* d = new Dog();
  • 3. a->makeSound(); // Animal::makeSound() because nothing to override b->makeSound(); // Bird::makeSound() because virtual function always gets overriden by the derived definition appropriate for the type object d->makeSound(); // Dog::makeSound() because virtual function always gets overriden by the derived definition appropriate for the type object return 0; } Correct Output of the Program: