Debugging the classes
Mar 1, 2014 at 8:40pm UTC
I am making a bank account program using classes. I have defined the classes so far. Just want to know if everything is OK so far. Please please check and see if there is any kind of error in the classes, dont know why but i have a feeling that something is wrong.
Name.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* Name Class Specification */
#ifndef NAME_H
#define NAME_H
#include <string>
using namespace std;
//Name class declarations
class Name {
string last;
string first;
public :
// mutators (or setter member functions)
void setLastname(string);
void setFirstname(string);
// accessors (or getter member functions)
string getLastname() const ;
string getFirstname() const ;
};
#endif
Name.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* Name Class Implementation */
#include <string>
#include "Name.h"
using namespace std;
void Name::setLastname(string lastname)
{
last = lastname;
return ;
}
void Name::setFirstname(string firstname)
{
first = firstname;
return ;
}
string Name::getLastname() const
{
return (last);
}
string Name::getFirstname() const
{
return (first);
}
Depositor.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef DEPOSITOR_H
#define DEPOSITOR_H
#include<string>
#include"Name.h"
using namespace std;
class Depositor{
Name name;
char SSN;
public :
void setName(string lastname, string firstname);
void setSSN(char SSN);
Name getName() const ;
char getSSN() const ;
};
#endif
Depositor.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <string>
#include "Depositor.h"
using namespace std;
void Depositor::setName(string lastname, string firstname)
{
name.setLastname(lastname);
name.setFirstname(firstname);
return ;
}
void Depositor::setSSN(char ssn)
{
SSN = ssn;
return ;
}
Name Depositor::getName() const
{
return (name);
}
char Depositor::getSSN() const
{
return (SSN);
}
Account.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include"Depositor.h"
using namespace std;
class Account{
Depositor depositor;
char acc_num;
double acc_bal;
char acc_type;
public :
// mutators (or setter member functions)
void setdepositor(Depositor);
void setacc_num(char );
void setacc_bal(double );
void setacc_type(char );
// accessors (or getter member functions)
Depositor getdepositor() const ;
char getacc_num() const ;
double getacc_bal() const ;
char getacc_type() const ;
};
#endif
Account.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include "Account.h"
using namespace std;
void Account::setdepositor(Depositor depo)
{
depositor = depo;
return ;
}
void Account::setacc_num(char Acc_Num)
{
acc_num = Acc_Num;
return ;
}
void Account::setacc_bal(double Acc_Bal)
{
acc_bal = Acc_Bal;
}
void Account::setacc_type(char Acc_Type)
{
acc_type = Acc_Type;
}
Depositor Account::getdepositor() const
{
return (depositor);
}
char Account::getacc_num() const
{
return (acc_num);
}
double Account::getacc_bal() const
{
return (acc_bal);
}
char Account::getacc_type() const
{
return (acc_type);
}
Last edited on Mar 2, 2014 at 12:11am UTC
Mar 1, 2014 at 9:43pm UTC
Well, the return statements in the void functions are unnecessary.
Why don't you write a couple of test cases to test the code out yourself?
Topic archived. No new replies allowed.