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

19.11.14

OOP : Excercise-8 : Check whether the given number is palindrome or not. Use individual member function to take input, output and display. Use Inheritance

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

//Program using Constructor
#include<iostream>
using namespace std;
class checkpelindrom
{
int num;
public:
checkpelindrom();
~checkpelindrom();
void view();
};
checkpelindrom :: checkpelindrom()
{
cout<<"Enter the number\n";
cin>>num;
}
checkpelindrom :: ~checkpelindrom()
{
//cout<<"\n\nDestruction";
}
void checkpelindrom :: view()
{
int a ,temp ,rev=0;
temp=num;
while(temp!=0)
{
a=temp%10;
rev=rev*10+a;
temp /=10;
}
if(rev==num)
cout<<"\nIt is a pelindrom number\n\n";
else
cout<<"\nIt is not a pelindrom number\n\n";

}
int main()
{
checkpelindrom cp;
cp.view();
return 0;

}

OOP : Excercise-7 : Search an element in an Array of 10 integer values. Use Constructor and Destructor with Class

Search an element in an Array of 10 integer values. Use Constructor and Destructor with Class

9.11.14

OOP : Excercise-6 : Write a Object Oriented Program to Display Studnet Information

Create a class named as Student containing the following data members:
--Roll_no
--Name
--Marks1, Marks2, Marks3
Write necessary member functions:
1. to accept details of all students
2. to display details of one student
3. to display details of all students(Use Function overloading).
 (Use Function overloading)

OOP : Excercise-5 : Check Whether the given number is Strange or Not.

Note: Use Inheritance to solve this program.

//check strange number using inheritance
‪#‎include‬<iostream>
using namespace std;
//base class
class strange
{
public:
void setdigit(int d)
{
digit=d;
}
protected:
int digit;
};
//derived class
class number : public strange
{
public:
int i,j,t=1,d;
int devide()
{
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
i=j;
}
}
}
}
int check()
{
if(t==1)
cout<<"this number is strange";
else
cout<<"this number is not strange";
}
};
int main()
{
number nmb;
int a;
cin>>a;
nmb.setdigit(a);
nmb.check();
}

Function : Excercise-4.2 : Check Whether the given number is Strange or Not.

[Use user defined function to solve this problem]

#include<iostream>
using namespace std;
int chkstrange(int digit);
int main()
{
int digit,p;
cout<<"Enter Number to Check: ";
cin>>digit;
p= chkstrange(digit);
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}
//function start here
int chkstrange(int digit)
{
int temp,rem,temp2=1;
while(digit!=0)
{
temp=digit/10;
rem=digit%10;
digit=temp;
for(int i=2;i<rem;i++)
    {
    if (rem%i ==0)
    {
    temp2= 0;
    i=rem;
    }
    }   
}
return temp2;
}

18.10.14

OOP : Excercise-4.1 : C++ 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

OOP : Excercise-3 : C++ program to calculate simple interest amount use default value for rate

Write a C++ program using class to calculate simple interest amount use default value for rate.


//1. calculate simple interset in cpp
‪#‎include‬<iostream>
using namespace std;
main()
{
float SI=0,p,t,r;
cin>>p>>t>>r;
SI=((p*t*r)/100);
cout<<SI;
}


//2. calculate simple interest using function

‪#‎include‬<iostream>
using namespace std;
float interest(float p,float t,float r);
main()
{
float p,t,r,SI=0;
cin>>p>>t>>r;
interest(p,t,r);
}
float interest(float a,float b,float c)
{
float SI;
SI=((a*b*c)/100);
cout<<SI;
}


//3. calculate simple interest in oop. Use member variable and member function as required
‪#‎include‬<iostream>
using namespace std;
class interest
{
public:
float p,t,r;
void get_value()
{
cin>>p>>t>>r;
}
void cal_value()
{
float SI;
SI=((p*t*r)/100);
cout<<SI;
}
};
main()
{
interest in;
in.get_value();
in.cal_value();
}

OOP : Excercise-2 : calculate square and cube of given number using inline function

C++ program using class to calculate square and cube of given number using inline function .

Sample Syntax:

#include<iostream.h>
class power
{
public:
inline int square(int n)
{
 -----------------------------
 -----------------------------
 }
inline int cube(int n)
{
 -----------------------------
 -----------------------------
 }

};
void main()
{
 -------------------------------
 -------------------------------
}