C++ Simple program


1. Write a C++ program using class with data member’s int feet,float inches to represent distance and define function that takes two distance values as arguments and returns the larger one.Include a main program that accepts two distance figures from the user compare them and displays the larger using Inline function.

2. Consider the mystring class
Class mystring
{
char str [100];
int length;
Public:
// methods
};
Overloading the method called “check” for the class to perform the following operations.
i)Check if a specific character is present in str. Returns position if found, -1 if not.
ii)Compares the length of two mystring objects and returns 1 if they are equal, 0 if not. With attribute real and imaginary.

3. Define a class for a 3 dimensional points.
Write necessary member functions for accepting & displaying the point object.
Overload the following operators:
Operator Example Purpose
+ (Binary) p3=p1+p2 adds coordinates of point p1 to p2.
– (Unary) -p1 Negates coordinates of point p1.

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

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

6. Write a C++ program using class to check maximum of two integer numbers using Inline function and conditional operator.

7. Define a class for 3 dimensional points necessary member
functions for accepting and the point object Overload the following operators:
Operator Example Purpose
* (Binary) p3=p1*p2 multiplies coordinates of point p1 with p2.
– (Binary) p3=p2-p1 subtracts coordinates of p1 from p2.

8. Write a C++ program using class to overload following binary operators (+,-,*,/).

9. Consider the following class mystring
Class mystring
{
char str [100];
Public:
// methods
};
overload operator “= =” to compare two strings.

10. Consider following class Numbers
Class Numbers
{
int x,y,z;
public:
// methods
};
Overload the operator unary minus- to negate the numbers.

11. Consider the following class mystring
Class mystring
{
char str [100];
Public:
// methods
};
Overload operator + to concatenate two strings such as string1+string2=string3.

12. Write a C++ program using class to overload the operator unary increment ++ for an integer number.

13. Write a C++ program using class to overload the operator unary decrement — for an integer number.

14. Consider the following class Person
Class Person
{
char Name [20];
char Addr [30];
float Salary;
int Property;//in sq. foot area
float tax_amount;
Public:
// methods
};
Calculate tax amount by checking salary and the property of the person
For salary <5000 tax rate=0
For salary >=5000||<=10000 tax rate= 14% of salary.
For salary >=10000 tax rate =16% of salary.

In this tax amount add following amt depending on the size of area in sq.foot
For 1000 sq. foot area amt=0.
For >1000|| < 5000 sq. foot area amt= 1000
For >5000||<= 10000 sq. foot area amt=3000.
15. Write a C++ program to define function power to raise a number m to a power n the function takes a double value for m. And integervalue for n and return the result correctly use a default value of 2 for n to make the function calculate squares when this argument is omitted

16. Write a menu driven C++ program using class to perform all arithmetic operation (+,-,*,/) (use inline function).

18. Write a C++ program to find volume of cube, cylinder an rectangle using function overloading.

19. Design a class which contain static data member and member function show() which displays number of times display operation is performed irrespective of the object responsible for display using static data member.

20. Write a menu driven C++ program using class to calculate Area and Volume of rectangle using inline function.

21.Consider the following class mystring
Class mystring
{
char str [100];
Public:
// methods
};
Overload operator “!” to reverse the case of each alphabet in the string.

22. Create a C++ class for a student object with the following attributes— roll no, name, number of subjects , marks of subjects. The number of subjects varies for each student. Write a parameterized constructor which initializes roll number, name and number of subject and creates the array for marks dynamically, write member function for accepting marks and display all information of student.

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

24. Write a c++ program using class to sort an integer array and float array element in ascending order using bubble sort method use function overload.

25.Write a C++ program which will find the maximum of 3 integer numbers and maximum of 3 float numbers using function overloading.

26.consider a class complex

class complex
{
float real;
float imaginary;
public:
};
overload operater ‘+’ to add object of two class use parameterized constructor for accepting value of complex number.

27. Consider a class Matrix
Class Matrix
{
int a[3][3];
Public:
//methods;
};
Let m1 and m2 are two matrices. Find out m3=m1+m2 (use operator overloading).

28.Consider a class Matrix
Class Matrix
{
int a[3][3];
Public:
//methods;
};
Overload the – (Unary) should negate the numbers stored in the object.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s