Write a program using a friend function, C/C++ Programming

Assignment Help:

Using a Friend

Using a friend function is quite easy. The following example explains a friend function to access members of two classes.

class Bclass;                                                        // Forward Declaration

class Aclass

 {

  public :

                                Aclass(int v)

                                 {

                                                Avar = v;

                                 }

 

friend int addup(Aclass &ac, Bclass &bc);

  private :

                                int Avar;

 };

class Bclass

 {

  public :

                                Bclass(int v)

                                 {

                                                Bvar = v;

                                 }

 

                                friend int addup(Aclass &ac, Bclass &bc);

  private :

int Bvar;

 

 };

int addup(Aclass &ac, Bclass &bc)

 {

                return( ac.Avar + bc.Bvar);

 }

void main()

 {

  Aclass aobj;

  Bclass bobj;

                  int total;

                                total = addup(aobj,bobj);

                 }

 


Related Discussions:- Write a program using a friend function

Program to calculate gross pay and tax payable, Study the following table u...

Study the following table used to compute the tax payable by employees in certain organization   Gross Pay                                  Fewer than Three             Three

Decoding smugglers message, Smugglers are becoming very smart day by day. N...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Flight Departure in C, I really have a hard time analyzing how to write a c...

I really have a hard time analyzing how to write a code in C. It''s all bout Time Departure and we must used a 24 hour clock. Can u help me?

Operations on strings, 1 Aims The main purpose of the assignment is to ...

1 Aims The main purpose of the assignment is to let you practice the following programming techniques: perform operations on pointers to basic and more complex types;

C++ Assignment Help me , Write a c++ program that contain the following fun...

Write a c++ program that contain the following functions : 1) Function Quality_Point that takes one int argument (student_average) and return ‘A’ if the student_average between 90-

Menus, create a shopping cart in c++

create a shopping cart in c++

Define the assignment operators in c language, Define the Assignment Operat...

Define the Assignment Operators in c language? The assignment operators can be used to assign a value to the variable and is represented by equal to (=) sign. The Assignment ex

Program to list the cities and their states, The program will ask the user ...

The program will ask the user to enter: '1' to List the cities(and their state abbrev)  from largest to smallest (by their population) with their population '2'  to List the

Radix sort - c program, Radix sort - C program: Write a program in c t...

Radix sort - C program: Write a program in c to define a radix sort. void main() {  int array[100],n;  int i;  void radix(int *,int);  printf ("How many nos\

Object oriented programming and cryptography, This assignment document will...

This assignment document will be distributed from Blackboard assignment folder. Some parts of the assignments will require you to research answers from your text book (you must rea

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd