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:
A is a character data type
#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;
}
Comments
Leave a comment