Command Prompt Errors

Hey guys when I run the following program the command prompt pops up but the data does not load can someone tell me what I am doing wrong.

customer.h
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

#ifndef CUSTOMER_H
#define CUSTOMER_H

#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Customer Class
class Customer {
private:
    string name;  //name of customer
    string ssn; // social security number
    string address;  // address
    string birthDate;      //birth date
    double savings;  // savings account balance
    double checking;  // checking account balance
    double balance;    // Consoldated Balance

public:
    Customer(); //constructor
    Customer(string, string, string, string ,int, int);
    void setName(string);
    void setSSN(string);
    void setAddress(string);
    void setBirthDate(string);
    void setSavings(double);
    void setChecking(double);
        void setBalance(double);
        
        void operator +=( double );
        void operator -=( double );
        void operator ++ ();

    string getName();
    string getSSN();
    string getAddress();
    string getBirthDate();
    double getSavings();
    double getChecking();
    double getBalance();

        void displayCustomer();
        string string_displayCustomer();


};


//-----------------------------------------------------------------------------
//class definition
Customer::Customer() {
    name = " ";
    ssn = " ";
    address = " ";
    birthDate = " ";
    savings = 0;
        checking = 0;
        balance = 0;
}

Customer::Customer(string name, string ssn, string address, string birthDate, int savings, int checking) {
    Customer::name =  name;
    Customer::ssn = ssn;
    Customer::address = address;
    Customer::birthDate = birthDate;
    Customer::savings = savings;
    Customer::checking = checking;
    Customer::balance = balance;
}

void Customer::setName(string name) {
    Customer::name = name;
}

void Customer::setSSN(string ssn) {
    Customer::ssn = ssn;
}

void Customer::setAddress(string address) {
    Customer::address = address;
}

void Customer::setBirthDate(string birthDate) {
    Customer::birthDate = birthDate;
}

void Customer::setSavings(double savings) {
    Customer::savings = savings;
}

void Customer::setChecking(double checking) {
    Customer::checking = checking;
}

void Customer::setBalance(double balance) {
        Customer::balance = balance;
}



string Customer::getName() {
    return name;
}

string Customer::getSSN() {
    return ssn;
}

string Customer::getAddress() {
    return address;
}

string Customer::getBirthDate() {
    return birthDate;
}

double Customer::getSavings() {
    return savings;
}

double Customer::getChecking() {
    return checking;
}

double Customer::getBalance() {
        return balance;

}

void Customer::displayCustomer() {
    cout << "The current customer is " << name << ", their address is " << address << ", and their Social Security Number is "
                << ssn << ".  "  << name << "'s Saving Account Ballance is:" << savings << ".  The Checking Account Balance is:" << checking << ".\n";
        cout << "The consolidated balance is: $" << balance << ".\n";
}

string Customer::string_displayCustomer() {
        stringstream buf;
        cout << "The current customer is " << name << ", their address is " << address << ", and their Social Security Number is "
        << ssn << ".  "  << name << "'s Saving Account Ballance is:" << savings << ".  The Checking Account Balance is:" << checking << ".\n";
        cout << "The consolidated balance is: $" << balance << ".\n";
    return buf.str();
}
void Customer::operator += ( double dValue ) {
        setBalance( getBalance()+ dValue );
                //return this;
    }
void Customer::operator -= ( double dValue ) {
        setBalance( getBalance() - dValue );
                //return this;
    }

void Customer::operator ++ () {
       
      setBalance(getSavings()  +  getChecking());
 }

#endif 


Account.h
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
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include "Customer.h"

//Account Class
class Account {
private:
        Customer myCustomer[2];
        string type;
        int number;
    double balance;
    double rate;
        double intrest;
        double NewBalance;

public:
        Account(); // Constructor
        Account(string, int, double, double) ;
                void setType(string);
                void setNumber(int);
                void setBalance(double);
                void setRate(double);

                string getType();
                int getNumber();
                double getBalance();
                double getRate();
                Customer& getCustomer ( int );
                void valid_rate(double);
                void ApplyInterest();
				void operator += (Account& a);
				void operator -= (Account& a);
				void operator ++ (int n );

                };      
