Account program,files are separated, using class, and exception handling

I having a error, the program is not able to run. I'm using Xcode. the error say " linker command failed with exit code 1 (use -v to see invocation)". At first I went online to try to find what it means, it said that I might have a duplicated definition of something that is not in their right files. Thank you in advance at looking at the code. it is in different files and it is separated by /*-----------------*/. Thank you.

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
#ifndef account_hpp
#define account_hpp

#include <stdio.h>

class Account{

public:
    Account(){
     balance=0;
    }
    
    Account(double initialDeposit){
        balance=initialDeposit;
    }
    
    double getBalance();
    double deposit(double amount);
    double withdraw(double amount);
private: double balance;
    
};


#endif

/*------------------*/


#include <stdio.h>
#include <iostream>
#include "account.hpp"

double Account::deposit( double amount){
    
    if (amount > 0)
    balance += amount;
    else return -1;
    
    return balance;
    
}
/*------------------*/
#include <stdio.h>
#include <iostream>
#include "account.hpp"

double Account::withdraw(double amount){
    
    if ((amount>balance) || (amount < 0))
    return -1;
    else balance -= amount;
    
    return balance;
   
}
/*------------------*/

#include <iostream>
#include "account.hpp"
#include "account.cpp"
#include "accountWithdraw.cpp"
using namespace std;

int main( ) {
    int x, withDra, dePosite;
   
    
    Account b;
   
    try {
        cout<< "checking the value of withdraw and deposite";
        
        dePosite = b.deposit(x);
        withDra= b.withdraw(x);
        
        if (dePosite <= -1) {
            throw dePosite;
            
        }
        if (withDra <= -1) {
            throw withDra;
        }
        
    }
    catch ( double &x  ) {
        cout<< "invalid, error program exit: ";
        exit(0);
    }
    
    
    
    
    return 0;
    
}

I've looking at the code for sometime, couldn't figure out what is the problem
with it. And thanks again.
Last edited on
In your main cpp file, you don't want to include the class cpp files (lines 61 and 62), just the hpp header file.

You can define all the class functions declared in the hpp header file in a single class cpp file - it looks like you have separate files for the deposit and withdraw class functions.
Thank you so much, is working now.
Topic archived. No new replies allowed.