C++ Programs

M.S University BCA C++ Practical Programs

Passing objects to function

Java program to multiply two matrices – Ultimate way 2 success

Java Programs

Java program to multiply two matrices

Aim

To write a C++ program for finding the factorial for a given number using class and object.

Procedure

STEP 1: Include the necessary header files for the program.
STEP 2: Define a class named “factorial” to encapsulate the functionality of calculating the factorial of a number.
STEP 3: Declare the member functions with in the “factorial” class.
(i)”in()” function – to get the user input.
(ii) “calculate()” function – to compute the factorial for the given input.
(iii) “out()” function – to display the result.
STEP 4: Implement the member functions.
STEP 5: In the “main()” function, create an object named “x” for the “factorial” class.
STEP 6: Invoke the member functions using the object to get the input, calculate the factorial, and display the result.
STEP 7: Terminate the program.

Source Code(Class and object)

Output

class and object

Explanation

Class and Object: In object-oriented programming (OOP), class is a blueprint or structure of an object. In this program, the “factorial” class serves as a blueprint or structure that defines the properties and functions.

Class Definition: The “factorial” class is defined with member variables (“n” and “f”) and member functions (“in()”, “calculate()”, and “out()”). These member functions define the actions or behaviors associated with objects of the “factorial” class.

Implementation of Member Functions: (i) “in()”: Gets input from the user. (ii) “calculate()”: Computes the factorial of a given number. (iii) “out()”: Displays the result.

Objects: Objects are instances of classes. In the “main()” function, an object “x” is created for the “factorial” class. This object is used to invoke the member functions such as “in()”, “calculate()”, and “out()”.

We hope this article has helped readers learn how to write a C++ program to demonstrate function overloading, default arguments, and inline functions. This C++ practical program is  included in the I year BCA TANSCHE syllabus.

If you found this article helpful, consider sharing it with your friends. For more tutorials and content, subscribe to our YouTube channel and follow us on TwitterInstagramLinkedIn and  Facebook.

Share the Article

Java program to multiply two matrices – Ultimate way 2 success Read More »

Passing objects to function

Java program to print prime numbers – Ultimate way 2 success

Java Programs

Java program to print prime numbers

Aim

To write a C++ program for finding the factorial for a given number using class and object.

Procedure

STEP 1: Include the necessary header files for the program.
STEP 2: Define a class named “factorial” to encapsulate the functionality of calculating the factorial of a number.
STEP 3: Declare the member functions with in the “factorial” class.
(i)”in()” function – to get the user input.
(ii) “calculate()” function – to compute the factorial for the given input.
(iii) “out()” function – to display the result.
STEP 4: Implement the member functions.
STEP 5: In the “main()” function, create an object named “x” for the “factorial” class.
STEP 6: Invoke the member functions using the object to get the input, calculate the factorial, and display the result.
STEP 7: Terminate the program.

Source Code(Class and object)

Output

class and object

Explanation

Class and Object: In object-oriented programming (OOP), class is a blueprint or structure of an object. In this program, the “factorial” class serves as a blueprint or structure that defines the properties and functions.

Class Definition: The “factorial” class is defined with member variables (“n” and “f”) and member functions (“in()”, “calculate()”, and “out()”). These member functions define the actions or behaviors associated with objects of the “factorial” class.

Implementation of Member Functions: (i) “in()”: Gets input from the user. (ii) “calculate()”: Computes the factorial of a given number. (iii) “out()”: Displays the result.

Objects: Objects are instances of classes. In the “main()” function, an object “x” is created for the “factorial” class. This object is used to invoke the member functions such as “in()”, “calculate()”, and “out()”.

We hope this article has helped readers learn how to write a C++ program to demonstrate function overloading, default arguments, and inline functions. This C++ practical program is  included in the I year BCA TANSCHE syllabus.

If you found this article helpful, consider sharing it with your friends. For more tutorials and content, subscribe to our YouTube channel and follow us on TwitterInstagramLinkedIn and  Facebook.

Share the Article

Java program to print prime numbers – Ultimate way 2 success Read More »

Passing objects to function

class and object in c++ – Ultimate way 2 success

C++ Programs

Class and Object in C++

Aim(Class and object)

To write a C++ program for finding the factorial for a given number using class and object.

Procedure

