Conversion from a basic type to a class type may be
achieved using______________

Answer Posted / sujatha

Conversion from a basic type to a class type may be
achieved using SUITABLE CONSTRUCTORS IN CLASS.


EX:
class distance
{
int feet;
float inch;


public:

distance(float p) //costructor to concert basic type to
class type
{

feet= (int) p;
inch=(p-feet)*12;
}


void show()
{
cout<<"feet="<<feet;
cout<<"inch="<<inch;
}
};

void main()
{
distance d1=1.75;

d1.show();
}

out put

feet=1;
inch=9;

Is This Answer Correct ?    59 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is abstraction needed?

566


what is the 3 types of system development life cycle

2431


What are the benefits of interface?

577


Give two or more real cenario of virtual function and vertual object

1851


How do you answer polymorphism?

577






Write a program to reverse a string using recursive function?

1791


#include #include #include #include void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

3246


What is encapsulation process?

575


What is abstract class in oops?

598


What is inheritance in oop?

599


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

1656


How does polymorphism work?

635


when to use 'mutable' keyword and when to use 'const cast' in c++

1642


What is inheritance and how many types of inheritance?

616


Can enum be null?

585