Slavi 94 Master Poster Featured Poster
Eclipse / Netbeans Java IDE's
Use Code blocks for c++ :)
#include <iostream>
using namespace std;
void swapNumbers(int &x, int &y)
{
int tmp= x;
x=y;
y=tmp;
}
int main()
{
int a,b;
cin >> a;
cin >> b;
cout<< "Numbers are " <<a <<" "<< b <<endl;
swapNumbers(a,b);
cout << "Swaped numbers are " << a <<" "<< b << endl;
}
Rahul's code is completed and it works as expected, I think it is easy to convert it into c++ yourself
What is your question... ?
^classes mainly as you can create objects of those classes
Or if you want to use Cout to print instead
#include <iostream>
using namespace std;
for(int i =1, i<10,i++){
cout<<"The current number is: "<<i<<endl;
}
cout<<"Merry xmas"<<endl;
you need to have the return type specified as well
what Ancient Dragon said :D
I see, fixed it, thank you
Hello =)
I've implemented the SavingsAccount now too.
SavingsAccount.h
#include "Account.h"
#include <iostream>
#include "string.h"
using namespace std;
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
class SavingsAccount :virtual public Account {
public:
SavingsAccount();
void deposit(int); // for example 1%
void withdraw(int); // with penalty
};
#endif
SavingsAccount.cpp
#include "SavingsAccount.h"
SavingsAccount::SavingsAccount(){}
void SavingsAccount::deposit(int amount){
amount += amount/100; // adds 1% interest if you deposit into your savings account
Account::deposit(amount);
}
void SavingsAccount::withdraw(int amount){
amount +=amount/100; // 1% of the withdrawn money is added as penalty
Account::withdraw(amount);
}
and the main I used to test it:
main.cpp
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
using namespace std;
int main()
{
SavingsAccount *acc;
acc = new SavingsAccount;
acc->deposit(500);
acc->account_balance();
cout<<endl;
acc->withdraw(200);
acc->account_balance();
cout<<endl;
return 0;
}
However, I have a question here ... i used the keyword virtual, i am not quite sure do I have to use it on the functions themselves or I am allowed to use it for the entire class that I inherit? The confusing part for me is that the functions in Account are not declared as virtual but I can use them in SavingsAccount just by using virtual public Account?
Hey guys, How are you doing?
My name is Slavi and I am 22. I am currently studying Electronics and Computer engineering in Copenhagen, Denmark.
I am very excited to become part of DaniWeb's community. I am a very interested person in programming and I am taking every optional course that I can in some of the basic languages such as c++,java, c etc.
I will most probably continue my education on a master's level in computer science.
Well, thats about me looking forward to meet more people on here!
Hello everyone! I've read a lot of articles on DaniWeb and I've decided to join your community!
I have a university project to make a bank account system, which consists of at least 10 account classes, and 3 of them inherit from at least 2 other. The system has 1 base account "Account" and all other classes inherit from it. I'd like to share with you guys my progress and if anyone has any suggestions, please do post and let me know...
So far, my ideas are of classes - Account, SavingsAccount, Salary account, CardAccount, NetworkAccount, SharedAccount(so multiple people can withdraw money) ... and I am out of account ideas for now! If you have any let me know :)
I've just started and I have the Account class defined as follows
Account.h
#include <iostream>
#include "string"
using namespace std;
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account {
public:
Account();
int deposit(int);
int withdraw(int);
void account_balance()const;
private:
float balance;
};
#endif
Account.cpp
#include "Account.h"
#include <iostream>
using namespace std;
Account::Account() {balance = 0.0;}
int Account::deposit(int amount){
balance += amount;
return balance;
}
int Account::withdraw(int amount){
balance -= amount;
return balance;
}
void Account::account_balance()const{
cout<<balance;
}
And I have a main to test the account class
main.cpp
#include <iostream>
#include "Account.h"
using namespace std;
int main()
{
Account *acc;
acc = new Account;
acc->deposit(23);
acc->account_balance();
cout<<endl;
acc->withdraw(12);
acc->account_balance();
return 0;
}
I am wondering now if I need an interest method, to calculate …