Friday, December 5, 2014

C++ using Excellant Pro



Uninitialized Variables
 
#include 
#include
using namespace std;
int main() 
{
   int number;             
   cout << number << endl;                   
   return 0;
}
Size of Operator
#include .h>
#include
using namespace std;
int main() 
{
   cout << "sizeof(char) is " << sizeof(char) << " bytes " << endl;
   cout << "sizeof(short) is " << sizeof(short) << " bytes " << endl;
   cout << "sizeof(int) is " << sizeof(int) << " bytes " << endl;
   cout << "sizeof(long) is " << sizeof(long) << " bytes " << endl;
   cout << "sizeof(long long) is " << sizeof(long long) << " bytes " << endl;
   cout << "sizeof(float) is " << sizeof(float) << " bytes " << endl;
   cout << "sizeof(double) is " << sizeof(double) << " bytes " << endl;
   cout << "sizeof(long double) is " << sizeof(long double) << " bytes " << endl;
   cout << "sizeof(bool) is " << sizeof(bool) << " bytes " << endl;
   return 0;
}
 
Output
 
sizeof(char) is 1 bytes
sizeof(short) is 2 bytes
sizeof(int) is 4 bytes
sizeof(long) is 4 bytes
sizeof(long long) is 8 bytes
sizeof(float) is 4 bytes
sizeof(double) is 8 bytes
sizeof(long double) is 12 bytes
sizeof(bool) is 1 bytes
Header climits
 
#include 
#include
#include    
using namespace std;
int main() 
{
   cout << "Int max = " << int_max << endl;
   cout << "Int min = " << int_min << endl;
   cout << "Unsigned int max = " << uint_max << endl;
   cout << "Long long max = " << llong_max << endl;
   cout << "Long long min = " << llong_min << endl;
   cout << "Unsigned long long max = " << ullong_max << endl;
   cout << "Bits in char = " << char_bit << endl;
   cout << "Char max = " << char_max << endl;
   cout << "Char min = " << char_min << endl;
   cout << "Signed char max = " << schar_max << endl;
   cout << "Signed char min = " << schar_min << endl;
   cout << "Unsigned char max = " << uchar_max << endl;
   return 0;
}
 
Output
 
Int max = 2147483647
Int min = -2147483648
Unsigned int max = 4294967295
Long long max = 9223372036854775807
Long long min = -9223372036854775808
Unsigned long long max = 18446744073709551615
Bits in char = 8
Char max = 127
Char min = -128
Signed char max = 127
Signed char min = -128
Unsigned char max = 255
C++ Literals Program
#include 
#include
using namespace std;
int main() 
{
   char gender = 'm';             
   bool ismarried = true;         
   unsigned short numchildren = 8; 
   short yearofbirth = 1945;      
   unsigned int salary = 88000;   
   double weight = 88.88;       
   float gpa = 3.88f;           
   cout << "Gender is " << gender << endl;
   cout << "Is married is " << ismarried << endl;
   cout << "Number of children is " << numchildren << endl;
   cout << "Year of birth is " << yearofbirth << endl;
   cout << "Salary is " << salary << endl;
   cout << "Weight is " << weight << endl;
   cout << "GPA is " << gpa << endl;
   return 0;
}
 
Output
 
Gender is m
Is married is 1    
Number of children is 8
Year of birth is 1945
Salary is 88000
Weight is 88.88
GPA is 3.88

Mixed-Type Operations


#include 
#include
#include    
using namespace std;
int main() 
{
   int i1 = 2, i2 = 4;
   double d1 = 2.5, d2 = 5.0;
   cout << fixed << setprecision(1);  
   cout << i1 << " + " << i2 << " = " << i1+i2 << endl;  
   cout << d1 << " + " << d2 << " = " << d1+d2 << endl;  
   cout << i1 << " + " << d2 << " = " << i1+d2 << endl;  
   cout << i1 << " - " << i2 << " = " << i1-i2 << endl;  
   cout << d1 << " - " << d2 << " = " << d1-d2 << endl;  
   cout << i1 << " - " << d2 << " = " << i1-d2 << endl;  
   cout << i1 << " * " << i2 << " = " << i1*i2 << endl;  
   cout << d1 << " * " << d2 << " = " << d1*d2 << endl;  
   cout << i1 << " * " << d2 << " = " << i1*d2 << endl;  
   cout << i1 << " / " << i2 << " = " << i1/i2 << endl;  
   cout << d1 << " / " << d2 << " = " << d1/d2 << endl;  
   cout << i1 << " / " << d2 << " = " << i1/d2 << endl;  
   return 0;
}

No comments:

Post a Comment