Assignments » Class and Objects » Set1 »Solution 2
solution of question 2
[SET – 1]

C++ Program to Define a Class Batsman and accessing member function using its object

 

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

class batsman
{
	int bcode;
	char bname[20];
	int innings,notout,runs;
	int batavg;
	void calcavg()
	{
		batavg=runs/(innings-notout);
	}

public :
	void readdata ();
	void displaydata();
};

void batsman::readdata ()
{
	cout<<"Enter batsman code ";
	cin>> bcode;
	cout<<"Enter batsman name ";
	gets(bname);
	cout<<"enter innings,notout and runs ";
	cin>>innings>>notout>>runs;
	calcavg();
}

void batsman::displaydata()
{
	cout<<"Batsman code "<<bcode<<"\nBatsman name "<<bname<<"\nInnings "<<innings
	<<"\nNot out "<<notout<<"\nRuns "<<runs<<"\nBatting Average "<<batavg;
}


int main()
{
	batsman obj;
	obj.readdata();
	obj.displaydata();
	getch();
	return 0;
}