// -- C ++ shortcut tutorial -- Chapter 3 -- Basic Data Type
// -- Chapter 3 -- Basic Data Type
// -- 11/7/2005 mon.
// -- Computer lab
// -- Liwei
// -- Program #1 Use of local variables
# Include <iostream>
Using namespace STD;
Void func ();
Int main ()
{
Int x = 10;
Func ();
Cout <"/N ";
Cout <x <Endl;
Return 0;
}
Void func ()
{
Int x =-199;
Cout <X;
}
// -- Program #2 Use of global variables
# Include <iostream>
Using namespace STD;
Void func1 ();
Void func2 ();
Int count ;//
Int main ()
{
Int I;
For (I = 0; I <10; I ++)
{
Count = I * 2;
Func1 ();
}
Return 0;
}
Void func1 ()
{
Cout <"count:" <count; // global variable
Func2 ();
Cout <"/N ";
}
Void func2 ()
{
Int count;
For (COUNT = 0; count <3; count ++)
Cout <'.' <"*";
}
// -- Program #3 differences between the number of signed characters and the number of unsigned characters
# Include <iostream>
Using namespace STD;
Int main ()
{
Short int I;
Short unsigned Int J;
J = 60000;
I = J;
Cout <I <''<j <Endl;
Return 0;
}
// -- Program #4 reverse output alphabet
# Include <iostream>
Using namespace STD;
Int main ()
{
Char letter;
For (letter = 'Z'; letter> = 'a'; letter --)
Cout <"" <letter;
Cout <Endl;
Cout <"/N // B//? /T/R ";
Return 0;
}
// -- Program #5 sample program for variable Initialization
# Include <iostream>
Using namespace STD;
Void total (int x );
Int main ()
{
Cout <"computing summation of 5./N ";
Total (5 );
Cout <"/ncomputing summation of 6./N ";
Total (6 );
Return 0;
}
Void total (int x)
{
Int sum = 0, I, count;
For (I = 1; I <= x; I ++)
{
Sum + = I;
For (COUNT = 0; count <10; count ++)
Cout <'.';
Cout <"the current sum is:" <sum <Endl;
}
}
// -- Program # 6% usage
# Include <iostream>
Using namespace STD;
Int main ()
{
Int X, Y;
X = 10;
Y = 3;
Cout <x/y <Endl;
Cout <X % Y <Endl;
X = 1, y = 2;
Cout <x/y <"" <X % Y <Endl;
Return 0;
}
// -- Program #7 use of exclusive or operations
# Include <iostream>
Using namespace STD;
Bool XOR (bool a, bool B );
Int main ()
{
Bool p, q;
Cout <"Enter P (0 or 1 ):";
Cin> P;
Cout <"Enter Q (0 or 1 ):";
Cin> q;
Cout <"p and q:" <(P & Q) <Endl;
Cout <"P or Q:" <(p | q) <Endl;
Cout <"p xor q:" <XOR (p, q) <Endl;
Return 0;
}
Bool XOR (bool a, bool B)
{
Return (A | B )&&! (A & B );
}
// -- Program #8 use of forced conversion
# Include <iostream>
Using namespace STD;
Int main ()
{
Int I;
For (I = 0; I <100; I ++)
Cout <I <"/2 is:" <(float) I/2 <Endl;
Return 0;
}