Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.

Similar presentations


Presentation on theme: "Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous."— Presentation transcript:

1 Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous

2 What is wrong here? int myvar.d; int data-1; int %value;

3 What is wrong here? int a=3; b=a;

4 What is wrong here? int a,b; a++; b++;

5 What is wrong here? cin>>a+b; cin>>10;

6 What is wrong here? int a=2; b=3;

7 What is wrong here? int a=2, b=3; a+b=5;

8 What is wrong here? int a=2, b=3, c=6, d; d = b–4ac;

9 What is wrong here? int a=2, b=3; cout<<a<<" "<<b<<endl; double a; cout<<a<<" "<<b<<endl;

10 What is wrong here? char a=h;

11 §Indentation and colors

12 §Initialize with constant or expression int a, b=3; a = b*53+7;

13 int a=70, b=80; How to print 70 80?

14 double amount; cout<<“Enter the balance in dollars:$”; cin>>amount;

15 int x=5, y=5; y=++x; cout<<x<<" "<<y<<endl; y=x--; cout<<x<<" "<<y<<endl;

16 int x=5, y=5; y=++x; cout<<x<<" "<<y<<endl; // prints 6 6 y=x--; cout<<x<<" "<<y<<endl; // prints 5 6

17 int x=5, y=5; cout << x++ << endl; cout << ++y << endl; cout << x << ‘,’ << y;

18 int x=5, y=5; cout << x++ << endl; //prints 5 cout << ++y << endl; //prints 6 cout << x << ‘,’ << y; //prints 6,6

19 The following code causes conversions (in this example, integral promotions): long lnum1=2345, lnum2=3456; int inum=45; // inum promoted to type long prior to assignment. lnum1 = inum; // inum promoted to type long prior to multiplication. lnum2 = inum * lnum2;

20 float fVal=3.0, fVal2=4.5; double dVal=9.768; int iVal=6; fVal2 = iVal * fVal; // iVal converted to float; // result of multiplication is float. dVal = iVal + dVal; // iVal converted to double; // result of addition is double.

21 What is wrong here? double total_price ; int feet; cin>>feet; //There are 5280 feet in a mile total_price = 5000*(feet/5280); //suppose user enters 15000 feet

22 int y; char c='3'; y = 5 + c; cout<<y<<endl; output?

23 Character Data l Each character corresponds to a binary code l Most commonly use binary codes are ASCII (American Standard Code for Information Interchange) CharacterASCII CodeInteger Equivalent %010010137 3011001151 A100000165 a110000197 b110001098 c110001199

24 int y; char c='3'; y = 5 + c; cout<<y<<endl; output 56 CharacterASCII CodeInteger Equivalent 3011001151

25 char ck='3'; int i=ck; cout <<i<<endl;

26 §Casts can be used cout<<(float)5/3<<endl; cout<<(float)3/6<<endl; Casts are considered operators – same precedence as unary operators

27 char ck='3'; cout <<(int) ck<<endl; ________________________________ char ck='3'; int i=ck; cout <<i<<endl;

28 Be careful with casts! e.g. Don’t cast a double into float

29 //Compiler will give warnings. Try this out! #include int main(){ int i, j; i=23.867; j=9876543219876; cout<<i<<" "<<j<<endl; return 0; }

30 //Compiler will give warnings Try this out! #include int main(){ int i, j, k; i=23.867; j=9876543219876; cout<<i<<" "<<j<<endl; return 0; } 23 -1881560924

31 cout<<"This is called \"fund raising\""; cout<<"\"\\"; cout<<"one"<<"\t"<<"two";

32 §Concept of true and false §true is any value other than zero §false is zero

33 bool b=true; cout<<b<<endl; b=false; cout<<b<<endl; //zero is false and non-zero is true b=35; cout<<b<<endl; b=-45; cout<<b<<endl; b=0; cout<<b<<endl;

34 bool b=true; cout<<b<<endl; //prints 1 b=false; cout<<b<<endl; //prints 0 //zero is false and non-zero is true b=35; cout<<b<<endl; //prints 1 b=-45; cout<<b<<endl; //prints 1 b=0; cout<<b<<endl; //prints 0


Download ppt "Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous."

Similar presentations


Ads by Google