Object Oriented Programming Practical 9
Question 1
Write a Program to declare a class birthday having data member day, month and year. Accept this info for object using pointer to array of object and display it.
birthday.cpp
C
#include<iostream.h>
#include<conio.h>
class Birthday
{
private:
int day,month,year;
public:
void accept()
{
cout << "Enter day: ";
cin >> day;
cout << "Enter month: ";
cin >> month;
cout << "Enter year: ";
cin >> year;
}
void display()
{
cout << "Birthday: " << day << "/" << month << "/" << year << endl;
}
};
int main()
{
Birthday b[5];
Birthday *bptr;
bptr=&b[0];
int n=5;
for (int i = 0; i < 5; i++)
{
cout << "\nEnter details for birthday " << i + 1 << ":" << endl;
bptr->accept();
bptr++;
}
bptr=&b[0];
cout << "\nDisplaying all birthdays:" << endl;
for (int i = 0; i < 5; i++)
{
cout << "Birthday " << i + 1 << ": ";
bptr->display();
bptr++;
}
getch();
return 0;
}
Output

Question 2
Write a C++ program to declare class ‘Account’ having data members as Account_No and Balance. Accept this data for 10 accounts and display data of Accounts having balance greater than 10000.
account.cpp
C
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Account
{
public:
int acno;
float balance;
void accept()
{
cout<<"\nEnter acno ";
cin>>acno;
cout<<"Enter balance ";
cin>>balance;
}
void display()
{
cout<<"\nAccount no is: "<<acno<<endl;
cout<<"Balance is: "<<balance<<endl;
}
};
int main()
{
clrscr();
int i;
Account a[5];
cout<<"\nEnter account details:"<<endl;
for(i=0;i<5;i++)
a[i].accept();
cout<<"\nAccounts with balance more than 10000 are: "<<endl;
for(i=0;i<5;i++)
{
if(a[i].balance>10000)
a[i].display();
}
getch();
return 0;
}
Output
