📄 pex6_9.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "wex6_13.h"
#include "random.h"
void main(void)
{
// a,b define initial members of S and T, respectively
int a[] = {1,5,7,12,24,36,45,103,355,499};
int b[] = {2,3,5,7,8,9,12,15,36,45,56,103,255,355,498};
// values to be deleted from T
int delA[] = {8, 36,103, 498};
RandomNumber rnd;
int item;
// define sets S and T and U
Set S(a,10), T(b,15), U;
// put {1,2,3,...,50} in U
for (int i = 1; i <= 50; i++)
U.Insert(i);
// output S, T and note that U + {1..50}
cout << "S = " << S << endl;
cout << "T = " << T << endl;
cout << "U = {1..50}" << endl;
// compute and print S+T, S*T and S*U
cout << "S + T = " << (S+T) << endl;
cout << "S * T = " << S*T << endl;
cout << "S * U = " << S*U << endl;
// delete 8, 36,103, 498 from U
for (i = 0; i< 4; i++)
T.Delete(delA[i]);
// print new T
cout << "After deletion of 8,36,103,489, T = " << T << endl;
// generate a random integer in the range 1..9 and determine if
// it is in T
item = rnd.Random(9) + 1;
if (item^T)
cout << item << " is in set T" << endl;
else
cout << item << " is not in set T" << endl;
}
/*
<Run>
S = {1, 5, 7, 12, 24, 36, 45, 103, 355, 499}
T = {2, 3, 5, 7, 8, 9, 12, 15, 36, 45, 56, 103, 255, 355, 498}
U = {1..50}
S + T = {1, 2, 3, 5, 7, 8, 9, 12, 15, 24, 36, 45, 56, 103, 255, 355, 498, 499}
S * T = {5, 7, 12, 36, 45, 103, 355}
S * U = {1, 5, 7, 12, 24, 36, 45}
After deletion of 8,36,103,489, T = {2, 3, 5, 7, 9, 12, 15, 45, 56, 255, 355}
3 is in set T
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -