Object based programming in C++

In summary: You need to know its implementation: sin() actually calculates the sine of a number using trigonometry. This is a complex mathematical operation, and it needs to be implemented in a specific way on your computer. sin()'s prototype includes the information needed to find the implementation:double sin (double x); // sin() implements a double-precision sin() function.If you want to use sin() to calculate the sine of a number x, you can call sin() like this:double sin (double x); // sin() calculates the sine of x.In other words, sin() 's
  • #1
kartikwat
49
0
What does object based programming mean?how does it localises the implementation details ,i tried to read it from book but i dint got it.
 
Technology news on Phys.org
  • #4
kartikwat said:
What does object based programming mean?

In short, object-based programming is when you are being object-oriented in a language that not necessarily has no direct support of objects, i.e. mechanisms like encapsulation, inheritance, polymorphism and so on. In those languages you have to manually program these mechanisms in if you want them and the language has no native support for it. For instance, in Javascript you can use function instances to act as objects, and in C you can use structs and function pointers. Depending on the language it may not be an easy thing to do.


kartikwat said:
how does it localises the implementation details ,i tried to read it from book but i dint got it.

It strongly depends on the language in question, so your question can only be answered in very general terms. Do you have a specific language in mind? And which book are you referring to?
 
  • #5
Filip Larsen said:
In short, object-based programming is when you are being object-oriented in a language that not necessarily has no direct support of objects, i.e. mechanisms like encapsulation, inheritance, polymorphism and so on. In those languages you have to manually program these mechanisms in if you want them and the language has no native support for it. For instance, in Javascript you can use function instances to act as objects, and in C you can use structs and function pointers. Depending on the language it may not be an easy thing to do.

It strongly depends on the language in question, so your question can only be answered in very general terms. Do you have a specific language in mind? And which book are you referring to?

I refer to sumita arora class 12 book.do you have any suggestion
 
  • #6
kartikwat said:
I refer to sumita arora class 12 book.

Most people who answer questions on PF are not from India, so we have no idea what is in that book.
 
  • #7
kartikwat said:
I refer to sumita arora class 12 book.

Can you give us a short quotation from the book and tell us what, specifically, you don't understand about it?

(Assuming the book is in English.)
 
Last edited:
  • #8
Filip Larsen said:
In short, object-based programming is when you are being object-oriented in a language that not necessarily has no direct support of objects ...

It strongly depends on the language in question, so your question can only be answered in very general terms. Do you have a specific language in mind?

The thread title says "Object based programming in C++".

It would be strange to re-invent a different way of doing object based programming in C++ that did not use the object oriented features that are already in the language - certainly at high-school level ( which is what I guess the OP's "class 12" refers to).
 
  • #9
This seemed like a very good explanation to me.

http://www.stroustrup.com/whatis.pdf

That has been revised from what he published in IEEE Software a few years earlier. The earlier version ended each section with a list of problems that that style of programming did not handle well and was thus the reason for the invention of the next newer style. The article finally ended with a list of problems that object oriented programming did not handle well and which he said someone would find a solution to within the next decade. I always wondered if that advance was found and what it turned out to be.
 
  • #10
Object based programming

Are there any tutorial on computer science which can guide ne on my class 12 computer science course
 
  • #11
Hey this is explanation of object based programming .i can't get what it means.
 

Attachments

  • kartikwat1.jpg
    kartikwat1.jpg
    41 KB · Views: 398
  • kartikwat2.jpg
    kartikwat2.jpg
    45.5 KB · Views: 403
Last edited by a moderator:
  • #12
AlephZero said:
The thread title says "Object based programming in C++".

It certainly does and I somehow managed to miss that completely. :redface: I hereby retract my question about which language the OP is thinking of :tongue:
 
  • #13
kartikwat said:
i can't get what it means.

Start at the top of the first page. Tell us where you first get "stuck."
 
  • #14
Object based programming

jtbell said:
Start at the top of the first page. Tell us where you first get "stuck."

In the first page I was not able to understand
1) "classes enforce inforce information hiding and abstraction and there by seperating implementation details"
2)in the point"OBP localises implementation details"I didnt got
a)which definition type is changed
b)what is user interface
c)as a whole what does point mean.
 
  • #15
To see what "separating implementation details" is all about, first consider a simple function: the sin() function which is available to you when you '#include <cmath>'. In order to use sin() properly, you need to know two things:

1. You need to know its interface: you need to give it a number as its parameter, and it returns a number as the function result. This is often specified by the function's prototype:

double sin (double x);

'double sin' indicates that it returns a double-precision floating point number as its result, and 'double x' indicates that it receives a double-precision floating point number as its parameter. Actually, it's more complicated in this case, because sin() can deal with single-precision floating point ('float'), double-precision floating point ('double'), and I think also complex ('complex') numbers. But this simplified version at least gives you the idea of what the prototype specifies.

2. You need to know what the function "does", its specification, which is usually given by a verbal description. For sin() it might be something like "returns the sine of the angle given by the parameter, which must be in radians."

You do not need to know how the function calculates the sine: a series expansion of some kind, or by looking it up in a table, or whatever. This is an "implementation detail" which is "separated" from the knowledge of how to use the function.

A class contains both (member) functions and (member) data. The member functions are like ordinary functions as far as "separating implementation details" is concerned.

"Data abstraction" basically separates the details of the data contained in the class, from the things that you "do" with the class. Think of it as applying "separation of implementation details" to the class's member data. In practice this means that if your program uses the class, you can't use the class's member data directly; only indirectly by way of the member functions. This is "information hiding." The member data is "hidden" from "direct view" from the rest of your program.
 
Last edited:

What is object-based programming in C++?

Object-based programming in C++ is a programming paradigm that allows developers to create objects that have both data (attributes) and functions (methods). These objects can interact with one another, making it easier to write complex programs.

What is the difference between object-based and object-oriented programming in C++?

Object-based programming in C++ is a simpler version of object-oriented programming. In object-based programming, objects have attributes and methods, but they cannot inherit from other objects. In contrast, object-oriented programming allows objects to inherit from other objects, creating a hierarchy of classes.

How do you create an object in C++?

To create an object in C++, you first need to define a class. A class is like a blueprint for an object, specifying its attributes and methods. Once you have a class, you can use the "new" keyword to create an instance of the class, also known as an object.

What are the advantages of using object-based programming in C++?

Object-based programming in C++ allows for code reusability, making it easier to maintain and update programs. It also allows for encapsulation, which means that the data and methods of an object are contained within the object, making it more secure. Additionally, object-based programming can make code more organized and easier to understand.

Can you give an example of object-based programming in C++?

One example of object-based programming in C++ is creating a "Person" class with attributes such as name, age, and occupation, and methods such as "introduce" and "work." Then, you can create multiple instances of this class, each representing a different person with their own unique attributes and methods.

Similar threads

  • Programming and Computer Science
Replies
4
Views
602
  • Programming and Computer Science
Replies
2
Views
1K
Replies
65
Views
3K
  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
1
Views
242
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
2
Replies
49
Views
3K
Back
Top