C ++ shortcut tutorial-Chapter 5-array and string (Part 2)

Source: Internet
Author: User

// -- 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;
} //
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.