// -- C ++ shortcut tutorial -- Chapter 5 -- array and string (Part 2)
// -- Chapter 5 -- array and string
// -- 11/11/2005 Friday
// -- Computer lab
// -- Liwei
// -- Program #17 two-dimensional array
# Include <iostream>
Using namespace STD;
Void F1 ();
Int main ()
{
F1 ();
F1 ();
Cout <Endl <"=========================" <Endl;
// Getchar ();
Return 0;
}
Void F1 ()
{
Char s [80] = "this is a test./N ";
Cout <s;
Strcpy (S, "changed./N ");
Cout <s;
}
// -- Program #18 String Array
# Include <iostream>
# Include <cstdio>
Using namespace STD;
Int main ()
{
Int T, I;
Char text [2, 100] [80];
For (t = 0; t <100; t ++)
{
// Int Len;
Cout <t <":";
Gets (Text [T]); // If you press enter without entering the key, a string of 0 is returned (the first character is
'/0 ')
// Len = gets (Text [T]);
// Cout <"Len:" <Len <Endl;
If (! Text [T] [0])
{
Cout <"Empty char is:" <text [T] <Endl;
Break;
}
}
For (I = 0; I <t; I ++)
Cout <I <":" <text [I] <Endl;
Cout <Endl <"=========================" <Endl;
// Getchar ();
Return 0;
}
// -- Program #19 a simple employee database program
# Include <iostream>
Using namespace STD;
Char name [10] [80];
Char phone [10] [20];
Float hours [10];
Float wage [10];
Int menu ();
Void enter (), Report (); // declare the Function
Int main ()
{
Int choice;
Do {
Choice = menu ();
Switch (choice ){
Case 0: break;
Case 1: Enter ();
Break;
Case 2: Report ();
Break;
Default: cout <"Try again./n ";
}
} While (choice! = 0 );
Cout <Endl <"=========================" <Endl;
// Getchar ();
Return 0;
}
Int menu ()
{
Int choice;
Cout <"0. Quit./N ";
Cout <"1. Enter information./N ";
Cout <"2. Report information./N ";
Cout <"/nchoose one :";
Cin> choice;
Return choice;
}
Void enter ()
{
Int I;
For (I = 0; I <10; I ++ ){
Cout <"Enter last name :";
Cin> name [I];
Cout <"Enter phone number :";
Cin> phone [I];
Cout <"Enter number of hours worked :";
Cin> hours [I];
Cout <"Enter wage :";
Cin> wage [I];
} //
}
Void report ()
{
Int I;
For (I = 0; I <10; I ++ ){
Cout <name [I] <''<phone [I] <Endl;
Cout <"pay for the week:" <wage [I] * hours [I] <Endl;
} //
}