Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am getting error LNK2005: int__cdecl menu(void) (?menu@@YAHXZ) already defined in function.obj and error LNK1169: one or more multiply defined symboles found I understand what

I am getting "error LNK2005: "int__cdecl menu(void)" (?menu@@YAHXZ) already defined in function.obj" and "error LNK1169: one or more multiply defined symboles found"

I understand what the errors are, but I can't figure out how to fix them.Please help fix them

I have a function.cpp, main.cpp, and header_file.h:

function.cpp:

#include "header_file.h" #include #include #include #include #include #include

using std::cin; using std::cout; using std::endl; using std::vector; using std::string;

int menu() { int choice = 0; cout << " Welcome to MadeUp Banking. Select options below:" << endl; cout <<"\t 1. Make new account." << endl; cout <<"\t 2. Display all accounts." << endl; cout <<"\t 3. Deposit to an account." << endl; cout <<"\t 4. Withdraw from an account." << endl; cout <<"\t 5. Print account." << endl; cout <<"\t 6. Delete an account." << endl; cout <<"\t 7. Quit." << endl; cout <<"Selection: "; cin >> choice; while(choice < 1 || choice > 7) { cout << "Invalid choice. Enter a valid choice: "; cin >> choice; }

return choice; } template void makeAccount(vector & myVec) { bool duplicate = true; int accNum; string fName, lName; double balance; while(duplicate) { duplicate = false; accNum = rand() % 9000 + 1000; for(int i = 0; i < myVec.size(); i++) if(myVec[i].accountNumber == accNum) duplicate = true; if(!duplicate) break; } cout << " Creating bank account number " << accNum << endl; typeStruct account; account.accountNumber = accNum; cout << " Enter first name: "; cin >> fName; account.firstName = fName; cout << "Enter last name: "; cin >> lName; account.lastName = lName; cout << "Enter starting balance: "; cin >> balance; account.accountBalance = balance; myVec.push_back(account); } template void printAllAccounts(vector myVec) { for(int i = 0; i < myVec.size(); i++) { cout << " Account number: " << myVec[i].accountNumber << "\t"; cout << "\t\tBalance: " << std::fixed << std::setprecision(2) << myVec[i].accountBalance << endl; cout << "\t\tLast name: " << myVec[i].lastName << "\t\t" << "First name: " << myVec[i].firstName << endl; } } template void printAccount(vector myVec) { int accNum; cout << "Enter account number to print: "; cin >> accNum; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { cout << "Account number: " << myVec[i].accountNumber << "\t"; cout << "Balance: " << std::fixed << std::setprecision(2) << myVec[i].accountBalance << endl; cout << "Last name: " << myVec[i].lastName << "\t" << "First name: " << myVec[i].firstName << endl; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void depositAccount(vector &myVec) { int accNum; double amount; cout << "Enter account number for deposit: "; cin >> accNum; cout << "Enter amount to be deposited: "; cin >> amount; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec[i].accountBalance += amount; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void withdrawAccount(vector & myVec) { int accNum; double amount; cout << "Enter account number for withdraw: "; cin >> accNum; cout << "Enter amount to be withdrawn: "; cin >> amount; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec[i].accountBalance -= amount; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void deleteAccount(vector & myVec) { int accNum; double amount; cout << "Enter account number to be deleted: "; cin >> accNum; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec.erase(myVec.begin() + i); found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void sortAccounts(vector & bankAccounts) { for(int i = 0; i < bankAccounts.size()-1; i++) for(int j = 0; j < bankAccounts.size()-i-1; j++) if(bankAccounts[j].accountNumber > bankAccounts[j+1].accountNumber) { typeStruct temp = bankAccounts[j]; bankAccounts[j] = bankAccounts[j+1]; bankAccounts[j+1] = temp; } }

------------------------------------------------------------------------------------------------------------------------------------

main.cpp"

#include "function.cpp" #include "header_file.h" #include #include #include #include #include

using std::cin; using std::cout; using std::endl; using std::vector; using std::string;

int main() { std::cout << std::flush;

vector accounts; while(true) { int choice = menu(); switch(choice) { case 1: makeAccount(accounts); break; case 2: printAllAccounts(accounts); break; case 3: depositAccount(accounts); break; case 4: withdrawAccount(accounts); break; case 5: printAccount(accounts); break; case 6: deleteAccount(accounts); break; case 7: return 0; default: cout << "Invalid menu..." << endl; } } }

-----------------------------------------------------------------------------------------------------------

header_file.h:

#ifndef MYNODE_H_ #define MYNODE_H_

#include #include #include #include

using std::cin; using std::cout; using std::endl; using std::vector; using std::string;

typedef struct Account{ int accountNumber; string lastName; string firstName; double accountBalance; }Account;

int menu(); template void makeAccount(vector &); template void printAllAccounts(vector ); template void printAccount(vector ); template void depositAccount(vector &); template void withdrawAccount(vector &); template void deleteAccount(vector &); template void sortAccounts(vector &);

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions