Program to illustrate Pointer A Simple Constructor


#include <iostream.h>
#include <string.h>
#include<conio.h>
class sample
{
    char itemname[20];
    int cost;
    public :
    sample();                // Constructor declaration
    void print_data();
};
sample::sample()                // Constructor definition
{
    strcpy(itemname,"Pencil");
    cost = 5;
}
void sample::print_data()
{
    cout << "Item : " << itemname << "\n";
    cout << "Cost : " << cost << "\n";
}
void main(void)
{
    clrscr();
    sample A;
    A.print_data();
    getch();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|