//-----------------------------------------------------------------------------
//class definition
        Account::Account() {
                type = " ";
                number = 0;
                balance = 0;
                rate = 0;
        }

        Account::Account(string type, int number, double balance, double rate) {
                Account::type = type;
                Account::number = number;
                Account::balance = balance;
                valid_rate(rate);
                }
void Account::setType(string type) {
    Account::type = type;
}

void Account::setNumber(int number) {
    Account::number = number;
}

void Account::setBalance(double balance) {
    Account::balance = balance;
}

void Account::setRate(double rate) {
        valid_rate(rate);
}

string Account::getType() {
    return type;
}
int Account::getNumber() {
    return number;
}
double Account::getBalance() {
    return balance;
}
double Account::getRate() {
    return rate;
}

void Account::valid_rate(double rate) {
        if (rate >=.01 && rate <= .1)
                Account::rate=rate;
        else {
                Account::rate=0;
                cout << "WARNING! You have entered an invalid rate!\n";
        }
}

void Account::ApplyInterest() {
                intrest = rate * balance;
                NewBalance = intrest + balance;
                cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
}      


Customer& Account::getCustomer(int n) {
        return myCustomer[n];
}

   // void operator += (Account& a) {
    void Account::operator+= (Account& a) {
        setBalance(getBalance()+ a.getBalance());
    }

    //void operator -= (Account& a) {
	void Account::operator-= (Account& a) {
        setBalance(getBalance() - a.getBalance());
    }

	void Account::operator++ (int n ) {
                //Customer::balance(Customer::savings + Customer::checking);
		myCustomer[0] += myCustomer[0].getSavings() + myCustomer[0].getChecking();
		myCustomer[1] += myCustomer[1].getSavings() + myCustomer[1].getChecking();        
    }

#endif 


test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Account.h"
#include "Customer.h"
#include "Date.h"
#include <iostream>
using namespace std;




int main() {
	Customer myCust[2];
	Account myInterest[2];
	int current_cust=0;
		Customer *myCustomer[2];
		myCustomer[0] = new Customer("Justin Puckett", "244-13-4567", "115 Fairbanks Court Mount Airy, NC", "May 17th 1990", 500, 1000);
		myCustomer[1] = new Customer("Shaina Parker", "244-13-0002", "234 Farmbrook Rd Mount Airy, NC", "May 27th 1990", 800, 2000);
		
		for(int x=0; x<2; x++)
		myCust[x].displayCustomer();
		for(int d=0; d<2; d++)
		myInterest[d].ApplyInterest();

        return 0;
}
Neither the myCust array nor the myInterest array have any meaningful data in them
(all elements are default constructed). You are putting the real data in the myCustomer
array.
Here is my new one

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
#include "Account.h"
#include "Customer.h"
#include "Date.h"
#include <iostream>
using namespace std;




int main() {
	Customer myCust[2];
	Account myInterest[2];
	int current_cust=0;
		Customer *myCustomer[2];
		myCustomer[0] = new Customer("Justin Puckett", "244-13-4567", "115 Fairbanks Court Mount Airy, NC", "May 17th 1990", 500, 1000);
		myCustomer[1] = new Customer("Shaina Parker", "244-13-0002", "234 Farmbrook Rd Mount Airy, NC", "May 27th 1990", 800, 2000);
		
		for(int x=0; x<2; x++)
		 myCustomer[x]->displayCustomer();

		for(int d=0; d<2; d++)
		Account *myInterestApplyInterest();
		delete [] myCustomer; // [] tells the OS that it needs to free an array


        return 0;
}
Lines 21 and 22 do nothing. Line 22 declares a function named myInterestApplyInterest.
You're also deleting your myCustomer array wrong:

1
2
3
4
5
6
7
// if you allocate with 2x new
myCustomer[0] = new Customer("Justin Puckett", "244-13-4567", "115 Fairbanks Court Mount Airy, NC", "May 17th 1990", 500, 1000);
myCustomer[1] = new Customer("Shaina Parker", "244-13-0002", "234 Farmbrook Rd Mount Airy, NC", "May 27th 1990", 800, 2000);

// then you delete with 2x delete
delete myCustomer[0];
delete myCustomer[1];


Since you never allocated with new[], you don't use delete[].
Topic archived. No new replies allowed.