New class:help constructor init. string before obj

Thread Starter

Ruby

Joined Oct 29, 2009
6
Hi. New to classes, old in most procedures. Classes just thrown the monkey wrench on the gears. My new project is 4 files: a header customer.h, loan.h, an object file client.cpp, and loan_Main.cpp.
The loan class needs customer name and ID(Client::ID), so I try to access them through public functions with "LoanID = Client.getPin(); and CliName[35] = Client.getName();" The compiler error is: "assignment must be for an especific object"-not exactly that, but it is the meaning that I get. So I have tried creating a demo object, right at the Client class constructor, to initialize Name[35], and Pin-a 4 char array, with no success at all. Delved into every book I own, but all I'm still stocked on this. Surely missing some of the rules. It looks like it needs to have a Client object before Name could be called or referenced to. I'm using Visual Studio Pro, version 2010. Any ideas would be highly appreciated.:confused:

Rich (BB code):
class Loan
    {
    private:
        double loanAmount;
        int numberPayments;        
        float annualInterest;
    public:
        int loan();//construct
        double setLoanAmount;
        int setnumberPayments;        
        float setannualInterest;
        double getLoanAmount();
        int getnumberPayments();
        float getannualInterest();
        float CalcmonthlyInterest();
        double CalcPayment(int, float, double);
        double CalcamountoPay();
        char getLoanID(){
        char LoanID[4] = Client.getPin();}//get PIN from Client
        char getcustomerName(){
        char CliName[35] = Client.getName();}//get customer name from Client
        Loan::~Loan();
class Client
    {
    private:
        char Name[NameSize];
        char Pin[PinSize];
        char address[AddresSize];
        char Phone[PhoneSize];
        double Payment;
    public:
        Client &DemoClient;
        void DemoClient(){char Nam[NameSize] = {" "};//start constructor
            for (int i = 0; i < NameSize; i++){
                Name = Nam;}}

        char Client::setName(){
            cout<<"\nEnter Customer name: ";
            cin>>Name; cin.ignore();}
        char Client::setPin(){
            cout<<"\nEnter Personal Identification Number (PIN): ";
            cin>>Pin;
            int count = 0;
            for(int i = 0; i < 4; i++){
                if(Pin < 0 || Pin > 9){
                    count++;}
                while(count > 0){i = 0;
                cout<<"\nInvalid PIN. Enter a VALID PIN: ";
                cin>>Pin[4];}
                }
            cout<<"PIN accepted ";}
        char Client::setAddress(){
            cout<<"\nEnter Customer address: ";
            cin>>address; cin.ignore();}
        char Client::setPhone(){cout<<"\nEnter home telephone number: ";
        cin>>Phone;}
        char Client::getName(){return Name[NameSize];}
        char Client::getPin(){return Pin[PinSize];}
        char Client::getAddress(){return address[50];}
        char Client::getPhone(){return Phone[10];}
        
    }//end Customer class
 
Last edited by a moderator:

Thread Starter

Ruby

Joined Oct 29, 2009
6
Sorry to disturb once again. There was an error on this function loop, which is used to validate user input for PIN. The loop before was using a while loop, after detecting a bad pin character. But the while loop had no way to reset, so it would loop forever... DON'T RUN, I MEAN DO NOT COMPILE IT! Here it is corrected, with an if conditional statement, which breaks at the end, returning to the for loop, with counter "i" reset to zero::D

Rich (BB code):
   char Client::setPin(){
            cout<<"\nEnter Personal Identification Number (PIN): ";
            cin>>Pin;
            int count = 0;
            for(int i = 0; i < 4; i++){
                if(Pin < 0 || Pin > 9){
                    count++;}
                if(count > 0){i = 0;
                cout<<"\nInvalid PIN. Enter a VALID PIN: ";
                cin>>Pin[4];}
                }
            cout<<"PIN accepted ";}
 
Last edited by a moderator:
Top