Я медленно строю свою банковскую систему и мне нужна помощь. Сначала хотя бы быстрый пробег. 1. выберите существующую учетную запись или новую. 2. после этого он отобразит варианты снятия, пополнения счета или закрытия счета (закрытие счета - наименьшее из моих беспокойств на данный момент). Я также использовал два разных текстовых документа. Один из них - «Счета», где он будет сканировать или добавлять учетные записи, другой - «Деньги», где он должен отслеживать деньги на каждом счете. Вопрос в том, как я могу назначить деньги на каждый счет?
У меня есть глава структурных массивов, но это меня смущает. Если это лучший способ действий, мне понадобится мини-пошаговое руководство, комментируя код для меня, чтобы лучше понять его.
#include <iostream>
#include <fstream>
#include <iomanip>//used to move text
#include <string>
using namespace std;
int display(char& anwser);
void N_account(char& anwser, string& name);
int Exist(string& name_search, char& anwser, string name_from_file, char&
anwser2, string& money_deposit);
void deposit(string& money_deposit, char& anwser, char& anwser2, int& money_D);
void withdraw(string& withdraw_money, char& anwser, char& anwser2, int& money_D, string& total_money, int& money_W);
int main()
{
int start_money, money_D, money_W;
string name, name_search, name_from_file, money_deposit, withdraw_money, total_money;
char anwser, anwser2;
display(anwser);
if (anwser == '1')
{
N_account(anwser, name);
}
if (anwser == '2')
{
Exist(name_search, anwser, name_from_file, anwser2, money_deposit);
}
if (anwser2 == '1')
{
deposit(money_deposit, anwser, anwser2, money_D);
}
if (anwser2 == '2')
{
withdraw(withdraw_money, anwser, anwser2, money_D, total_money, money_W);
}
}
int display(char& anwser)
{
cout << setw(65) << "=================" << endl;
cout << setw(65) << "Banking Managment" << endl;
cout << setw(65) << "=================" << endl;
cout << setw(60) << "1.New account" << endl;
cout << setw(65) << "2.Existing account" << endl;
cin >> anwser;
return 0;
}
void N_account(char& anwser, string& name)
{
ofstream outfile;
outfile.open("Accounts.txt", std::ofstream::out | std::ofstream::app);
cout << "Enter in first and last name for new account:";
cin.ignore();
getline(cin, name);
outfile << name;
outfile << endl;
cout << "Account added" << endl;
outfile.close();
}
int Exist(string & name_search, char& anwser, string name_from_file, char& anwser2, string & money_deposit)
{
ifstream infile;
infile.open("Accounts.txt");
cout << "Enter in your account:";
cin.ignore();
getline(cin, name_search);
while (getline(infile, name_from_file))
{
if (name_from_file == name_search)
{
cout << "Account found: " << name_search << endl;
cout << "Choose what you would like to do" << endl;
cout << setw(56) << "1.Deposit" << endl;
cout << setw(57) << "2.Withdraw" << endl;
cout << setw(62) << "3.Close account" << endl;
cin >> anwser2;
return 0;
}
}
infile.close();
}
void deposit(string & money_deposit, char& anwser, char& anwser2, int& money_D)
{
ofstream O_file;
O_file.open("Money.txt", std::ofstream::out | std::ofstream::app);
cout << "Enter in how much you would like to deposit: ";
cin.ignore();
getline(cin, money_deposit);
money_D = stoi(money_deposit);//converts string into integer so that I may use basic operators such as less than or subtraction ect.
if (money_D < 0)
{
cout << "Error!" << endl;
system("pause");
exit(1);
}
O_file << money_deposit;
O_file << endl;
O_file.close();
}
void withdraw(string & withdraw_money, char& anwser, char& anwser2, int& money_D, string & total_money, int& money_W)
{
ofstream O_file;
O_file.open("Money.txt", std::ofstream::out | std::ofstream::app);
cout << "Enter in how much you would like to withdraw:";
cin.ignore();
getline(cin, withdraw_money);
money_W = stoi(withdraw_money);//converting string to integer
total_money = money_W - money_D;
O_file << total_money;
O_file << endl;
O_file.close();
}
Когда я выбираю учетную запись с именем «Джон Доу» с балансом 45,00 долл. США и хочу снять 20,00 долл. США, я хочу, чтобы деньги для Джона Доу уменьшились до 25,00 долл. США, а НЕ занимать новую строку в текстовом документе «Деньги», в котором указано значение 20,00 долл. это было сделано.
Существуют следующие учетные записи:
Джон Доу
Джейн Доу
Трэвис Скотт
Уильям Смит
Патрик Майклс
Кортни Десмонд
Их банковские счета:
45,00
98,00
48,00
56,00
120.00`