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

📄 09d1.cpp

📁 C++ interview materials. Very helpful for interview. Including Answer.
💻 CPP
字号:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P9.8	9.D.1
审核:周永 Laozhou@swpi.edu.cn	23:58 2004-10-18
测试环境:Microsoft Windowsn 2000(VC++);Red Hat Linux 7.3;Red Hat Linux 9.0
*/

#include <iostream>
#include <string>
using namespace std;

class String
{
private:	
	char *str; 
	int check()
	{
		if (str == NULL)
			return 0;
		else 
			return 1;
	}
public:
	String()
	{
		str = 0;
	}
	String(char *inString)
	{
		str = new char[strlen(inString)+1];
		strcpy(str,inString);
	}
	void replace(char search, char repl)
	{
		if(check() == 0)
		{
			throw "NULL pointer exception";
		}

		int counter;
		for(counter = 0; str[counter] != '\0'; counter++)
		{
			if(str[counter] == search)
			{
				str[counter] = repl;
			}
		}
	}
	void display()
	{
		cout << str;
	}
};


int main()
{
	String strObject; //The Object Does Not Contain Anything 
	try
	{
		strObject.replace('+',' '); //The replace Function Raises An Exception 
		strObject.display();
	}
	catch(char *message)
	{
		cout << "Exception : " << message << endl;
	}
	catch(...)
	{
		cout <<"Unknown Exception!" <<endl;
	}
	return 0;
}

⌨️ 快捷键说明

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