Lecture_Notes_03

Lecture_Notes_03 - C+ keywords discussed so far in lectures...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
44 C++ keywords – discussed so far in lectures namespace int short long unsigned signed short double using bool char true false
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
45 Case Study in Data Type #include <cstdlib> #include <iostream> using namespace std; int main() { double score; cout<<score; cin>>score; return 0; //Equivlent to return EXIT_SUCCESS; }
Background image of page 2
46 Case Study in Data Type int main() { double score; cout<<score; int score=5; cin>>score; return 0; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
47 Case Study in Data Type int main() { short score; score=50000; cout<<score; system( "PAUSE" ); return 0; //Equivlent to return EXIT_SUCCESS; }
Background image of page 4
48 Case Study in Data Type int main() { short 1score; 1score=50000; cout<<1score; system( "PAUSE" ); return 0; //Equivlent to return EXIT_SUCCESS; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Division by zero #include <cfloat> // DBL_MAX and DBL_MIN are defined in cfloat header #include <iostream> #include <cstdlib> using namespace std; int main() { double testVariable=0.0; double j=-0.0/testVariable; //results in indefinite number or NaN(not a number) cout<<j<<endl; if (j!=j) //indifinite number is not equal to anything, even itself cout<< “j is NAN, 0.0/0" <<endl; //--------------------------------- j=-1.0/testVariable; //results in infinite number cout<<j<<endl; if ((j>=DBL_MAX)||(j<=DBL_MIN)) //infinite number is outside the limits of double cout<< “j is infinite 1.0/0" <<endl; //----------------------------------- int zeroInt=0; j=5/zeroInt; //run-time error, typically causes a program to terminate prematurely system( "PAUSE" ); return EXIT_SUCCESS; } NOTE: Integer types do not support NaN values. Since they use the whole, say, 32 bits for storing the number without any special values. In other words, bit patterns for +Inf, -Inf, Nan, which are not defined for an int. Extra notes Lecture 6
Background image of page 6
Operators Assignment operators: X = 5; // assign value to left operand i.e., X 5 = X; // compile-time error Mathematical operators: + , - , * , / , % result = 56+32; //result=88 result = 12-10;
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/01/2012 for the course GENE 121 taught by Professor Smucker during the Winter '11 term at Waterloo.

Page1 / 24

Lecture_Notes_03 - C+ keywords discussed so far in lectures...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online