Help with understanding class

I thought I had figured out how to create classes, until I had to use numbers in them. The example I was given did not use them, and the problem for my assignment has almost nothing to do with the example. My problem is that I'm not sure how to go forward with implementing the use of a static random number generator, or the addition of an array.

Here's the assignment:
Define the class bankAccount to implement the basic properties of a
bank account. An object of this class should store the following data:
Account holder’s name (string), account number (int), account
type (string, checking/saving), balance (double), and interest rate
(double). (Store interest rate as a decimal number.) Add appropriate
member functions to manipulate an object. Use a static member
in the class to automatically assign account numbers. Also declare
an array of 10 components of type bankAccount to process up to
10 customers and write a program to illustrate how to use your class.

My cpp file:
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
  #include <iostream>
#include <string>
#include "bankAccount.h"

using namespace std;

void bankAccount::print() const
{
    cout << accNum << " " << name << " " << type << " " << bal << " " << rate << endl;
}

void bankAccount::setName(string name)
{
    fullName = name;
}

void bankAccount::setType(string type)
{
    accType = type;
}

void bankAccount::setAccNum(int num)
{
    accNum = num;
}

void bankAccount::setBal(double bal)
{
    accBal = bal;
}

void bankAccount::setRate(double rate)
{
    interestRate = rate;
}

bool bankAccount::isFullName(string name) const
{
    return (fullName == name);
}

bool bankAccount::isAccType(string type) const
{
    return (accType == type);
}

bool bankAccount::isAccNum(int num) const
{
    return (accNum == num);
}

bool bankAccount::isAccBal(double bal) const
{
    return (accBal == bal);
}

bool bankAccount::isInterestRate(double rate) const
{
    return (interestRate == rate);
}

string bankAccount::getFullName() const
{
    return fullName;
}

string bankAccount::getAccType() const
{
    return accType;
}

int bankAccount::getAccNum() const
{
    return accNum;
}

double bankAccount::getAccBal() const
{
    return accBal;
}

double bankAccount::getInterestRate() const
{
    return interestRate;
}

bankAccount::bankAccount(string name, string type, int num, double bal, double rate)
{
    fullName     = name;
    accType      = type;
    accNum       = num;
    accBal       = bal;
    interestRate = rate;

}
My header file:
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
#include <string>
using namespace std;

class bankAccount
{
public:
	void print() const;
	void setName(string name);
	void setType(string type);
	void setAccNum(int num);
	void setBal(double bal);
	void setRate(double rate); //decimal

	bool isFullName(string name) const;
	bool isAccType(string type) const;
	bool isAccNum(int num) const;
	bool isAccBal(double bal) const;
	bool isInterestRate(double rate) const;

	string getFullName() const;
	string getAccType() const;
	int getAccNum() const;
	double getAccBal() const;
	double getInterestRate() const;

	bankAccount(string name = "", string type = "", int num = 0, double bal = 0.0, double rate = 0.0); 

private:
	string fullName;
	string accType;
	int accNum;
	double accBal;
	double interestRate;

};
My main:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
#include "bankAccount.h"
using namespace std;

int main()
{
    bankAccount owner("not quite sure what to put here");
    owner.print();
}
line 8 is filling in the parameters of line 26 from the previous post.
bankAccount(string name = "", string type = "", int num = 0, double bal = 0.0, double rate = 0.0);

so you need
bankAccount owner("some_name", "type like savings or something") ; //the rest default to zero OR
bankAccount owner("some_name", "type like savings or something", 3, 152.75, 0.02) ; //override the zeros

because you also did defaults on the strings, you can treat this like a default ctor though it is NOT technically one. /shrug.
Last edited on
Thank you jonnin, I wasn't sure if that's what I was meant to to or not for that spot, or if my code was working so far to even do that
Topic archived. No new replies allowed.