x.Hmne could help to get this code working, it would be awesome. (This is simila
ID: 3619031 • Letter: X
Question
x.Hmne could help to get this code working, it would be awesome. (This is similar to problem 13, Chapter 13 in the book listed below, but not as detailed. Basically, just a checking account using class and Inheritance) The error that I am getting is this : fatal error C1083: Cannot open include file: 'BankAccount.h': No such file or directoryOf course, its the only error that I get, and no warnings.
Here is the code:
#include <iostream> #include <iomanip> using namespace std; class BankAccount { protected: double balance; public: BankAccount(); ~BankAccount(); double getbal() const; void withdrawl (double); double deposit(double); }; BankAccount::BankAccount() : balance(0.0) { } BankAccount::~BankAccount() { } double BankAccount::getbal() const { return balance; } void BankAccount::withdrawl (double amount) { if (amount > 0 && balance >= amount) { balance -= amount; } } double BankAccount::deposit (double amount) { if (amount > 0) { balance += amount; } return balance; } class checkingAccount: public BankAccount { public: checkingAccount(double = 0.0); ~checkingAccount(); void withdrawl (double); protected: double fees; }; void checkingAccount::withdrawl(double amount) { if (amount > 0 && balance >= amount) { balance -= (amount+fees); } } checkingAccount::checkingAccount(double initbalance): fees(0.0) { balance = initbalance; } checkingAccount::~checkingAccount() { } #include "BankAccount.h" #include "CheckingAccount.h" #include <iostream> #include <iomanip> using namespace std; int main () { BankAccount ba; checkingAccount ca; cout << " Welcome to The Bank " << endl; do{ char choice; MAINMENU: system("cls"); cout << endl; cout << " The Bank" << endl; cout << " Checking Account" << endl; cout << endl; cout << " Please select banking activity number 1 - 5" << endl; cout << " 1. Deposit " << endl; cout << " 2. withdrawlal " << endl; cout << " 3. Account Balance " << endl; cout << " 4. Exit " << endl; cout << endl; cout << " Enter your choice by using the numbers -->> "; choice=toupper(getchar()); fflush (stdin); switch(choice) { double dep, withdrawl; case '1': cout <<"Enter amount of money to deposit:"<< endl; cin>>dep; cout <<"You have deposited "<< dep <<"dollars" << endl; break; case '2': ca.getbal(); { if (balance <= 0 ("Invalid Funds, Please try again."); else cout <<"How much would you like to withdrawlal?"<< endl; cin>>withdrawl; checkingAccount(withdrawl); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; } break; case '3': ba.getbal(); break; case '4': break; default: cout<<"Invalid menu item...Please re-enter your choice"<<endl; break; cout<<""<<endl; cout<<"Checking Account Balance Before: $"<<ca.getbal()<<endl<<endl; ca.withdrawl(2500.43); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; system("pause"); } return 0; } WLX fatal error C1083: Cannot open include file: 'BankAccount.h': No such file or directory
Of course, its the only error that I get, and no warnings.
Here is the code:
#include <iostream> #include <iomanip> using namespace std; class BankAccount { protected: double balance; public: BankAccount(); ~BankAccount(); double getbal() const; void withdrawl (double); double deposit(double); }; BankAccount::BankAccount() : balance(0.0) { } BankAccount::~BankAccount() { } double BankAccount::getbal() const { return balance; } void BankAccount::withdrawl (double amount) { if (amount > 0 && balance >= amount) { balance -= amount; } } double BankAccount::deposit (double amount) { if (amount > 0) { balance += amount; } return balance; } class checkingAccount: public BankAccount { public: checkingAccount(double = 0.0); ~checkingAccount(); void withdrawl (double); protected: double fees; }; void checkingAccount::withdrawl(double amount) { if (amount > 0 && balance >= amount) { balance -= (amount+fees); } } checkingAccount::checkingAccount(double initbalance): fees(0.0) { balance = initbalance; } checkingAccount::~checkingAccount() { } #include "BankAccount.h" #include "CheckingAccount.h" #include <iostream> #include <iomanip> using namespace std; int main () { BankAccount ba; checkingAccount ca; cout << " Welcome to The Bank " << endl; do{ char choice; MAINMENU: system("cls"); cout << endl; cout << " The Bank" << endl; cout << " Checking Account" << endl; cout << endl; cout << " Please select banking activity number 1 - 5" << endl; cout << " 1. Deposit " << endl; cout << " 2. withdrawlal " << endl; cout << " 3. Account Balance " << endl; cout << " 4. Exit " << endl; cout << endl; cout << " Enter your choice by using the numbers -->> "; choice=toupper(getchar()); fflush (stdin); switch(choice) { double dep, withdrawl; case '1': cout <<"Enter amount of money to deposit:"<< endl; cin>>dep; cout <<"You have deposited "<< dep <<"dollars" << endl; break; case '2': ca.getbal(); { if (balance <= 0 ("Invalid Funds, Please try again."); else cout <<"How much would you like to withdrawlal?"<< endl; cin>>withdrawl; checkingAccount(withdrawl); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; } break; case '3': ba.getbal(); break; case '4': break; default: cout<<"Invalid menu item...Please re-enter your choice"<<endl; break; cout<<""<<endl; cout<<"Checking Account Balance Before: $"<<ca.getbal()<<endl<<endl; ca.withdrawl(2500.43); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; system("pause"); } return 0; } #include <iostream> #include <iomanip> using namespace std; class BankAccount { protected: double balance; public: BankAccount(); ~BankAccount(); double getbal() const; void withdrawl (double); double deposit(double); }; BankAccount::BankAccount() : balance(0.0) { } BankAccount::~BankAccount() { } double BankAccount::getbal() const { return balance; } void BankAccount::withdrawl (double amount) { if (amount > 0 && balance >= amount) { balance -= amount; } } double BankAccount::deposit (double amount) { if (amount > 0) { balance += amount; } return balance; } class checkingAccount: public BankAccount { public: checkingAccount(double = 0.0); ~checkingAccount(); void withdrawl (double); protected: double fees; }; void checkingAccount::withdrawl(double amount) { if (amount > 0 && balance >= amount) { balance -= (amount+fees); } } checkingAccount::checkingAccount(double initbalance): fees(0.0) { balance = initbalance; } checkingAccount::~checkingAccount() { } #include "BankAccount.h" #include "CheckingAccount.h" #include <iostream> #include <iomanip> using namespace std; int main () { BankAccount ba; checkingAccount ca; cout << " Welcome to The Bank " << endl; do{ char choice; MAINMENU: system("cls"); cout << endl; cout << " The Bank" << endl; cout << " Checking Account" << endl; cout << endl; cout << " Please select banking activity number 1 - 5" << endl; cout << " 1. Deposit " << endl; cout << " 2. withdrawlal " << endl; cout << " 3. Account Balance " << endl; cout << " 4. Exit " << endl; cout << endl; cout << " Enter your choice by using the numbers -->> "; choice=toupper(getchar()); fflush (stdin); switch(choice) { double dep, withdrawl; case '1': cout <<"Enter amount of money to deposit:"<< endl; cin>>dep; cout <<"You have deposited "<< dep <<"dollars" << endl; break; case '2': ca.getbal(); { if (balance <= 0 ("Invalid Funds, Please try again."); else cout <<"How much would you like to withdrawlal?"<< endl; cin>>withdrawl; checkingAccount(withdrawl); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; } break; case '3': ba.getbal(); break; case '4': break; default: cout<<"Invalid menu item...Please re-enter your choice"<<endl; break; cout<<""<<endl; cout<<"Checking Account Balance Before: $"<<ca.getbal()<<endl<<endl; ca.withdrawl(2500.43); cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; system("pause"); } return 0; }
Explanation / Answer
x.P5lor="red">please rate - thanks you didn't define separate files for your 2 classes. they are all in the 1 file. to keep everything in 1 file rearrange your code, and get rid of the 2 #include I did that, and cleared up your other syntax errors(hope you don't mind), also made it a little bit more readable #include #include using namespace std; class BankAccount { protected: double balance; public: BankAccount(); ~BankAccount(); double getbal() const; void withdrawl (double); double deposit(double); }; BankAccount::BankAccount() : balance(0.0) { } BankAccount::~BankAccount() { } double BankAccount::getbal() const { return balance; } void BankAccount::withdrawl (double amount) { if (amount > 0 && balance >= amount) { balance -= amount; } } double BankAccount::deposit (double amount) { if (amount > 0) { balance += amount; } return balance; } class checkingAccount: public BankAccount { public: checkingAccount(double = 0.0); ~checkingAccount(); void withdrawl (double); protected: double fees; }; void checkingAccount::withdrawl(double amount) { if (amount > 0 && balance >= amount) { balance -= (amount+fees); } } checkingAccount::checkingAccount(double initbalance): fees(0.0) { balance = initbalance; } checkingAccount::~checkingAccount() { } int main () { BankAccount ba; checkingAccount ca; char choice; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.