Answer to Question #267439 in C++ for Awais

Question #267439

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

1
Expert's answer
2021-11-17T06:30:47-0500
/******************************************************************************


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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS