ZenithMkII's Profile User Rating: -----

Reputation: 3 Apprentice
Group:
Members
Active Posts:
49 (0.07 per day)
Joined:
06-September 12
Profile Views:
202
Last Active:
User is offline Nov 02 2012 02:41 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   ZenithMkII has not set their status

Posts I've Made

  1. In Topic: Changing a value through polymorphism (Abstract classes/functions)

    Posted 1 Nov 2012

    I've come up with a way to get this working, but I do not know if i am losing/gaining money from the multiplication of the int64_t balance and double interest, but here is what I have so far.

    main.cpp
    #include "ServiceChargeChecking.h"
    #include "NoServiceChargeChecking.h"
    
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	BankAccount *accountList[2];
    
    	accountList[0] = new ServiceChargeChecking("Sharon Osmod", 10023, 2000);
    	accountList[1] = new NoServiceChargeChecking("Billy Mays", 10024, 5000);
    
    	cout << "January\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->print();
    	}
    
    	cout << "February\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    
    	cout << "March\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    
    	cout << "April\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    
    	cout << "May\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    
    	cout << "June\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    
    	cout << "July\n\n";
    
    	for(int i = 0; i < 2; i++){
    		accountList[i]->createMonthlyStatements();
    		accountList[i]->print();
    	}
    }
    
    BankAccount.h
    #ifndef BANKACCOUNT_H
    #define BANKACCOUNT_H
    
    #include <iostream>
    #include <cstdint>
    
    using namespace std;
    
    class BankAccount{
    private:
    	int accountNumber;
    	string name;
    	int64_t balance;
    public:
    	BankAccount(string nam, int accNum, double bal);
    	void setName(string nam);
    	void setAccountNumber(int accNum);
    	void setBalance(double bal);
    	string getName() const;
    	int getAccountNumber() const;
    	double getBalance() const;
    	void deposit(double dep);
    	void withdraw(double with);
    	virtual void createMonthlyStatements();
    	virtual void print() = 0;
    };
    
    #endif
    
    BankAccount.cpp
    #include "BankAccount.h"
    
    #include <iostream>
    
    using namespace std;
    
    BankAccount::BankAccount(string nam, int accNum, double bal){
    	name = nam;
    	accountNumber = accNum;
    	balance = bal * 1000;
    }
    
    void BankAccount::setName(string nam){
    	name = nam;
    }
    
    void BankAccount::setAccountNumber(int accNum){
    	accountNumber = accNum;
    }
    
    void BankAccount::setBalance(double bal){
    	balance = bal * 1000;
    }
    
    string BankAccount::getName() const{
    	return name;
    }
    
    int BankAccount::getAccountNumber() const{
    	return accountNumber;
    }
    
    double BankAccount::getBalance() const{
    	double bal = static_cast<double>(balance);
    	return bal / 1000;
    }
    
    void BankAccount::deposit(double dep){
    	balance += dep * 1000;
    }
    
    void BankAccount::withdraw(double with){
    	balance -= with * 1000;
    }
    
    void BankAccount::createMonthlyStatements(){
    
    }
    
    void BankAccount::print(){
    
    }
    
    
    CheckAccount.h
    #ifndef CHECKACCOUNT_H
    #define CHECKACCOUNT_H
    
    #include "BankAccount.h"
    
    #include <iostream>
    
    using namespace std;
    
    class CheckAccount : public BankAccount{
    private:
    public:
    	CheckAccount(string nam, int accNum, double bal);
    	void writeCheck();
    	virtual void createMonthlyStatements();
    	virtual void print() = 0;
    };
    
    #endif
    
    CheckAccount.cpp
    #include "CheckAccount.h"
    
    #include <iostream>
    
    using namespace std;
    
    CheckAccount::CheckAccount(string nam, int accNum, double bal)
    : BankAccount(nam, accNum, bal){
    
    }
    
    void CheckAccount::writeCheck(){
    	cout << "Write Check.\n\n";
    }
    
    void CheckAccount::createMonthlyStatements(){
    
    }
    
    void CheckAccount::print(){
    
    }
    
    ServiceChargeChecking.h
    #ifndef SERVICECHARGECHECKING_H
    #define SERVICECHARGECHECKING_H
    
    #include "CheckAccount.h"
    
    class ServiceChargeChecking: public CheckAccount{
    private:
    	int checkLimit;
    	double minimumBalance;
    	double interest;
    public:
    	ServiceChargeChecking(string nam, int accNum, double bal);
    	int getCheckLimit() const;
    	double getMinimumBalance() const;
    	double getInterest() const;
    	virtual void createMonthlyStatements();
    	virtual void print();
    };
    
    #endif
    
    ServiceChargeChecking.cpp
    #include "ServiceChargeChecking.h"
    
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    
    
    ServiceChargeChecking::ServiceChargeChecking(string nam, int accNum, double bal)
    : CheckAccount(nam, accNum, bal){
    	minimumBalance = 0.0;
    	checkLimit = 10;
    	interest = 0.0;
    }
    
    int ServiceChargeChecking::getCheckLimit() const{
    	return checkLimit;
    }
    
    double ServiceChargeChecking::getMinimumBalance() const{
    	return minimumBalance;
    }
    
    double ServiceChargeChecking::getInterest() const{
    	return interest;
    }
    
    void ServiceChargeChecking::createMonthlyStatements(){
    
    }
    
    void ServiceChargeChecking::print(){
    	cout << "--------------Service Charge Checking--------------\n"
    		 << "Account Holder: " << BankAccount::getName() << endl
    		 << "Account Number: " << BankAccount::getAccountNumber() << endl
    		 << "Balance: " << fixed << setprecision(2) << BankAccount::getBalance() << endl
    		 << "Minimum Balance: " << fixed << setprecision(2) << getMinimumBalance() << endl
    		 << "Check Limit: " << getCheckLimit() << endl
    		 << "Interest: " << fixed << setprecision(3) << getInterest() << endl << endl;
    }
    
    
    NoServiceChargeChecking.h
    #ifndef NOSERVICECHARGECHECKING_H
    #define NOSERVICECHARGECHECKING_H
    
    #include "CheckAccount.h"
    
    class NoServiceChargeChecking: public CheckAccount{
    private:
    	int checkLimit;
    	int64_t minimumBalance;
    	double interest;
    public:
    	NoServiceChargeChecking(string nam, int accNum, double bal);
    	void setCheckLimit(int chkLim);
    	void setMinimumBalance(double minBal);
    	void setInterest(double in);
    	int getCheckLimit() const;
    	double getMinimumBalance() const;
    	double getInterest() const;
    	virtual void createMonthlyStatements();
    	virtual void print();
    };
    
    #endif
    
    NoServiceChargeChecking.cpp
    #include "NoServiceChargeChecking.h"
    
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    
    
    NoServiceChargeChecking::NoServiceChargeChecking(string nam, int accNum, double bal)
    : CheckAccount(nam, accNum, bal){
    	minimumBalance = 300.0;
    	checkLimit = 0;
    	interest = 0.0008;
    }
    
    void NoServiceChargeChecking::setCheckLimit(int chkLim){
    	checkLimit = chkLim;
    }
    
    void NoServiceChargeChecking::setMinimumBalance(double minBal){
    	minimumBalance = minBal * 1000;
    }
    
    void NoServiceChargeChecking::setInterest(double in){
    
    }
    
    
    int NoServiceChargeChecking::getCheckLimit() const{
    	return checkLimit;
    }
    
    double NoServiceChargeChecking::getMinimumBalance() const{
    	double minBal = static_cast<double>(minimumBalance);
    	return minBal / 1000;
    }
    
    double NoServiceChargeChecking::getInterest() const{
    	return interest;
    }
    
    void NoServiceChargeChecking::createMonthlyStatements(){
    	setBalance(getBalance() * (1 + interest));
    }
    
    void NoServiceChargeChecking::print(){
    	cout << "------------No Service Charge Checking------------\n"
    		 << "Account Holder: " << getName() << endl
    		 << "Account Number: " << getAccountNumber() << endl
    		 << "Balance: " << fixed << setprecision(2) << getBalance() << endl
    		 << "Minimum Balance: " << fixed << setprecision(2) << getMinimumBalance() << endl
    		 << "Check Limit: " << getCheckLimit() << endl
    		 << "Interest: " << fixed << setprecision(3) << getInterest() << endl << endl;
    }
    
    
  2. In Topic: Changing a value through polymorphism (Abstract classes/functions)

    Posted 1 Nov 2012

    Thank you for your input. I did not grasp the idea of inheritance. As for balance, I have read that using a signed integer would be best and moving it two significant numbers up. What I have been doing is erasing all the instances where I have reoccurring code and just letting inheritance fill in the gaps. I will post up new code once I have it done.
  3. In Topic: C++ program doesn't execute correctly!

    Posted 23 Oct 2012

    Instead of testing for both the uppercase and lowercase letters you could use toupper() to make everything uppercase. Then all you would need to do is check for the uppercase stuff. Also a switch statement would help a lot. Then anything that wasn't on your list you can handle with the switch's default part. Just some suggestions.
  4. In Topic: 2 Errors with Tic-Tac-Toe Game

    Posted 23 Oct 2012

    I fixed the first error by adding a return isWon; in the if statement.
    if(isWon){
    	cout << "\nPlayer " << ch << " has won!\n";
    	return isWon;
    }
    
    
  5. In Topic: 2 Errors with Tic-Tac-Toe Game

    Posted 23 Oct 2012

    Thank you Jim for helping with the second error I had. That was a small error I had missed. Thanks for the quick reply. I will be working on the first error. If someone does find it before me, thanks in advanced.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

ZenithMkII hasn't added any friends yet.

Comments

ZenithMkII has no profile comments yet. Why not say hello?