Define a class batsman with the following specifications:Private members:bcode 4 digits code numberbname 20 charactersinnings, notout, runs integer typebatavg it is calculated according to the formula batavg =runs/(innings-notout)calcavg() Function to compute batavgPublic members:readdata() Function to accept value from bcode, name, innings,  notout and invoke the function calcavg()displaydata() Function to display the data members on the screen. Â
#include <iostream>
using namespace std;
class batsman{
  private:
    int bcode;
    char bname[20];
    int innings, notout, runs;
    int batavg;
    int calcavg(){
      batavg =runs/(innings-notout);
      return batavg;
    }
  public:
    void readdata(){
      cout<<"\nEnter bcode: ";
      cin>>bcode;
      cout<<"\nEnter bname: ";
      cin>>bname;
      cout<<"\nEnter innings: ";
      cin>>innings;
      cout<<"\nEnter notout: ";
      cin>>notout;
      cout<<"\nEnter runs: ";
      cin>>runs;
     Â
      batavg=calcavg();
     Â
    }
    void displaydata(){
      cout<<"\nBcode: "<<bcode;
      cout<<"\nbname: "<<bname;
      cout<<"\ninnings: "<<innings;
      cout<<"\nnotout: "<<notout;
      cout<<"\nruns: "<<runs;
      cout<<"\nbatavg: "<<batavg;
    }
};
int main()
{
   batsman b;
   b.readdata();
   b.displaydata();
  return 0;
}
Comments
Leave a comment