⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wex8_15.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -