Customer Account: C++ Program Friend Function
Problem Statement : Perform the following tasks on the classes:
a) Write the constructor function for both classes to initialize the values of the private variables.
b) Write a function, outside of either class, that prints private data members from both objects.
This function should print the name, ytd_balance and c_num from person, and the acct_code and ac_balance from ledger.
Make this function a friend of each class.
HINT: You will need to pass parameters of type Account and Customer to the function.
c) Add a call to this function in the main procedure.
d) Run the program.
#include<iostream>
#include<cstring>
using namespace std;
class Account;
class Customer
{
char name[30];
int c_num;
float ytd_balance;
public:
Customer()
{
strcpy(name,"Pratik");
c_num = 123;
ytd_balance = 1000;
}
friend void display(Customer , Account );
};
class Account
{
char acc_code[5];
float acc_balance;
public:
Account()
{
strcpy(acc_code,"AC123");
acc_balance = 20000;
}
friend void display(Customer , Account );
};
void display(Customer c, Account a)
{
cout<<"\nName of the Account Holder : "<<c.name<<endl;
cout<<"\nCustomer Number is : "<<c.c_num<<endl;
cout<<"\nMinimum balance for Customer is : "<<c.ytd_balance<<endl;
cout<<"\nThe Account code is : "<<a.acc_code<<endl;
cout<<"\nThe Account balance is : "<<a.acc_balance<<endl;
}
int main()
{
Customer c;
Account a;
display(c,a);
return 0;
}
#COFPROG
Sign up here with your email
ConversionConversion EmoticonEmoticon