I am trying to make my program print out the contents of a vector containing objects of class type Checking
i want it to print the balance of each element in the vector but when i try to use
cout<<checking[1]
all i get is nonsense characters
here is what i have so far
Main
#include "checking.h"
#include "savings.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector < Checking * > checking(50) ;
vector < Savings *> savings(50);
int accNumS = 0, accNumC = 0;
double bal = 0, amt = 0;
while(accNumC < 3)
{
cout << "Enter balance for accont #" << accNumC+1 << ": ";
cin >> bal;
checking[accNumC] = new Checking(accNumC+1,bal);
accNumC++;
}
cout << checking[1]<<"\n";
cout << checking[2]<<"\n";
cout << checking[3]<<"\n";
system("pause");
return 0;
}
account.h(checking inherits from this)
#include "checking.h"
#include "savings.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector < Checking * > checking(50) ;
vector < Savings *> savings(50);
int accNumS = 0, accNumC = 0;
double bal = 0, amt = 0;
while(accNumC < 3)
{
cout << "Enter balance for accont #" << accNumC+1 << ": ";
cin >> bal;
checking[accNumC] = new Checking(accNumC+1,bal);
accNumC++;
}
cout << checking[1]<<"\n";
cout << checking[2]<<"\n";
cout << checking[3]<<"\n";
system("pause");
return 0;
}
account.cpp
// Class automatically generated by Dev-C++ New Class wizard
#include "account.h" // class's header file
// class constructor
Account::Account(int accnum, double accbalance)
{
setAccountNum(accnum);
setbalance(accbalance);
}
void Account::setAccountNum(int num)
{
AccountNum = num;
}
int Account::getAccountNum()
{
return AccountNum;
}
void Account::setbalance(double sbalance)
{
balance = sbalance;
}
double Account::getbalance()
{
return balance;
}
void Account::operator+=(double num)
{
double accountbalance;
accountbalance = getbalance();
accountbalance += num;
setbalance(accountbalance);
}
void Account::operator-=(double num)
{
double accountbalance;
accountbalance = getbalance();
accountbalance -= num;
setbalance(accountbalance);
}
// class destructor
Account::~Account()
{
// insert your code here
}
checking.h
// Class automatically generated by Dev-C++ New Class wizard
#ifndef CHECKING_H
#define CHECKING_H
#include "account.h" // inheriting class's header file
// No description
class Checking : public Account
{
public:
// class constructor
Checking(int, double);
// class destructor
~Checking();
};
#endif // CHECKING_H
checking.cpp
// Class automatically generated by Dev-C++ New Class wizard
#include "checking.h" // class's header file
// class constructor
Checking::Checking(int num, double bal): Account(num, bal)
{
// insert your code here
}
// class destructor
Checking::~Checking()
{
// insert your code here
}
may be more code than you need to solve problem but i figured id post it all to be safe