Slip 10 - A) Write a C++ program to create a class Account with data members Acc_number, Acc_type and Balance. Write member functions to accept and display ‘n’ account details. (Use dynamic memoryallocation).

 Solution:

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

 class Account

{

public:

int Acc_no,Balance;

char Acc_type[30];

public:

Account()  {  cout << "Constructor" << endl; }

~Account() { cout << "Destructor" << endl; }

void get_data()

{

cout<<"\n Enter Acc_no.:";

cin>>Acc_no;

cout<<"\n Enter Acc_type :";

cin>>Acc_type;

cout<<"\n Enter Balance :";

cin>>Balance;                    

}

void display_data()

{

cout<<"\t"<<Acc_no<<"\t"<<"\t"<<Acc_type<<"\t"<<Balance;      

}

};

int main()

{

 clrscr();

int num;

 Account* a = new Account[4];

delete [] a; // Delete array

 cout<<"\n How many records u want?: ";

cin>>num;

 for(int i=0;i<num;i++)

{

a[i].get_data();

}

for(i=0;i<num;i++)

{

a[i].display_data();

}

return 0;

 }

Post a Comment

0 Comments