0% found this document useful (0 votes)
10K views

WAP To Calculate Factorial of A Given Number Using Copy Constructor

This C++ program defines a class called "copy" that takes an integer as a parameter and calculates its factorial. The main function prompts the user to input a number, creates an object of the copy class using that number, and calculates and displays the factorial twice - once using the original object and once using a copy of the original object.

Uploaded by

9y9a
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10K views

WAP To Calculate Factorial of A Given Number Using Copy Constructor

This C++ program defines a class called "copy" that takes an integer as a parameter and calculates its factorial. The main function prompts the user to input a number, creates an object of the copy class using that number, and calculates and displays the factorial twice - once using the original object and once using a copy of the original object.

Uploaded by

9y9a
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream.h> #include<conio.

h> class copy { int var,fact; public:

copy(int temp) { var = temp; }

double calculate() { fact=1; for(int i=1;i<=var;i++) { fact = fact * i; } return fact; } }; void main()

{ clrscr(); int n; cout<<"\n\tEnter the Number : "; cin>>n; copy obj(n); copy cpy=obj; cout<<"\n\t"<<n<<" Factorial is:"<<obj.calculate(); cout<<"\n\t"<<n<<" Factorial is:"<<cpy.calculate(); getch(); }

You might also like