1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Conversion Operator Problem

Discussion in 'C' started by Peter_APIIT, Aug 5, 2007.

  1. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    Hello all expert C++ programmer, i truly new to C++ programming.

    I have a exercise where need to calculate the monthly interest with the balance supplied.

    Header File:

    Code:
    #pragma once
    
    class savingAccount
    {
    	static double annualInterestRate;
    	double balance;
    	double monthlyInterest;
    public:
    	savingAccount() : balance(0), monthlyInterest(0){}
    	explicit savingAccount(double balance, double monthlyInterest) 
    		:balance(balance), monthlyInterest(monthlyInterest){}
    	
    	void calMonthlyInterest();
        static void modifyInterestRate();
    
    	~savingAccount(){}
    };
    
    
    /* Static data member cannot initialized
       by constructor
    */
    
    
    
    
    Implementation File:



    Code:
    #include<iostream>
    #include<cstdlib>
    #include "Saving Account.h"
    
    using std::cout;
    using namespace std;
    
    double savingAccount::annualInterestRate = 0.05;
    
    int main(int argc, char *argv[])
    {
    	savingAccount peter(2000);
    	savingAccount nicholas_tse(3000);
        
    	peter.calMonthlyInterest();
    
    	return EXIT_SUCCESS;
    }
    // -----------------------------------------
    void savingAccount::calMonthlyInterest()
    {
    	monthlyInterest = (balance * annualInterestRate)/12;
    }
    // -----------------------------------------
    
    
    

    Error Message :

    I hope someone cna help me out.

    Thanks for your help.

    Your help is greatly appreciated by me and others.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    I cannot understand what you are trying to do. I don't see any one parameter constructor for your class savingAccount but your error suggest it has one with a const parameter. If thats the case convert your int parameter into const int
     
  3. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    I have set the one of the constructor explicit where to enhance one argument is been supplied.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    What is the signature of that constructor?
     
  5. it career

    it career New Member

    Joined:
    Apr 8, 2007
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Designing
    Home Page:
    What is the reason of having explicit constructor?
    Where is the defintion of constructor corresponding to
    Code:
    savingAccount peter(2000);
    
     
  6. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    No definition for Single argument constructor in ur program

    If u want a simple solution means
    add the following line to ur header file

    savingAccount(double balance):balance(balance){}


    so that u got an answer...........
     

Share This Page