![](https://i-blog.csdnimg.cn/blog_migrate/eefdff4d2240ba02f25fd582353c8e14.png)
![](https://i-blog.csdnimg.cn/blog_migrate/704dd9f9a3f55959b662e4b4ce1249b9.png)
#include <iostream>
using namespace std;
class A
{
int a;
public:
void set();
void Sum();
void Product();
void PrimeNumber();
};
void A::set()
{
cin >> a;
}
void A::Sum()
{
int num = 0;
for(int i=1; i<=a; i++)
num = num + i;
cout << num << endl;
}
void A::Product()
{
int ret = 1;
for(int i=1; i<=a; i++)
ret = ret * i;
cout << ret << endl;
}
void A::PrimeNumber()
{
int j;
for(int i=1; i<=a; i++)
{
for(j=2; j<i; j++)
{
if(i%j==0)
break;
}
if(i==j)
{
cout << i << "\t";
}
}
}
int main()
{
A a1;
a1.set();
a1.Sum();
a1.Product();
a1.PrimeNumber();
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/f42957e87bbd79e2c4b6ee1931c5e2ca.png)
![](https://i-blog.csdnimg.cn/blog_migrate/61dfad424e4fc3e547824c1427bf1e85.png)
class A
{
int a;
int b;
public:
A():a(0),b(0){}
void MyGetChar()
{
b = a++;
if(b > 9)
b %= 10;
cout << b;
}
};
class B
{
char a;
char b;
public:
B():a(97),b(0){}
void MyGetChar()
{
char c = a++;
c -= 97;
c %= 26;
b = 97 + c;
cout << b;
}
};
int main()
{
A a1;
B b1;
for(int i=0; i<70; i++)
{
if(i%2 == 0)
a1.MyGetChar();
else
b1.MyGetChar();
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/7ea32ed653f40195e3a29bcbf0b96548.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7cd3363dcb82e5475272e0eb93e94fa8.png)
class A
{
public:
void dump(string s, int len)
{
cout << "字母为:";
for(int i=0; i<len; i++)
if(s[i] >= 'a' && s[i] <= 'z')
cout << s[i];
cout << endl;
}
};
class B
{
public:
void dump(string s, int len)
{
cout << "数字为:";
for(int i=0; i<len; i++)
if(s[i] >= '0' && s[i] <= '9')
cout << s[i];
cout << endl;
}
};
int main()
{
string s;
A a1;
B b1;
cin >> s;
int len = s.size();
a1.dump(s, len);
b1.dump(s, len);
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6cdb73fd54bf853955b18ffa7d428e07.png)