// Filename: GB.CPP
// Determines whether the user typed a G or a B.
#include <iostream.h>
// toupper is in ctype.h
#include <ctype.h>
void main()
{
char ans; // Holds user's response
cout << "Are you a girl or a boy (G/B)? ";
cin >> ans; // Gets answer
cout << endl;
ans = toupper(ans); // Converts answer to uppercase
switch (ans)
{ case ('G'): { cout << "You look pretty today!" << endl;
break; }
case ('B'): { cout << "You look handsome today!" << endl;
break; }
default : { cout << "Your answer makes no sense!" << endl;
break; }
}
return;
}
=======================
// Filename: GCH1.CPP
// Uses get() and put() for input and output
#include <fstream.h>
void main()
{
int ctr; // for loop counter
char letters[5]; // Holds five input characters. No
// room is needed for the null zero
// because this array will never be
// treated as a string.
cout << "Please type five letters..." << endl;
for (ctr = 0; ctr < 5; ctr++)
{
letters[ctr] = cin.get(); // Adds input to array
}
for (ctr = 0; ctr < 5; ctr++) // Prints them to printer
{
cout.put(letters[ ctr ]);
}
return;
}
======================
// Filename: GETL.CPP
#include <iostream.h>
void main()
{
char city[15];
cout << "Where are you from? ";
cin.getline(city, 15);
cout << "So you are from " << city << endl;
return;
}
=========================
// Filename: GETS.CPP
// Gets a string from the keyboard into a character array
#include <iostream.h>
void main()
{
char str[81]; // Reserves space for up to 80 characters
// and the null zero
cout << "What is your full name? ";
cin.get(str, 80);
cout << "Thank you, " << str << ", for answering me.";
return;
}
============================
// Filename: GOTO.CPP
// Uses goto to print messages in a strange order
#include <iostream.h>
void main()
{
goto Larry;
Final:
cout << "What a stooge of a program!" << endl;
goto EndIt;
Moe:
cout << "Moe is here!" << endl;
goto Curly;
Larry:
cout << "Larry is here!" << endl;
goto Moe;
Curly:
cout << "Curly is here!" << endl;
goto Final;
EndIt:
return;
}
===========================
Tidak ada komentar:
Posting Komentar