The problem is that you're calling the setfee member function only for the first object in the array stu. And since the array stu was default initialized meaning its elements were also default initialized, the data member fee of each of those elements inside stu has an indeterminate value. So, calling showfee on the elements on which setfee was not called, is undefined behavior since for those elements fee has indeterminate value and you're printing the value inside showfee.
because I want to set the same fee amount for every student and then autoprint it in a file for every stu[] array variable.
To solve this and do what you said in the above quoted statement, you can ask the user for the fee inside the main and then pass the input as an argument to the setfee member function. For this we have to change setfee member function in such a way that it has an int parameter. Next, using a 2nd for loop we could print the fee of each of the elements inside stu using showfee member function. This is shown below:
#include<iostream>
class FEE
{
    private:
    int fee = 0; //use in-class initializer for built in type
    public:
    void setfee(int pfee)
    {
        fee = pfee;
        
    }
    void showfee()
    {
        std::cout<<"Monthly fee is "<<fee<<std::endl;
    }
};
int main()
{
    FEE stu[5];   //default initiailized array 
    
    int inputFee = 0;
    for(int i=0;i<5;i++)
    {
        std::cout<<"Enter the monthly fee= ";
        std::cin>>inputFee;
        
        //call setfee passing the inputFee
        stu[i].setfee(inputFee);
        
    }
    for(int i = 0; i<5; ++i)
    {
        stu[i].showfee();
    }
}
Demo
Also, note that using a std::vector instead of built in array is also an option here.
Some of the changes that i made include:
- Added a parameter to the setfeemember function.
- Used in-class initializer for the feedata member.
- The input fee is taken inside mainwhich is then passed to thesetfeemember function for each of the element insidestu.
- The member function showfeeis called for each of the element insidestuusing the 2nd for loop.