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
|
//Konto.h
// contains information for account (konto in swedish)
class Konto
{
public:
Konto() : nummer(0), innehavare(""), saldo(0), rantesats(0) {}
Konto(const int _nummer, string &_innehavare, double _saldo, double _rantesats) : nummer(_nummer), innehavare(_innehavare), saldo(_saldo), rantesats(_rantesats) {}
Konto(const Konto &rhs) : nummer(rhs.nummer), innehavare(rhs.innehavare), saldo(rhs.saldo), rantesats(rhs.rantesats) {}
Konto operator=(const Konto &rhs)
{
if (&rhs == this)
{
return *this;
}
nummer = rhs.nummer;
innehavare = rhs.innehavare;
saldo = rhs.saldo;
rantesats = rhs.rantesats;
return *this;
}
//Metod: Sets the necessary info
void SetInfo(const int _nummer, string &_innehavare, double _saldo, double _rantesats)
{
nummer = _nummer;
innehavare = _innehavare;
saldo = _saldo;
rantesats = _rantesats;
}
void Konto::skrivut(vector<Konto>&kontoClass);
// Acessor functions
int Nummer() const { return nummer; }
const string &Innehavare() const { return innehavare; }
double Saldo() const { return saldo; }
double Rantesats() const { return rantesats; }
//Member variables
private:
int nummer;
string innehavare;
double saldo;
double rantesats;
};
//Bank.h
//contains a vector with several accounts when added in Bank.cpp
class Bank {
public:
Bank() = default; // default contrcutor
Bank(int m_size): konton(m_size, 0), antal_konton(0) {}
Bank(vector<Bank> &_konton, int _antal_konton) : konton(_konton), antal_konton(_antal_konton) {} // I'm sure you meant vector<Bank> instead of Bank
Bank(const Bank &rhs) : konton(rhs.konton), antal_konton(rhs.antal_konton) {}
Bank operator=(const Bank &rhs)
{
if (&rhs == this)
{
return *this;
}
konton = rhs.konton;
antal_konton = rhs.antal_konton;
return *this;
}
void SetInfo(const vector<Bank> _konton, int _antal_konton) // You are taking a vector<Bank>, not an int
{
konton = _konton;
antal_konton = _antal_konton;
}
void Bank::nytt_konto(vector<Bank>&Konton);
vector<Bank> Konton() const { return konton; } // You are returning a vector<Bank> not an int
vector<Bank>::size_type getSize() const { return konton.size(); }
private:
vector<Bank> konton;
int antal_konton;
};
//Bank.cpp - Function Definitions
#include "Bank.h"
// Lägger till ett nytt konto
// Adds new konto (account) to bank konton (accounts) vector - several account in a bank vector
void Bank::nytt_konto(vector<Bank>&konton)
{
// This get me error message C2082
Konto* konton = new Konto();
int nummer;
string innehavare;
int saldo;
int rantesats;
cout << "Skriv in kontonummer: " << flush << endl;
// Enter values into vector
cin >> nummer;
// Flush makes sure that the buffer is cleared and the characters are written to their destination
cout << "Skriv namn på innehavare: " << flush << endl;
// Enter values into vector
cin >> innehavare;
cout << "Skriv in saldot: " << flush << endl;
// Enter values into vector
cin >> saldo;
// Flush makes sure that the buffer is cleared and the characters are written to their destination
cout << "Skriv in räntesatsen: " << flush << endl;
// Enter values into vector
cin >> rantesats;
// This get me error message C2664
konton.push_back(Konto(nummer, innehavare, saldo, rantesats));
cout << endl;
}
|