class and variable declaration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<iostream>
#include<conio.h>
#include<string>

using namespace std;
class ir;
class Bank_acc
{
	private:
       string name,type,s;
       long int accno,temp,balance,in;

       public:
       void putdata()
       {
		cout << "Enter Name of account holder: ";
		cin >> name;
		cout <<endl<< "Enter account number: ";
		cin >> accno;
		cout <<endl<< "Is the account a savings account or a current account? (s/c): "<<endl;
        cin >> s;
		if(s=="s")
		 type="savings";

		if(s=="c")
		type="current";
		cout<<"Enter Your balance amount: ";
		cin>>balance;
	}

	void dispdata()
	{
		cout<<"Account holder name: "<<name<<endl;
		cout<<"Account number: "<<accno<<endl;
		cout<<"Account type: "<<type<<endl;
		cout<<"Balance amount: "<<balance<<endl;
	}

	void deposit()
	{
		cout<<"Enter the amount you want to deposit:";
		cin>>temp;
		balance=balance+temp;
		cout<<endl<<"Your new balance is: "<<balance<<endl;
	}

	void withdraw()
	{
		cout<<"Enter the amount you want to withdaw: ";
		cin>>temp;
		balance=balance-temp;
		cout<<endl<<"Your new balance is: "<<balance<<endl;
	}
    friend void ir::interest();
};

class ir
{
    public:
    void interest(long int balance)
{
    long int t;
    t=0.05*balance;
    cout<<"Principle amount: "<<balance<<endl;
    cout<<"Interest earned: "<<t<<endl;
    cout<<"Total amount: "<<t+balance<<endl;
}

};

int main()
{
    int t;
    char q;
	ir rate;
	Bank_acc acc;
	cout<<"Enter account details: "<<endl;
	acc.putdata();
	cout<<endl;
	do
    {
	cout<<"what do you want to do?"<<endl<<"1. Display account details"<<endl<<"2. Deposit amount"<<endl<<"3. Withdraw amount"<<endl<<"4. Calculate interest"<<endl;
	cin>>t;
	switch(t)
    {
        case 1:
        acc.dispdata();
        break;

        case 2:
        acc.deposit();
        break;

        case 3:
        acc.withdraw();
        break;

        case 4:
        rate.interest();

        default:
        cout<<"Invalid entry";

    }
    cout<<"Do You want to continue?(y/n)"<<endl;
    cin>>q;
    }while(q=='y');
}



errors are:
|6|error: forward declaration of 'class ir'|
|54|error: invalid use of incomplete type 'class ir'|
|99|error: no matching function for call to 'ir::interest()'|


PLEASE help me. I'really stuck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<iostream>
//#include<conio.h>
#include<string>
#include <cmath> // *** added

using namespace std;

////// **** definition of ir moved to the top **** /////////////////
class ir
{
    public:
    void interest( long int balance )
    {
        // long int t;
        // t = 0.05*balance;
        const long t = std::lround( 0.05 * balance ) ; // *** modified

        cout << "Principle amount: " << balance << endl;
        cout << "Interest earned: " << t << endl;
        cout << "Total amount: " << t + balance << endl;
    }

};

class Bank_acc
{
    private:
    string name, type, s;
    long int accno, temp, balance, in;

    public:

    ////// **** added **** /////
    long balance_amount() const { return balance ;  }
    ///////////////////////////

    void putdata( )
    {
        cout << "Enter Name of account holder: ";
        cin >> name;
        cout << endl << "Enter account number: ";
        cin >> accno;
        cout << endl << "Is the account a savings account or a current account? (s/c): " << endl;
        cin >> s;
        if( s == "s" )
            type = "savings";

        if( s == "c" )
            type = "current";
        cout << "Enter Your balance amount: ";
        cin >> balance;
    }

    void dispdata( ) const // *** const added
    {
        cout << "Account holder name: " << name << endl;
        cout << "Account number: " << accno << endl;
        cout << "Account type: " << type << endl;
        cout << "Balance amount: " << balance << endl;
    }

    void deposit( )
    {
        cout << "Enter the amount you want to deposit:";
        cin >> temp;
        balance = balance + temp;
        cout << endl << "Your new balance is: " << balance << endl;
    }

    void withdraw( )
    {
        cout << "Enter the amount you want to withdaw: ";
        cin >> temp;
        balance = balance - temp;
        cout << endl << "Your new balance is: " << balance << endl;
    }
    
    // friend void ir::interest( );
    friend void ir::interest( long int ); // *** modified
};


int main( )
{
    int t;
    char q;
    ir rate;
    Bank_acc acc;
    cout << "Enter account details: " << endl;
    acc.putdata( );
    cout << endl;
    do
    {
        cout << "what do you want to do?\n1. Display account details\n"
             << "2. Deposit amount\n3. Withdraw amount\n4. Calculate interest\n" ;
        cin >> t;
        switch( t )
        {
            case 1:
                acc.dispdata( );
                break;

            case 2:
                acc.deposit( );
                break;

            case 3:
                acc.withdraw( );
                break;

            case 4:
                // rate.interest( );
                rate.interest( acc.balance_amount() ) ; // *** modified

            default:
                cout << "Invalid entry";

        }
        cout << "Do You want to continue?(y/n)" << endl;
        cin >> q;
    } while( q == 'y' );
}
Last edited on
Topic archived. No new replies allowed.