Add a Friend function to the Mutualfund class. Design the friend function so that it sets, retrieves, and prints all of the MutualFund Class's private data members. Also, rewrite the main() function so that instead of setting, retrieving, and printing the private data members directly, it passes to the friend function a pointer to a MutualFund object...
Code:
// E6.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
class MutualFund{
public:
void setNumberOfShares(int num){
iNumberOfShares = num;
}
void setAnnualYield(double yield){
dAnnualYield = yield;
}
int getNumberOfShares(){
cout<<iNumberOfShares<<endl;
return 0;
}
double getAnnualYield(){
cout<<dAnnualYield<<endl;
return 0;
}
private:
int iNumberOfShares;
double dAnnualYield;
};
int main(int argc, char* argv[])
{
MutualFund m;
int share, yield;
cout<<"Enter number of shares: ";
cin>>share;
cout<<"Enter the Annual yield: ";
cin>>yield;
m.setNumberOfShares (share);
m.setAnnualYield (yield);
cout<<"\nNumber of share will be ";
m.getNumberOfShares ();
cout<<"Annual yield will be: ";
m.getAnnualYield ();
cout<<endl;
return 0;
}
Alright, making the friend function is np
Code:
void Friend()
{
cout << "Please enter Shares: " << endl;
cin >> iNumberOfShares; cout << endl;
cout << "Please enter the annual yield: " << endl;
cin >> dAnnualYield; cout << endl;
cout << iNumberOfShares << endl;
cout << dAnnualYield << endl;
}
but wtf about the other part?