Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.
-
date post
19-Dec-2015 -
Category
Documents
-
view
217 -
download
3
Transcript of Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.
![Page 1: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/1.jpg)
Tuesday, December 12, 2006
“Press any key to continue or any other key to quit.”
- Anonymous
![Page 2: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/2.jpg)
What is wrong here?
int myvar.d;
int data-1;
int %value;
![Page 3: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/3.jpg)
What is wrong here?
int a=3;
b=a;
![Page 4: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/4.jpg)
What is wrong here?
int a,b;
a++;
b++;
![Page 5: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/5.jpg)
What is wrong here?
cin>>a+b;
cin>>10;
![Page 6: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/6.jpg)
What is wrong here?
int a=2; b=3;
![Page 7: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/7.jpg)
What is wrong here?
int a=2, b=3;
a+b=5;
![Page 8: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/8.jpg)
What is wrong here?
int a=2, b=3, c=6, d;
d = b–4ac;
![Page 9: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/9.jpg)
What is wrong here?
int a=2, b=3;
cout<<a<<" "<<b<<endl;
double a;
cout<<a<<" "<<b<<endl;
![Page 10: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/10.jpg)
What is wrong here?
char a=h;
![Page 11: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/11.jpg)
Indentation and colors
![Page 12: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/12.jpg)
Initialize with constant or expression
int a, b=3;
a = b*53+7;
![Page 13: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/13.jpg)
int a=70, b=80;
How to print 70 80?
![Page 14: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/14.jpg)
double amount;
cout<<“Enter the balance in dollars:$”;
cin>>amount;
![Page 15: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/15.jpg)
int x=5, y=5;
y=++x;
cout<<x<<" "<<y<<endl;
y=x--;
cout<<x<<" "<<y<<endl;
![Page 16: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/16.jpg)
int x=5, y=5;
y=++x;
cout<<x<<" "<<y<<endl; // prints 6 6
y=x--;
cout<<x<<" "<<y<<endl; // prints 5 6
![Page 17: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/17.jpg)
int x=5, y=5;
cout << x++ << endl;
cout << ++y << endl;
cout << x << ‘,’ << y;
![Page 18: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/18.jpg)
int x=5, y=5;
cout << x++ << endl; //prints 5
cout << ++y << endl; //prints 6
cout << x << ‘,’ << y; //prints 6,6
![Page 19: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/19.jpg)
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;
![Page 20: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/20.jpg)
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.
![Page 21: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/21.jpg)
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
![Page 22: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/22.jpg)
int y;
char c='3';
y = 5 + c;
cout<<y<<endl;
output?
![Page 23: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/23.jpg)
Character Data Each character corresponds to a binary code Most commonly use binary codes are ASCII (American
Standard Code for Information Interchange)Character ASCII Code Integer Equivalent
% 0100101 37
3 0110011 51
A 1000001 65
a 1100001 97
b 1100010 98
c 1100011 99
![Page 24: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/24.jpg)
int y;
char c='3';
y = 5 + c;
cout<<y<<endl;
output 56
Character ASCII Code Integer Equivalent
3 0110011 51
![Page 25: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/25.jpg)
char ck='3';
int i=ck;
cout <<i<<endl;
![Page 26: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/26.jpg)
Casts can be usedcout<<(float)5/3<<endl;
cout<<(float)3/6<<endl;
Casts are considered operators – same precedence as unary operators
![Page 27: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/27.jpg)
char ck='3';
cout <<(int) ck<<endl;
________________________________
char ck='3';
int i=ck;
cout <<i<<endl;
![Page 28: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/28.jpg)
Be careful with casts!
e.g. Don’t cast a double into float
![Page 29: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/29.jpg)
//Compiler will give warnings. Try this out!#include <iostream.h>int main(){
int i, j;
i=23.867;
j=9876543219876;
cout<<i<<" "<<j<<endl;
return 0;}
![Page 30: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/30.jpg)
//Compiler will give warnings Try this out!#include <iostream.h>int main(){
int i, j, k;i=23.867;j=9876543219876;cout<<i<<" "<<j<<endl;
return 0;}
23 -1881560924
![Page 31: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/31.jpg)
cout<<"This is called \"fund raising\"";
cout<<"\"\\";
cout<<"one"<<"\t"<<"two";
![Page 32: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/32.jpg)
Concept of true and falsetrue is any value other than zerofalse is zero
![Page 33: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/33.jpg)
bool b=true;cout<<b<<endl;b=false;cout<<b<<endl;//zero is false and non-zero is trueb=35;cout<<b<<endl;b=-45;cout<<b<<endl;b=0;cout<<b<<endl;
![Page 34: Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.](https://reader036.fdocuments.in/reader036/viewer/2022062714/56649d395503460f94a137c7/html5/thumbnails/34.jpg)
bool b=true;cout<<b<<endl; //prints 1b=false;cout<<b<<endl; //prints 0//zero is false and non-zero is trueb=35;cout<<b<<endl; //prints 1b=-45;cout<<b<<endl; //prints 1b=0;cout<<b<<endl; //prints 0