我知道这个问题已被问过并多次回答 我已经尝试了几乎所有可以在Stackoverflow上找到的解决方案 但其他问题中给出的解决方案无效 使用了矢量/模板,这就是我认为导致问题的原因 问题是模板或我不知道的事情 我需要调试此代码,我不熟悉模板和向量 使用Visual Studio 2017 这些是两个源代码文件,其余是自动生成的
ConsoleApplication1.cpp
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct bank
{
int accno;
double accountBalance;
string firstname;
string lastname;
};
template <typename typeStruct>
int main()
{
vector <bank> bankAccounts;
// declare list of account here. The size of the list is not fixed.
int input = 0, i=0;
int *inputPtr = &input;
menu(inputPtr);
switch (input)
{
case 1:
{
i++;
makeAccount(i,bankAccounts);
break;
}
case 2:
{
PrintAllAcount();
break;
}
case 3:
{
depositAccount(i,bankAccounts);
break;
}
case 4:
{
cout << "Enter account no";
cin >> i;
withdrawAccount(i, bankAccounts);
break;
}
case 5:
{
printAccount();
break;
}
case 6:
{
return 0;
}
default:
{
cout << "Invalid Input";
}
// cases: call functions to perform tasks
}
return 0;
}
功能file.cpp
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct bank
{
int accno;
double accountBalance;
string firstname;
string lastname;
};
void menu(int *num)
{
int select = 0;
cout << "Welcome to MadeUp Banking. Select options below:" << endl;
cout << "\t1. Make new account."
<< "\n\t2. Display all accounts."
<< "\n\t3. Deposit to an account."
<< "\n\t4. Withdraw from an account."
<< "\n\t5. Print account."
<< "\n\t6. Quit." << endl;
cout << "Selection:\t";
cin >> select;
*num = select;
}
// write the remaining functions here
void makeAccount(int i, vector <bank> &vec)
{
cout << "\n*************************************";
cout << "\n ACCOUNT CREATION ";
cout << "\n*************************************";
cout << "\n Creating bank account number :" << i;
vec[i-1].accno = i;
cout << "\nEnter first name:";
cin >> vec[i-1].firstname;
cout << "\nEnter last name:";
cin >> vec[i-1].lastname;
cout << "Enter starting balance:";
cin >> vec[i-1].accountBalance;
}
void PrintAllAcount()
{
cout << "\n";
}
void depositAccount(int i, vector <bank> &a)
{
int accno, b = 0, m = 0;
double aa;
cout << "\n*************************************";
cout << "\n DEPOSIT ";
cout << "\n*************************************";
cout << "\nEnter your Account Number";
cin >> accno;
for (b = 0; b<i; b++)
{
if (a[b].accno == accno)
m = b;
}
if (a[m].accno == accno)
{
cout << "\n Account Number : " << a[m].accno;
cout << "\n First Name : " << a[m].firstname;
cout << "\n Starting Balance : " << a[m].accountBalance;
cout << "\n How Much Deposited Now:";
cin >> aa;
a[m].accountBalance += aa;
printf("\nDeposit Amount is :%f", a[m].accountBalance);
}
else
{
cout << "\nACCOUNT NUMBER IS INVALID";
}
}
void withdrawAccount(int i, vector <bank> &a)
{
int accno, b = 0, m = 0;
double aa;
cout << "\n*************************************";
cout << "\n WITHDRAW ";
cout << "\n*************************************";
cout << "\nEnter your Account Number";
cin >> accno;
for (b = 0; b<i; b++)
{
if (a[b].accno == accno)
m = b;
}
if (a[m].accno == accno)
{
cout << "\n Account Number : " << a[m].accno;
cout << "\n First Name : " << a[m].firstname;
cout << "\n Starting Balance : " << a[m].accountBalance;
cout << "\n How Much Withdrawl Now:";
cin >> aa;
a[m].accountBalance -= aa;
printf("\nThe Balance Amount is :%f", a[m].accountBalance);
}
else
{
cout << "\nACCOUNT NUMBER IS INVALID";
}
}
void printAccount()
{
cout << "\n";
}
void sortAcounts()
{
cout << "\n";
}
// sort the accounts using the account numbers
void deleteAccount()
{
cout << "\n";
}