I have this code which is working, but I cannot make work as separate files. I'm getting errors:
error C3861: 'Saving': identifier not found and error C3861: 'SmartSaving': identifier not found.
There are 2 more files Account.h and Account.cpp but i dont think they are the problem.
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include "Account.h"
using namespace std;
int main() {
int n;
cin >> n;
vector<Account> accounts(n);
string type, id;
double amount, percent;
for (int i = 0; i < n; i++) {
cin >> type >> id >> amount >> percent;
if (type == "c")
accounts[i] = Account(id, amount, percent);
else if (type == "s")
accounts[i] = Saving(id, amount, percent);
else if (type == "ss")
accounts[i] = SmartSaving(id, amount, percent);
}
string t;
int idx;
double sum;
cout << fixed << setprecision(2);
while (cin >> t) {
if (t == "w") {
cin >> idx >> sum;
accounts[idx - 1].withdraw(sum);
}
else if (t == "d") {
cin >> idx >> sum;
accounts[idx - 1].deposit(sum);
}
else if (t == "b") {
cin >> idx;
cout << accounts[idx - 1].getAmount() << endl;
}
else if (t == "p") {
for (int i = 0; i < n; i++)
accounts[i].tick();
}
}
system("pause");
}
Saving.h
#pragma once
#ifndef _SAVING_H
#define _SAVING_H
#include "Account.h"
#include <string>
class Saving : public Account {
public:
Saving();
Saving(std::string, double, double);
};
#endif
Saving.cpp
#include "Saving.h"
#include <string>
Saving::Saving(std::string id, double amount, double percent)
: Account(id, amount, percent) {}
SmartSaving.h
#pragma once
#ifndef _SMARTSAVING_H
#define _SMARTSAVING_H
#include "Account.h"
#include <string>
class SmartSaving : public Account {
public:
SmartSaving() {};
SmartSaving(std::string id, double amount, double percent);
};
#endif
SmartSaving.cpp
#include "SmartSaving.h"
#include <string>
SmartSaving::SmartSaving(std::string id, double amount, double percent)
: Account(id, amount, percent) {}
Aucun commentaire:
Enregistrer un commentaire