0% found this document useful (0 votes)
55 views

Object Oriented Programming Assignment 3: Questions

This document provides an assignment on object-oriented programming in C++. It asks the student to: 1. Create a BankAccount class with data members for the name and account number of the depositor. It should include member functions to deposit, withdraw, and display the name and balance. 2. List the differences between call by value and call by reference, and between structures and classes in C++. The document then provides an implementation of the BankAccount class with the requested data members and member functions. The main function demonstrates creating an object of this class and calling its member functions.

Uploaded by

Muhammad Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Object Oriented Programming Assignment 3: Questions

This document provides an assignment on object-oriented programming in C++. It asks the student to: 1. Create a BankAccount class with data members for the name and account number of the depositor. It should include member functions to deposit, withdraw, and display the name and balance. 2. List the differences between call by value and call by reference, and between structures and classes in C++. The document then provides an implementation of the BankAccount class with the requested data members and member functions. The main function demonstrates creating an object of this class and calling its member functions.

Uploaded by

Muhammad Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming

Assignment 3
Questions:

1. Create a class to represent a bank account , include the following members:


1. Data members:
                                                              i.      Name of the depositor
                                                            ii.      Account number
2. Member functions
                                                              i.      Deposit an amount
                                                            ii.      Withdraw an amount
                                                          iii.      Display name and balance

#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

class bank
{
        int acno;
        char nm[100], acctype[100];
        float bal;  
   public:
        bank(int acc_no, char *name, char *acc_type, float
balance)  //Parameterized Constructor
        {
                acno=acc_no;
                strcpy(nm, name);
                strcpy(acctype, acc_type);
                bal=balance;
        }
        void deposit();
        void withdraw();
        void display();
};
void bank::deposit()   //depositing an amount
{
        int damt1;
        cout<<"\n Enter Deposit Amount = ";
        cin>>damt1;
        bal+=damt1;
}
void bank::withdraw()  //withdrawing an amount
{
        int wamt1;
        cout<<"\n Enter Withdraw Amount = ";
        cin>>wamt1;
        if(wamt1>bal)
                cout<<"\n Cannot Withdraw Amount";
        bal-=wamt1;
}
void bank::display()  //displaying the details
{
        cout<<"\n ----------------------";
        cout<<"\n Accout No. : "<<acno;
        cout<<"\n Name : "<<nm;
        cout<<"\n Account Type : "<<acctype;
        cout<<"\n Balance : "<<bal;  
}
int main()
{
        int acc_no;
        char name[100], acc_type[100];
        float balance;
        cout<<"\n Enter Details: \n";
        cout<<"-----------------------";
        cout<<"\n Accout No. ";
        cin>>acc_no;
        cout<<"\n Name : ";
        cin>>name;
        cout<<"\n Account Type : ";
        cin>>acc_type;
        cout<<"\n Balance : ";
        cin>>balance;
  
        bank b1(acc_no, name, acc_type, balance);  //object is created
        b1.deposit(); //
        b1.withdraw(); // calling member functions
        b1.display(); //
        return 0;
}

2. List the difference between


1. Call by value & call by reference
2. Structure and class

Class Structure

Class is a reference type. Structure is a value type.

In class, object is created on the heap In structure, object is created on the stack
memory. memory.

It supports inheritance. It does not support inheritance.

It includes all types of constructors and It includes only parameterized constructors.


destructors.

Object can be created using new keyword. Object can be created without using


For eg. Test t = new Test(); the new keyword.
For eg. Test t;

The member variable of class can be The member variable of structure cannot be
initialized directly. initialized directly.

You might also like