PDA

View Full Version : question adout c++ 2011



saneha
05-02-2011, 04:51 PM
1: how data and functions are not tightly bound with each other in procedral laguagess. plz give me a solid example.

2: in example char *name how we can store name within it. plz give example

3: when the object will be destroyed.

4:can we use cin function to give values to class data

Vuhelper
05-02-2011, 04:53 PM
1. Data and functions are not tightly bound in procedural programming because data and functions are independent of each other. Data and functions are stored in separate locations of memory. While in object oriented programming, data and member functions are stored in same memory location. And we can access functions through its appropriate object.
For example:
int sum(int a, int b) {
int c;
c = a + b;
return c;
}
int main() {
int var1, var2;
var1=sum(10,20);
var2=sum(30,40);
}
Here var1 is data, through which we access the sum function. And var2 is another data, through which we access sum function also. While in object oriented we can access only member functions of a class through its object.
class student{
int rollNo;
char * name;
public:
void myFunc(){
cout<<”Welcome to my function”;
}
};
class teacher{
int id;
char * name;
public:
void information(){
cout<<”Welcome to teacher function”;
}
};
int main() {
student obj;
teacher tech;
obj.myFunc();
tech.myFunc(); //we can not access myFunc function through tech object.
}
So in object oriented programming data and its functions are tightly bound, while in procedural programming data and functions are not tightly bound.
2. char * name;
name= “ali”;
So Ali is saved in memory location which is labeled as name. Instead of Ali any name can be used.

3. When scope of object ends or when the program terminates, the object will destroy.
4. Yes we can use cin statement in class body to give values to class data.