I'm writing the following program.
Write a class called CAccount which contains two private data elements, an integer accountNumber and a floating point accountBalance, and three member functions:
A constructor that allows the user to set initial values for accountNumber and accountBalance and a default constructor that prompts for the input of the values for the above data members.
A function called inputTransaction, which reads a character value for transactionType ('D' for deposit and 'W' for withdrawal), and a floating point value for transactionAmount, which updates accountBalance.
A function called printBalance, which prints on the screen the accountNumber and accountBalance.
--
#include <iostream>
using namespace std;
class CAccount{
public:
CAccount(){
setValues(2, 5);
printBalance();
inputTransaction();
printBalance();
}
void setValues(int aN, int aB);
void inputTransaction();
void printBalance();
private:
int accountNumber;
float accountBalance;
};
void CAccount::setValues(int aN, int aB){
accountNumber = aN;
accountBalance = aB;
}
void CAccount::inputTransaction(){
char transactionType;
float transactionAmount;
cout << "Type of transaction? D - Deposit, W - Withdrawal" << endl;
cin >> transactionType;
cout << "Input the amount you want to deposit/withdraw" << endl;
cin >> transactionAmount;
if(transactionType == 'D'){
accountBalance += transactionAmount;
}
else if(transactionType == 'W'){
accountBalance -= transactionAmount;
}
}
void CAccount::printBalance(){
cout << "Account number : " << accountNumber << endl << "Account balance : " << accountBalance << endl;
}
int main ()
{
CAccount client;
}
I don't understand this part :
1. A constructor that allows the user to set
initial values for accountNumber and
accountBalance and a default constructor
that prompts for the input of the values for
the above data members.
What exactly is the difference between a constructor and default constructor, I'm kinda confused on this step.
Other than that, I would like to ask people with more experience to tell me any tips I should follow when coding with classes and which mistakes to avoid (this is my first class I ever wrote in C++).