Answer to Question #227589 in C++ for Joseph

Question #227589

Create a class with an integer data member. Include functions for input and output in class. Count the number of times each function is called and display it. It should be a user defined program.


1
Expert's answer
2021-08-19T14:32:20-0400
#include<iostream>
using namespace std;




class Data{
	private:
		int x;
		static int funInput ;
		static int funOutput ;
	public:
		void input(); //Inputting data
		void output();//Displaying the entered data
		void display();//Displaying the number of times the two above functions has been called
		
	
	
};
int Data::funInput=0;
int Data::funOutput = 0;
	void Data::input(){
			
			cout<<"Enter the value of x\n";
			cin>>x;
			funInput++;
		}
		
	void Data::output(){
			
			cout<<"The value of x is "<<x<<endl;
			funOutput++;
		}
		//This function will display the number of times a function has been called
			void Data::display(){
			cout<<"The input function has been called  "<<funInput<<" times\n";
			cout<<"The output function has been called  "<<funOutput<<" times\n";
		}
int main(){
	Data d;
	d.input(); //Calling the function the first time
	d.output();
	d.input();
	d.output();
	d.display();
}

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

Joseph
21.08.21, 19:17

Thanks a lot !!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS