Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: another programming assignment

  1. #1
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Exclamation another programming assignment

    Greetings,

    I hope someone can help me. i have this C++ assignment to do i hav evryting else lock but i am not gettin the constructor part. see question below.

    Define a class to represent a bank account. Include the following members.
    Data members
    a. name of the depositor
    b. account number
    c. type of account (savings or current)
    d. balance amount in the account

    Write member functions to:
    a) assign initial values depending on the type of account (use constructor). Assume initial balance is $500 in the case of savings, $1000 in the case of current account.
    (this part especially is giving me a hard time)

    well the rest of the question is asking to write functions to deposit, withdraw and display and i know what to do there basically an it also mentioned to write a main program to achieve the above functionalities.

    please help! the code is below

    Code:
    //Kemar Lee
    //Module No. 1
    //Assignment # 1
    //Solution to Question 1
    //Lecturer: Narsi Bathula
    
    #include<iostream.h>
    #include<stdio.h>
    using namespace std;
    
    //Statement of Class....
    class bankacc
    {
                 char name[15], sav_type[2], cur_type[2];
                 int acco, bal;
                 
          
          public:
                 bankacc();
                 bankacc(char[], char[]);
                 
                 void readdata();
                 void deposit();
                 void withdraw();
                 void display();
    };
    
    //Statement of null constructor and constructor
         bankacc::bankacc()
         {}
         bankacc::bankacc(char sav[] = 500, char cur[] = 1000)
         {
                 strcpy(sav_type, sav);
                 strcpy(cur_type, cur);
                              
                               }
     
    
    
    // Statement of customer information...                           
    void bankacc::readdata()
    {
        char s[1], c[1];
        
        cout<<" Enter the name of customer:- "<<endl;
        cin>>name;
        cout<<" Enter account no:- "<<endl;
        cin>>acco;
        cout<<" Enter opening balance:- "<<endl;
        cin>>bal;
        
        if(sav_type == "s")
         {
              cout<<" Enter savings amount:- "<<endl;
              cin>>s;
              }
        else
        {
            cout<<" Enter current amount:- "<<endl;
            cin>>c;
            }                         
    }
    
     // Statement of deposit function...            
    void bankacc::deposit()
    {
         int dep;
                        
         cout<< "Enter amount you wish to be deposited: "<<endl;
         cin<<dep;
                        
         bal = bal + dep;
    }
    
    
    //Statement of Withdrawal function...
    void bankacc::withdraw()
    {
          int wd
                        
                        cout<< "Enter amount you wish to be withdrawn: "<<endl;
                        cin>>wd;
                        
                        while( bal < wd )
                        {
                               cout<<"Sorry, Insufficient Balance"<<endl;
                               
                               cin>>wd;
                               }
                               
                        bal = bal - wd;     
    }
    
    // Statement of display Funtion...
    void bankacc::display()
    {
                        cout<<"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
                        cout<<"\n%                                               %";                      
                        cout<<"\n%                                               %";
                        cout<<"\n     Name:         %"<<name;                   
                        cout<<"\n%                                               %";
                        cout<<"\n     Balance:      %$"<<bal;                     
                        cout<<"\n%                                               %";
                        cout<<"\n%                                               %";
                        cout<<"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
                  
         }
    
      
    // statement of Main Function....   
    int main()
    {
      bankacc 
      
      getchar();
      getchar();
        }
    yea thts all i have now. Thanks in advance.
    Kemar Lee

  2. #2
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    Code:
    bankacc obj("firsword","secondword");
    would declare a bankacc object called obj and call the second constructor to set the initial values of sav_type and cur_type
    1337

  3. #3
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Default

    @wiel

    Thanks for responding.

    Pertain to ma code, where's the best place to put it?
    Kemar Lee

  4. #4
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    inside main
    int main(){bankacc obj("firsword","secondword");}
    1337

  5. #5
    Join Date
    Jun 2008
    Posts
    74
    Rep Power
    0

    Default

    A start:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    enum Account_type {
    	SAVINGS = 0,
    	CURRENT
    };
    
    class Bank_account
    {
    	private:
    		string name;
    		int account_number;
    		Account_type type;
    		double balance;
    	public:
    		Bank_account(string name, int account_number, int type) {
    			this->name           = name;
    			this->account_number = account_number;
    			this->type           = (type == 0) ? SAVINGS : CURRENT;
    
    			if(this->type == SAVINGS) {
    				this->balance = 500.00;
    			} else {
    				this->balance = 1000.00;
    			}
    		}
    
    		~Bank_account() {
    		}
    		
    		void set_name(string name) {
    			this->name = name;
    		}
    
    		void set_account_number(int account_number) {
    			this->account_number = account_number;
    		}
    
    		void deposit(double amount) {
    			this->balance += amount;
    		}
    
    		void withdraw(double amount) {
    			if((this->balance - amount) < 0) {
    				cout << "Insufficient funds. You can withdraw a maximum of $" << this->balance << endl;
    				return;
    			}
    			this->balance -= amount;
    		}
    
    		void display() {
    			cout << "Name: " << this->name << endl;
    			cout << "Account type: " << ((this->type == SAVINGS) ? "Savings" : "Current") << endl;
    			cout << "Balance: " << this->balance << endl;
    		}
    };
    
    int main()
    {
    	
    	return 0;
    }

  6. #6
    Join Date
    Dec 2010
    Posts
    256
    Rep Power
    0

    Default

    Quote Originally Posted by jayrulez View Post
    A start:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    enum Account_type {
    	SAVINGS = 0,
    	CURRENT
    };
    
    class Bank_account
    {
    	private:
    		string name;
    		int account_number;
    		Account_type type;
    		double balance;
    	public:
    		Bank_account(string name, int account_number, int type) {
    			this->name           = name;
    			this->account_number = account_number;
    			this->type           = (type == 0) ? SAVINGS : CURRENT;
    
    			if(this->type == SAVINGS) {
    				this->balance = 500.00;
    			} else {
    				this->balance = 1000.00;
    			}
    		}
    
    		~Bank_account() {
    		}
    		
    		void set_name(string name) {
    			this->name = name;
    		}
    
    		void set_account_number(int account_number) {
    			this->account_number = account_number;
    		}
    
    		void deposit(double amount) {
    			this->balance += amount;
    		}
    
    		void withdraw(double amount) {
    			if((this->balance - amount) < 0) {
    				cout << "Insufficient funds. You can withdraw a maximum of $" << this->balance << endl;
    				return;
    			}
    			this->balance -= amount;
    		}
    
    		void display() {
    			cout << "Name: " << this->name << endl;
    			cout << "Account type: " << ((this->type == SAVINGS) ? "Savings" : "Current") << endl;
    			cout << "Balance: " << this->balance << endl;
    		}
    };
    
    int main()
    {
    	
    	return 0;
    }
    this look like a mr narsi special :P ahh boy....... all now the assignment stays the same

    u get the cricketer one as yet? or the library?
    Dip,Bsc,CCNA,CCSP,MCP.. Up next MCSA WINDOWS 8, CCNA SECURITY,CCNP SWITCH,
    CCNA SEEKING AN OPPORTUNITY
    Theres no Friend Like Google..........

  7. #7
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Default

    @wiel

    I tried it but when i run the program, theres nothing telling me to input something.

    @ crazeeplayer

    I got both those questions, the cricketer and the library thing lol.

    @ jayrulez

    This example is a pointer example right?
    Last edited by Arch_Angel; Oct 2, 2012 at 04:37 PM. Reason: merged multiple posts
    Kemar Lee

  8. #8
    Join Date
    Dec 2010
    Posts
    256
    Rep Power
    0

    Default

    Quote Originally Posted by pweezy-f View Post
    @ crazeeplayer

    I got both those questions, the cricketer and the library thing lol.

    mr narsi ah di boss..... same thing time and time again is a pity me caan find di ol assignment dem......

    u get any mock exam yet
    Dip,Bsc,CCNA,CCSP,MCP.. Up next MCSA WINDOWS 8, CCNA SECURITY,CCNP SWITCH,
    CCNA SEEKING AN OPPORTUNITY
    Theres no Friend Like Google..........

  9. #9
    Join Date
    Jun 2008
    Posts
    74
    Rep Power
    0

    Default

    @ jayrulez

    This example is a pointer example right?
    I don't quite understand that question.

    Only the class is implemented. You need to write code to use it.
    Last edited by jayrulez; Oct 2, 2012 at 06:42 PM.

  10. #10
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Default

    @ crazeeplayer

    no mock exams yet. Btw wat year did u do OOP?
    Kemar Lee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •