/* Copyright: 2000, All rights reserved. Program: C Strings 2 Version: 1.0 Created/Revised: File: cstrings2.cpp Programmer: C. S. Tritt, Ph.D. Course: CS-150 Assignment: C Strings Example Compiler: Microsoft Visual C++ 6.0 Target: Win32 Description: This program demonstrates the use of C strings in C++. The problem solved involves asking the user for a size code (L+, L, M, S and S-) and displying the corresponding text (Extra large, Large, Medium, Small and Extra small, respectively. This program compares multi-character strings. This program uses a somewhat odd approach for demonstration purposes. It does not do error checking and it is possible to overflow the input string with improper input. Revisions: There have been no major revisions of this program. Constants and Variables: See code for constant and variable descriptions. */ // Included files. #include #include // Macros for ANSI C++ logical operations in MSVC++ 6.0. #define and && #define or || #define not ! using namespace std; int main() { // Define constants. const char XLARGE[] = "L+"; const char LARGE[] = "L"; const char MEDIUM[] = "M"; const char SMALL[] = "S"; const char XSMALL[] = "S-"; // Get input. cout << "Please enter a size code: "; char scode[3]; cin >> scode; // Process input. cout << "Size: "; if (strcmp(scode, XLARGE) == 0) cout << "Extra large\n"; else if (strcmp(scode, LARGE) == 0) cout << "Large"; else if (strcmp(scode, MEDIUM) == 0) cout << "Medium"; else if (strcmp(scode, SMALL) == 0) cout << "Small"; else if (strcmp(scode, XSMALL) == 0) cout << "Extra small\n"; else { cout << "Invalid\n"; return 1; } cout << '\n'; // Everything worked. return 0; }