wex8_15.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 93 行

CPP
93
字号
#include <iostream.h>
#include <stdlib.h>
#pragma hdrstop

#include "strclass.h"

#define TF(b)	((b) ? "TRUE" : "FALSE")

void main(void)
{
	String s1("STRING "), s2("CLASS");
	String s3;

	int i;
	char c, cstr[50];
	
	cout << "(a)" << endl;
	s3 = s1 + s2;
	cout << s1 << "concatenated with " << s2
		 << " = " << s3 << endl;
		 
	cout << endl << "(b)" << endl;
	cout << "Length of " << s2 << " = " 
		 << s2.Length() << endl;

	cout << endl << "(c)" << endl;
	cout << "The first occurrence of 'S' in " << s2
		 << " = " << s2.Find('S',0) << endl;
	cout << "The last occurrence of 'S' in " << s2
		 << " = " << s2.FindLast('S') << endl;

	cout << endl << "(d)" << endl;
	cout << "Insert 'OBJECT ' into s3 at position 7."
		 << endl;
	s3 = s1 + s2;
	s3.Insert("OBJECT ",7);
	cout << s3 << endl;

	cout << endl << "(e)" << endl;
	s1 = "FILE1.S";
	for(i=0;i < s1.Length();i++)
	{
		c = s1[i];
		if (c >= 'A' && c <= 'Z')
		{
			c += 32;
			s1[i] = c;
		}
	}
	cout << s1 << endl;

	cout << endl << "(f)" << endl;
	s1 = "ABCDE";
	s2 = "BCF";

	cout << "s1 < s2 = " << TF(s1 < s2) << endl;
	cout << "s1 == s2 = " << TF(s1 == s2) << endl;

	cout << endl << "(g)" << endl;
	s1 = "Testing pointer conversion operator.";
	strcpy(cstr,s1);
	cout << cstr << endl;
} 

/*
<Run>

(a)
STRING concatenated with CLASS = STRING CLASS

(b)
Length of CLASS = 5

(c)
The first occurrence of 'S' in CLASS = 3
The last occurrence of 'S' in CLASS = 4

(d)
Insert 'OBJECT ' into s3 at position 7.
STRING OBJECT CLASS

(e)
file1.s

(f)
s1 < s2 = TRUE
s1 == s2 = FALSE

(g)
Testing pointer conversion operator.
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?