Write a class which consists of four data members and four member function sum min max and factorial you can inilized class object or can be take by an function
/******************************************************************************
Write a class which consists of four data members and four member function sum
min max and factorial you can inilized class object or can be take by an function
*******************************************************************************/
#include <iostream>
using namespace std;
class ClassA{
private:
int a;
int b;
int c;
int d;
public:
ClassA(int x1,int x2,int x3, int x4){
a=x1;
b=x2;
c=x3;
d=x4;
}
void getsum(){
int total=a+b+c+d;
cout<<"\nSum = "<<total;
}
void getmin(){
int arr[4]={a,b,c,d};
int min=arr[0];
for (int i=0;i<4;i++){
if(arr[i]<min)
min=arr[i];
}
cout<<"\nMin = "<<min;
}
void getmax(){
int arr[4]={a,b,c,d};
int max=arr[0];
for (int i=0;i<4;i++){
if(arr[i]>max)
max=arr[i];
}
cout<<"\nMax = "<<max;
}
void factorial(){
int arr[4]={a,b,c,d};
int fact=1;
for (int i=0;i<4;i++){
fact*=arr[i];
}
cout<<"\nFactorial = "<<fact;
}
};
int main()
{
ClassA c(1,2,3,4);
c.getsum();
c.getmin();
c.getmax();
c.factorial();
return 0;
}
Comments
Leave a comment