Thread: C++ Problem, I'm such a noob :d

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    C++ Problem, I'm such a noob :d

    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?

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    alright, alright, i'm stupid

    *figures out there is a friend keyword*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is the problem here? (noob question)
    By p_m63 in forum C++ Programming
    Replies: 9
    Last Post: 07-10-2006, 02:50 AM
  2. Noob problem - function call
    By Ultraman in forum C++ Programming
    Replies: 4
    Last Post: 05-20-2006, 02:28 AM
  3. Noob problem with "for" statement
    By Ultraman in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2006, 09:26 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. total noob with a problem
    By dwainpipe in forum C++ Programming
    Replies: 5
    Last Post: 03-07-2006, 07:48 AM