Sunday, February 24, 2008

Programming, and other Interests

Just finished writing a little program in C++. After a while of painstaking research, I managed to finish this piece of code in under 2 hours.

Account.h
//Account Header
//This file defines the Account class, all
//of its member functions and data members.

#include
// many apologies but there should be a "<" followed by "iostream" followed by ">". Blogger screws it up.

using std::cout;
using std::cin;
using std::endl;

int balance;
int accountBalance;
int credit;
int debit;

//Account Class
class Account
{
public:
//Constructor (creates an account with an initial balance)
Account( int balance )
{
setAccountBalance( balance );
}
//End Constructor

//setAccountBalance (associates balance with accountBalance)
void setAccountBalance( int balance )
{
accountBalance = balance;
if ( balance < balance =" 0;">> credit;
creditAccountBalance( credit );
}
else
{
accountBalance = accountBalance + credit;
}
}
//End creditAccountBalance

//debitAccountBalance (removes value from balance)
void debitAccountBalance ( int debit )
{
if ( debit <>> debit;
};

if ( accountBalance <>> debit;
debitAccountBalance( debit );
};

if ( accountBalance >= debit )
{
( accountBalance = accountBalance - debit );
};
}
//End debitAccountBalance
};

Account.cpp
//Account Code
//This code simulates the actions of an ATM machine.
//Due to my inexperience, I have yet to learn how to
//make the number of accounts and their names a
//variable controlled by the client. Hence, there are
//simply 2 pre-generated accounts, with transactions
//executing serially, first on account1, then account2.

//I have yet to learn to let the program verify the
//integrity of the type of input, only whether the
//input, if an integer, is positive or negative.

#include
// many apologies but there should be a "<" followed by "iostream" followed by ">". Blogger screws it up.
#include "Account.h"

int main()
{
//Account1 Transactions Begin
cout << "Enter a positive integer to create Account1.\n"; cin >> balance;
Account account1( balance );
cout << "Account1's balance is " <<>> credit;
account1.creditAccountBalance( credit );
cout <<>> debit;
account1.debitAccountBalance( debit );
cout << "Account1's balance is " <<>> balance;
Account account2( balance );
cout << "Account2's balance is " <<>> credit;
account2.creditAccountBalance( credit );
cout <<>> debit;
account2.debitAccountBalance( debit );
cout << "Account2's balance is " <<>
//End Account2 Transactions

return 0;
}

Haha, at the very least, it works ;)

Blogger is screwing with the way my code looks and is munching on some of the important bits. Don't try and compile this. It's not going to work for you, unless you know how to code and can find and fix the errata. :)

I've been wondering. I've taken up so many interests now: digital art, programming, cardistry, violin... Can I handle them all? Coupled with school it's going to be a toughie, no doubt. But if I get into Computing in JC, then there's programming taken care of. And I'm in taekwondo in my school, so, that's done too. I suppose it will all work out. Hopefully.

Give me some encouragement, people :(

No comments: