Answer to Question #191163 in C++ for python

Question #191163

1.  Write a program that check the type of the value and determine the data type of the value. In this program, you will develop a Type checking program (Type Checker).


 

 

If the argument of printType(true) is true or false, it will invoke a function inside and print a message “true is a boolean”. If it is int 463287462 then it should display “4632874 is Integer”. The sample output format is as follows:

1.24353 is double data type 334345345 is an integer data type 1 is boolean data type

A is a character data type

 

 

1
Expert's answer
2021-05-12T13:10:44-0400
#include <iostream>
#include <string>


using namespace std;


void printType(bool type) { 
	if (type==1){
		cout<<"true is a boolean\n";
	}else{
		cout<<"false is a boolean\n";
	}
}
void printType(int type) { 
	if(type==1){
		cout<<"1 is a boolean\n";
	}else if(type==0){
		cout<<"0 is a boolean\n";
	}else{
		cout<<type<<" is a Integer\n";
	}
	
}
void printType(double type) { 
	cout<<type<<" is a double\n";
}
void printType(char type) { 
	cout<<type<<" is a character \n";
}


int main()
{
	printType(true);
	printType(463287462);
	printType(1.24353);
	printType('A');
	printType(1);
	printType(0);


	system("pause");
	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