Find the Size of a Class and object in C++



Write a Program to find the Size of a Class
and object.





#include <iostream.h>


#include <conio.h>





 class
SI


  {


  
public:


   
double p,t,r;


   
void interest(double,double,double);


  };





 inline
void SI :: interest(double a, double b, double c)


   {


   
double i,sum;


   
p=a;


   
t=b;


   
r=c;


   
i=(p*t*r)/100;


   
sum=p+i;


   
cout<<"\nThe Interest is: "<<i;


   
cout<<"\nThe Sum is: "<<sum;





   }





 int
main()


  {


 
double principal,time,rate;


 
clrscr();


 
cout<<"Principal: ";


 
cin>>principal;


 
cout<<"Time: ";


 
cin>>time;


 
cout<<"Rate: ";


 
cin>>rate;


  SI
ob;


 
ob.interest(principal,time,rate);


 
cout<<"\nSize of Class: "<<sizeof(SI);


 
cout<<"\nSize of Object: "<<sizeof(ob);


 
getch();


 
return 0;


  }





Output:





Principal: 5000


Time:10


Rate: 10


The Interest is: 5000


The Sum is: 10000


Size of Class: 24


Size of Object: 24










Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C