清明节作业

#include <iostream>

using namespace std;

int mproduct(int a)

{

if(a>1)

{

return a*mproduct((a-1));

}

else

{

return 1;

}

}

class number

{

int a;

public:

number():a(5){};

number(int a):a(a){}

void set(int a){this->a=a;}

void sum(){

int sun=0;

for(int i=1;i<=a;i++)

{

sun+=i;

}

cout<<"sun="<<sun<<endl;

}

void product(){

cout<<mproduct(a)<<endl;

}

void primeNumber(){

for(int j=1;j<a;j++){

if(a%j==0){

continue;

}else{

cout<<j<<" ";

}

}

cout<<endl;

}

};

int main()

{

number num;

num.set(12);

num.sum();

num.product();

num.primeNumber();

return 0;

}

实现字符串交错输出

#include <iostream>

using namespace std;

class A

{

string str;

int a;

public:

A():str("abcdefghijklmnopqrstuvwxyz"),a(0){}

void mygetchar()

{

cout <<str.at(a)<<" ";

a=(a+1)%26;

}

};

class B{

string str;

int a;

public:

B():str("1234567890"),a(0){}

void mygetchar()

{

cout<<str.at(a)<<" ";

a=(a+1)%10;

}

};

int main()

{

A a;

B b;

int i=0;

int len;

cin>>len;

while(i++<len)

{

a.mygetchar();

b.mygetchar();

}

return 0;

}

将字母和数字分别存入两个不同的类的对象,然后输出。

#include <iostream>

#include<cstring>

#include<stdio.h>

using namespace std;

class A

{

string a;

public:

A()

{

}

void myinsert(char c)

{

a+=c;

}

void show(){

cout<<a<<endl;

}

};

class B

{

string b;

public:

B(){}

void myinsert(char c)

{

b+=c;

}

void show(){

cout<<b<<endl;

}

public:

};

int main()

{

string str;

A A;

B B;

//char a128;

cin>>str;

cout<<"字符串输入成功"<<endl;

for(unsigned int i=0;i<str.length();i++)

{

if(str.at(i)<'9'&&str.at(i)>'0')

{

A.myinsert(str.at(i));

}

else

{

B.myinsert(str.at(i));

}

}

A.show();

B.show();

return 0;

}

相关推荐
czhc11400756631 小时前
退出防呆:用“总闸“收口所有退出入口,以及三个并发语法坑
开发语言·c#
高山有多高1 小时前
【Linux笔记】Linux自定义Shell
linux·c++
papaofdoudou1 小时前
初中数学-整数整除判定法全解:从 2 到 19 的方法、依据与证明
算法
让学习成为一种生活方式1 小时前
啤酒花基因组与重测序--Nature Communications
人工智能·算法
悠仁さん1 小时前
【C++】vector 类
开发语言·c++
_upupup2 小时前
智能指针的原理及简单模拟实现(C++)
开发语言·c++
l1t2 小时前
DeepSeek总结的OpenZL压缩变换器
c++·算法
想吃火锅10052 小时前
【leetcode】238.除了自身以外数组的乘积js
javascript·算法·leetcode
en.en..2 小时前
C语言---宏
c语言·开发语言
郝学胜-神的一滴2 小时前
C++ Templates 01:拨开迷雾,读懂C++模板经典著作
开发语言·c++·程序人生·游戏·游戏引擎·软件构建