I need help with a program please.

Hello fellow programers. I have written this program and I keep getting back a building error. The error reads as follows:

"Acct::Acct(char*, char, double)", referenced from:
_main in main.o
_main in main.o
_main in main.o
_main in main.o
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


If you know what is causing this please help me out! thanks guys/gals.







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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>

using namespace std;

class Acct
{
public:
	Acct(char[], char, double);           //constructor
    
	void printAccount();
	void changeBalance(double);
	
	void setAcctType(char);
	
	char getAcctType();
	double getBalance();
	
	void set_acctName(char []);
	void set_acctType(char );
	void set_acctBal(double);
	double newAcctBal;
	double newAcctType;
	
private:
	char name[50];
	char acctType;
	double balance;
	
};

void Acct::set_acctType( char newAcctType )
{
	if( newAcctType == 'C' || newAcctType == 'S' )
	{
		acctType = newAcctType;
	}
}
void Acct::set_acctBal( double newAcctBal )
{
	balance = newAcctBal;
}


int main()
{
	
	Acct account1 = Acct( "Doe, John", 'C', 113019.77 );
	Acct account2 = Acct( "Doe, Jane", 'S', 1234.50 );
	Acct account3 = Acct( "Temperance, Brennan", 's', 82.12 );
	Acct account4 = Acct( "Seeley, Booth", 'c', 3869.00 );
	Acct account5 = Acct( "Zach, Addy", 'C', 71940.76 );
	
	account1.printAccount();
	account1.changeBalance(939.39);
	account1.printAccount();
	
	account2.printAccount();
	account2.changeBalance(-240.00);
	account2.printAccount();
	
	account3.printAccount();
	account3.changeBalance(82000.12);
	account3.printAccount();
	
	account4.printAccount();
	account4.setAcctType('z');
	account4.changeBalance(43321.98);
	account4.getBalance();
	account4.printAccount();
	
	account5.printAccount();
	account5.changeBalance(-30);
	account5.changeBalance(369);
	account5.printAccount();
}

void Acct::printAccount()
{
	if (acctType == 'C' || acctType == 'c')
	{
		cout << "Name: " << name << "/t"<< "Checking Account Balance:  $"<< balance;
	}	
	else if (acctType == 'S' || acctType == 's')
	{	
		cout << "Name: " << name << "/t"<< "Savings Account Balance:  $"<< balance;
	}
	else
	{	
		cout << "Invalid account type";
	}
}

void Acct::changeBalance( double amountToChange )
{
	if (amountToChange > 0)
	{
		newAcctBal = balance + amountToChange;
	}
	else
	{
		newAcctBal = balance - amountToChange;
			if (balance <0)
			{
			cout << "Account overdrawn $10 fee added to account";
			newAcctBal = newAcctBal - 10;
			}
	}
}
void Acct::setAcctType(char)
{
	char choice;
	
	cout << "Enter the new account type";
	cin >> choice;
	if(choice == 'c' || choice == 'C')
	{
		cout << "The new account type is checking";
	}	
	else if (choice == 's' || choice == 'S')
	{
		cout << "The new account type is savings";
	}	
	else
	{	
		cout << "Invalid new account type";
	}	
}

char Acct::getAcctType()
{
	cout << "The Account type is: "<< acctType;
}

double Acct::getBalance()
{
	cout << "Account balance is: " << newAcctBal;
	
}
You're getting caught up in C++ treating expressions like this:

"Doe, John"

as a C++ string instead of a C string. (You might want to search google for an explanation of the differences.)

You can fix it with something like this:

1
2
3
4
5
int main()
{
	char cstring[80];
	strcpy(cstring, "Doe, John");
	Acct account1 = Acct( cstring, 'C', 113019.77 );


Though I'd recommend you look at moving away from character arrays in favor of C++ strings.

You're also missing a couple of return statements.
closed account (DSLq5Di1)
mzimmers wrote:
Though I'd recommend you look at moving away from character arrays in favor of C++ strings.
+1

Also, you haven't defined the constructor.
mzimmers (356),

I tried to implement what you were talking about but i have never really seen that format before. I am in a basic C++ class at my school so i don't even know if we are allowed to use C stuff. i tried it and ended up with:

int main()
{
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	char cstring1[80];
	strcpy(cstring, "Doe, John");
	Acct account1 = Acct( cstring, 'C', 113019.77 );
	
	char cstring2[80];
	strcpy(cstring, "Nagasruthi");
	Acct account2 = Acct( cstring, 'S', 1234.50 );
	
	char cstring3[80];
	strcpy(cstring, "Temperance, Brennan");
	Acct account3 = Acct( cstring, 's', 82.12 );
	
	char cstring4[80];
	strcpy(cstring, "Seeley, Booth");
	Acct account4 = Acct( cstring, 'c', 3869.00 );
	
	char cstring5[80];
	strcpy(cstring, "Zach, Addy");
	Acct account5 = Acct( cstring, 'C', 71940.76 );


However it told me that "cstring was not declared in the scope".

sloppy9, how would you go about defining a constructor? i do not remember how.
Well, it's correct. cstring isn't declared in the scope. You've created cstring1, 2, 3, 4 and 5, but nothing just called cstring. I imagine this was an oversight on your part. You really only need one cstring array, though.

You've declared your constructor here:

Acct(char[], char, double); //constructor

but you haven't defined it. A constructor is like any other function in this respect: if you declare it, you have to define it. Also, if you want this to be your default constructor, you have to give defaults to any paramaters you pass it.
Hi ,
you haven't declared the constructor .
Topic archived. No new replies allowed.