Question

In: Computer Science

What are the object oriented concepts and which all object oriented concepts are used in the...

What are the object oriented concepts and which all object oriented concepts are used in the
given program? Consider the following code and explain how each of the object oriented
concepts are applied in the given program. (CO1)
class Vehicle
{
string brand;
public:
void honk();
void honk(int);
};
void Vehicle::honk()
{
cout << "Tuut, tuut! \n" ;
}
void Vehicle::honk(int x)
{
for(int i=0;i<x;i++)
cout << "Tuut, tuut! \n" ;
}
int main()
{
Vehicle V1;
V1.honk();
V1.honk(3);
}

Solutions

Expert Solution

The object-oriented concepts available in the given program are as follows:

  1. There is a clear case of inheritance. Here, Vehicle class is declared and inherited.
  2. There is also a close of method overloading, where honk() method is overloaded. A method is with an integer parameter and other is without any parameter.
  3. There are also concepts like Object creation. V1 is the object of the Vehicle class.

Please refer to the comments of the program for more clarity and understanding.

#include<bits/stdc++.h>
using namespace std;

/*
 Below we are creating the Vehicle class
*/
class Vehicle {
  string brand;
  /*
   Below is the condition of method overloading
   Here, honk() method is overloaded
   One method is with a integer parameter and other method is without any parameter
  */
  public: void honk();
  void honk(int);
};
void Vehicle::honk() {
    // Implementation of the honk() method without parameter
  cout << "Tuut, tuut! \n";
}
void Vehicle::honk(int x) {
    // Implementation of honk() method with a integer parameter

  // The below loop will run for x times(integer passed in the parameter)
  for (int i = 0; i < x; i++)
  cout << "Tuut, tuut! \n";
}
int main() {
  Vehicle V1;  // Creating instance of the Vehicle class.
               // Here V1 is the object of V1
  V1.honk();   // Calling the honk() method of Vehicle class
  V1.honk(3);  // Calling the honk(int) method of Vehicle class
}

Output of the above program:

Please let me know in the comments in case of any confusion. Also, please upvote if you like.


Related Solutions

What is different between procedural and object-oriented programming? Match each of the following OOP concepts with...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with its example/description. Question 2 options: 12345678 Providing a way for an entity to behave in several ways OR providing multiple entities to be treated in a similar way 12345678 A key way of saving having to retype a lot of code for similar but different objects 12345678 The removal of non-essential information 12345678 Allowing which function to be called by an object to be...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an...
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an explanation which of each part in it)
what is the essence of the object oriented analysis and design approach with UML diagramming tools
what is the essence of the object oriented analysis and design approach with UML diagramming tools
Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
Describe the types of hierarchy found in object-oriented systemdescriptions.
Describe the types of hierarchy found in object-oriented system descriptions.
Research and explain in your words what is known as Object Oriented Programming. Then, identify two...
Research and explain in your words what is known as Object Oriented Programming. Then, identify two advantages of OOP for application development. In peer replies, choose from one of the following and define the concept as part of your response. Abstraction. Encapsulation. Inheritance. Polymorphism.
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities....
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities. Group of answer choices A. True B. False 2. __________ programming is centered on the procedures or actions that take place in a program. Group of answer choices A. Class B. Object-oriented C. Menu-driven D. Procedural/ Structural 3. __________ programming encapsulates data and functions in an object. Group of answer choices A. Object-oriented B. Class C. Menu-driven D. Procedural 4. The data in an...
Use composition relationship. What is composition? You will find out what composition in object oriented programming....
Use composition relationship. What is composition? You will find out what composition in object oriented programming. Based on the bedroom package below please create your own classroom package. After completing entire package, you will write about your package specification in Readme.txt and also explain how you apply composition to your project. package Bedroom; public class Bedroom { private String name; private Wall wall1; private Wall wall2; private Wall wall3; private Wall wall4; private Ceiling ceiling; private Bed bed; private Lamp...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT