c++问题,高手请帮忙。

来源:百度知道 编辑:UC知道 时间:2024/06/23 15:47:14
#include <iostream>
using namespace std;

const int MAXNUM = 100;

class Set {
private:
int num; // 元素个数
char setdata[MAXNUM]; // 字符数组,用于存储集合元素
public:
Set(char *s); // 构造函数,用字符串s构造一个集合对象
bool InSet(char c); // 判断一个字符c是否在集合中,若在,返回true,否则返回false
void Print() const; // 输出集合中所有元素
};

Set::Set(char *s)
{
num = 0;
while (*s){
//**********found**********
if (______________________) // TODO: 添加代码,测试元素在集合中不存在
//**********found**********
______________________; // TODO: 添加一条语句,加入元素至集合中
s++;
}
}

bool Set::InSet(char c)
{
for (int i = 0; i < num; i++)
//**********found**********
if (______________________) // TODO: 添加代码,测试元素c是否与集合中某元素相同
//**********found**********
______________________; // TODO: 添加一条语句,进行相应处理

return false;
}

void Set::Print() const
{
cou

#include <iostream>
using namespace std;

const int MAXNUM = 100;

class Set {
private:
int num; // 元素个数
char setdata[MAXNUM]; // 字符数组,用于存储集合元素
public:
Set(char *s); // 构造函数,用字符串s构造一个集合对象
bool InSet(char c); // 判断一个字符c是否在集合中,若在,返回true,否则返回false
void Print() const; // 输出集合中所有元素
};

Set::Set(char *s)
{
num = 0;
while (*s){
//**********found**********
if (*s != setdata[num]) // TODO: 添加代码,测试元素在集合中不存在
//**********found**********
setdata[num++] = *s; // TODO: 添加一条语句,加入元素至集合中
s++;
}
}

bool Set::InSet(char c)
{
for (int i = 0; i < num; i++)
//**********found**********
if (setdata[i] == c) // TODO: 添加代码,测试元素c是否与集合中某元素相同
//**********found**********
return true; // TODO: 添加一条语句,进行相应处理

return false;
}

void Set::Print() const
{