STEP 1: Include the necessary header files for the program.
STEP 2: Define a class named “factorial” to encapsulate the functionality of calculating the factorial of a number.
STEP 3: Declare the member functions with in the “factorial” class.
(i)”in()” function – to get the user input.
(ii) “calculate()” function – to compute the factorial for the given input.
(iii) “out()” function – to display the result.
STEP 4: Implement the member functions.
STEP 5: In the “main()” function, create an object named “x” for the “factorial” class.
STEP 6: Invoke the member functions using the object to get the input, calculate the factorial, and display the result.
STEP 7: Terminate the program.

Source Code(Class and object)

Output

class and object

Explanation

Class and Object: In object-oriented programming (OOP), class is a blueprint or structure of an object. In this program, the “factorial” class serves as a blueprint or structure that defines the properties and functions.

Class Definition: The “factorial” class is defined with member variables (“n” and “f”) and member functions (“in()”, “calculate()”, and “out()”). These member functions define the actions or behaviors associated with objects of the “factorial” class.

Implementation of Member Functions: (i) “in()”: Gets input from the user. (ii) “calculate()”: Computes the factorial of a given number. (iii) “out()”: Displays the result.

Objects: Objects are instances of classes. In the “main()” function, an object “x” is created for the “factorial” class. This object is used to invoke the member functions such as “in()”, “calculate()”, and “out()”.

We hope this article has helped readers learn how to write a C++ program to demonstrate function overloading, default arguments, and inline functions. This C++ practical program is  included in the I year BCA TANSCHE syllabus.

If you found this article helpful, consider sharing it with your friends. For more tutorials and content, subscribe to our YouTube channel and follow us on TwitterInstagramLinkedIn and  Facebook.

Share the Article

class and object in c++ – Ultimate way 2 success Read More »

function overloading

Function overloading in C++ – Ultimate way 2 success

C++ Programs

Function Overloading in C++

Aim(Function Overloading)

To write a C++ program to demonstrate function overloading with default arguments and inline function by finding the area of a square, circle, and rectangle.

Procedure

Step 1: Include the necessary header files for the program.
Step 2: Define a class named “shape” to encapsulate different shape-related functionalities.
Step 3: Define various public member functions with the same name “area()” with different parameters by overloading functions with default arguments and an inline function.
Step 4: Implement the member functions to calculate the area of a square, circle, and rectangle.
Step 5: In the main() function, create an object “s” for the class “shape”.
Step 6: Get the inputs from the user and pass them through the functions , by invoking the area() member functions using the object , to find the area of square, circle, and rectangle.
Step 7: Print the results.
Step 8: Terminate the program.

Source Code(Function overloading)

Output

Function overloading

Explanation

1. Function Overloading : Function overloading enables the implementation of multiple functions with the same name but with different parameters.The programmer can distinguish the functions by number of parameters, datatype of parameters and return type.
In this program, the “area” function is overloaded within the “shape” class. There are three “area” functions:
(i) The first function with an integer argument (for calculating the area of a square).
(ii) The second function with two integer arguments (for calculating the area of a rectangle).
(iii) The third function with  a double argument (for calculating the area of a circle).
This allows the program to call the appropriate “area” function based on the number and types of arguments , passed by the user.

2. Default Arguments : Default arguments provide default values for function parameters, if  there is no argument value is passed during the function call. This default argument is defined by the programmer.
In the above program, the “area” function for calculating the area of a circle has a default argument for “pi” with a value of 3.14. If the user does not provide a value for “pi” when calling this function, it will use the default value of 3.14.

3. Inline Functions :  Inline functions are functions whose code is expanded at the time of the function call, rather than being executed through a function call mechanism.
In the above program, the “area” function for calculating the area of a square is declared as an inline function using the “inline” keyword. This means that the function call is replaced with the actual code of the function during compilation, which can result in faster execution compared to a regular function call.

We hope this article has helped readers learn how to write a C++ program to demonstrate function overloading, default arguments, and inline functions. This C++ practical program is  included in the I year BCA TANSCHE syllabus.

If you found this article helpful, consider sharing it with your friends. For more tutorials and content, subscribe to our YouTube channel and follow us on TwitterInstagramLinkedIn and  Facebook.

Share the Article

Function overloading in C++ – Ultimate way 2 success Read More »

Spread the code...