27.11.14

Inheritence in C++ to check a Perfect Number (Excercise-19)

Write a Object Oriented C++ program using Inheritance to check whether a given number is perfect or not ?


#include<iostream>
using namespace std;
class perfect
{
     public:
          void setnum (int digit)
              {
                    number = digit;
               }
               protected: 
               int number;
};

class chknumber : public perfect
{
      public:
          int sum=0;
          void getperfect ( )
                 {
                       for ( int i=1; i<number; i++ )
                           {
                                if ( number%i = =0 )
                                     {
                                         sum += i;
                                     }
                            }
                   }
         int chksum( )
                {
                     if  (number = = sum)
                          cout << "Yes!!" << endl<< "the given number is perfect number" << endl << endl;
                     else
                          cout << "Not!!"<< endl << "the given number is not a perfect number" << endl;
                }
};

int main( )
{
     chknumber per;
     int digit;
     cout << "Enter a number to check perfect or not : ";
     cin >> digit;
     per.setnum(digit);
     per.getperfect();
     per.chksum();
     return 0;
}

C++ Definition : object oriented programming

Write answer for the following questions in comments. Give answer in short. Example as source code is preferable with each answer.


How is OOP important in C++?

What is abstract class?

What is this Pointer ? What is its significance?

What is the difference between while and do-while loop?

Why main() function is important in C++?

What is type casting in C++?


What is OOP?

What is the type conversion in C++

What is the difference between local variable and global variable.

Show Inheritance with at least two derived class

Show Data Abstraction and data Encapsulation

Describe Polymorphism with Example

 

Excercise-18 : Recursive Function Progamming



Write a program using recursive function in C++ to find factorial of a given integer number.

Excercise-17 : Function Progamming


Write a program using function to Sum of all Odd numbers from an Array. Use function prototype and parameter

OOP Excercise-16 : Array Progamming



Search an element in an Array of 20 integer values.
      (i) Use one Constructor to get input on variable and array.
(ii) Use one Constructor to Search the Array.
(iii) Use a member function to display the result.
(iv) Use Destructor in any suitable position.

OOP Excercise-15 : Banking System



Define a class to represent a bank account which includes following members:
Data members –   i) Name
ii) Account number
iii) Type of account
iv) Balance Amount
Member functions –
a. To assign initial value
b. To deposit an account
c. To withdraw from an account
                                    d. To display name, account number & balance

23.11.14

Excercise-14 : Count the number of character


Write a c++ program to count number of character in a given string

Excercise-13 : Find ODD or EVEN


Write a c++ program to check whether the given number is odd or even

Function : Excercise-12 : Sum of all even elements from an Array


Write a program of function to Sum of all even elements from an Array. The initial value of the array must take from main ( ) as input

Function : Excercise-11 : recursive function to fill an Integer Array of 5 Elements


Write a program of recursive function in C++ to fill an Integer Array of 5 Elements. After fill the array print/show all elements using recursive function. Take array and size of the array from main() body.
You may follow the below page to solve this problem:
http://c-programming-practice.blogspot.com/2013/06/c-function-to-insert-element-in-array.html

OOP : Excercise-10 : Check palindrome. Use Inheritance


Check whether the given number is palindrome or not. Use individual/separate member function to take input, output and display according to logic. Use Inheritance

OOP : Excercise-9 : Program to find area of triangle, circle, and rectangle using function overloading


Write a C++ program to find area of triangle, circle, and rectangle using function overloading