Function in class

I want to use funtion case 2 to print out all values but it not working.
I dont know why and couldnt find any examples.

This line gives the error:

konto.skriv_kontolista(); //

The code generates this error code:

error C2660: 'Konto::skriv_kontolista' : function does not take 0 arguments

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  	case 1:

	//Denna funktionen fungerar, this function is working
	cout << endl << "L\x84gg in ett nytt konto" << endl;
	//Bank nytt_konto();
	bank.nytt_konto();
break;

case 2:
        // Denna funktionen fungerar inte, this function isnt working
        cout << endl << "Skriv ut en lista \x94ver konton" << endl;
	konto.skriv_kontolista(); // 				break;

// Bankaccount

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#ifndef BANKACCOUNTS_H
#define BANKACCOUNTS_H

using namespace std; 

//Konto klassen
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 skriv_kontolista(vector<Konto>&konton);

	// 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;
};

//Bankklassen

class Bank {
public:
	vector<Konto>konton;
	Bank(): konton(), antal_konton(0) {}
	Bank(vector<Konto> &_konton, int _antal_konton) : konton(_konton), antal_konton(_antal_konton) {} 
	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<Konto> _konton, int _antal_konton)
	{
		konton = _konton;
		antal_konton = _antal_konton;
	}

	void nytt_konto();

	vector<Konto> Konton() const { return konton; }
    vector<Konto>::size_type getSize() const { return konton.size(); }
	int Antal_konton() const { return antal_konton; }
	
private:
	int antal_konton;
}; 

//Function Declarations


//void nytt_konto(vector<Konto>&konton);

//void skriv_kontolista(vector<Konto>&konton);

//void ranteutbetalning(vector<Konto>&konton);

//void sok_kontonummer(vector<Konto>&konton,const int& key, const int& start, const int& end); 

//BubbleSort - Sorterar vektorn
void BubbleSort(vector<Konto>&konton);
// @param konton - Vektorn som ska sorteras ska sorteras efter namn

//Swap - Skapar tillf\x84lliga variabler f\x94r namn
void swap(Konto &p, Konto &q);

//void check_kontonummer(vector<Konto>&konton,const int& nummer, const int& start, const int& end);*/

#endif

//Bankccount.cpp - Function Definitions

#include "Bankaccount.h"

	// L\x84gger till ett nytt konto
	void Bank::nytt_konto()
	{
		string fornamn;
		string efternamn;

		int nummer;
		string innehavare;
		double saldo;
		double rantesats;

		cout << "Skriv in kontonummer: " << flush << endl;
		
		// Enter values into vector
		cin >> nummer;

		for(unsigned int i=0; i < konton.size(); i++)
		{
			if (nummer == konton[i].Nummer())
			{
				cout << "Konto existerar redan." << endl << endl;
				return;
			}
		}

		// Flush makes sure that the buffer is cleared and the characters are written to their destination
		cout << "Skriv namn p\x86 innehavare: " << flush << endl << endl;
		
		// Enter values into vector
		cout << "Skriv in f\x94rnamn: " << endl;

		cin >> fornamn;

		cout << "Skriv in efternamn: " << endl;

		cin >> efternamn;

		innehavare = fornamn + " " + efternamn;
			
		cout << endl << "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 << endl << "Skriv in r\x84ntesatsen: " << flush << endl;
		
		// Enter values into vector
		cin >> rantesats;

		cout << endl;
		cout << "Nytt konto skapat:" << endl;
		cout << "Kontonummer: " << nummer << endl;
		cout << "Innehavare: " << innehavare << endl;
		cout << "Saldo: " << saldo << endl;
		cout << "R\x84ntesats: " << rantesats << endl << endl;

		// This get me error message C2664
		konton.push_back(Konto(nummer, innehavare, saldo, rantesats));
} 

//Skriver ut samtliga attribut
void Konto::skriv_kontolista(vector<Konto>&konton)
{		
	//Sort order, innehavare
	for (unsigned int i = 0; i < konton.size(); i++)
	{
		BubbleSort(konton);
		cout << "Kontonummer: " << konton[i].Nummer() << endl;
		cout << "Innehavare: " << konton[i].Innehavare() << endl;
		cout << "Saldo: " << konton[i].Saldo() << endl;
		cout << "R\x84ntesats: " << konton[i].Rantesats() << endl << endl;
	}
}

/*

void ranteutbetalning(vector<Konto>&konton)
{
	int nummer;
	string innehavare;
	double saldo;
	double rantesats;	

	double saldo_tmp;
	double slutligt_saldo;	

	int j = 0;

		for (unsigned int i = 0; i < konton.size(); i++)
		{
			BubbleSort(konton);
			while (j < konton.size())
			{
			nummer = konton[i].Nummer();
			innehavare = konton[i].Innehavare();

			saldo_tmp = konton[i].Saldo();
			rantesats = konton[i].Rantesats();

			konton.erase(konton.begin());

			slutligt_saldo = (saldo_tmp * ((rantesats * 0.01) + 1.00));

			saldo = slutligt_saldo;

			konton.push_back(Konto(nummer, innehavare, saldo, rantesats));

			j++;
			}

			cout << "Kontonummer: " << konton[i].Nummer() << endl;
			cout << "Innehavare: " << konton[i].Innehavare() << endl;
			cout << "Slutligt saldo: " << konton[i].Saldo() << endl;
			cout << "R\x84ntesats: " << konton[i].Rantesats() << endl << endl;
		}
}

void sok_kontonummer(vector<Konto>&konton,const int& key, const int& start, const int& end)
{
    if(end < start)
        // Set is empty
        cout << "Hittar inget matchande kontonummer" << endl;
    else
    {
        // Calculate midpoint to cut set in half
        int mid = (start + end)/2;
         
        if(konton[mid].Nummer() > key)
            // Key is in lower subset
            return sok_kontonummer(konton, key, start, mid-1);
        else if (konton[mid].Nummer() < key)
            // Key is in upper subset
            return sok_kontonummer(konton, key, mid+1, end);
        else if (konton[mid].Nummer() == key)
		{
            // Key has been found
			cout << endl;
			cout << "Konto hittat:" << endl;
            cout << "Kontonummer: " << endl << konton[mid].Nummer() << endl;
			cout << "Innehavare: " << konton[mid].Innehavare() << endl;
			cout << "Saldo " << konton[mid].Saldo() << endl;
			cout << "R\x84ntesats: " << konton[mid].Rantesats() << endl << endl;
		}
	}
} */

//Function Definitions

void BubbleSort(vector<Konto>&konton)
{
	// The outer loop, going through all list
    for(int i = 0; i < konton.size(); i++)
	{
		//Inner loop, going through element by element
		int nrLeft = konton.size() - i; // To se how many has been gone through
		for (int j = 0; j < nrLeft - 1; j++)
		{
			
			if (konton[j].Innehavare() > konton[j+1].Innehavare()) // Compare the elements
			{
				swap(konton[j], konton[j+1]); 
			}
		}
	}
}

void swap(Konto &p, Konto &q) 
{ 
	Konto temp = p; 
	p = q;
	q = temp;
}

Last edited on
1
2
3
void skriv_kontolista(vector<Konto>&konton); // This is what your function should look like, you declared it this way.

konto.skriv_kontolista(); //  so when you call it, you cant have empty parameters, because this function takes a vector as parameter. 
Topic archived. No new replies allowed.