清明节作业

#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 a[128];

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;

}

相关推荐
️是781 分钟前
信息奥赛一本通(4005:【GESP2306一级】时间规划)
数据结构·c++·算法
tankeven2 分钟前
HJ174 交换到最大
c++·算法
xyq20242 分钟前
SQL CREATE INDEX
开发语言
Дерек的学习记录4 分钟前
Unreal Eangie 5:蓝图编程
开发语言·学习·ue5
AI科技星4 分钟前
基于v≡c第一性原理:密度的本质与时空动力学
人工智能·学习·算法·机器学习·数据挖掘
kishu_iOS&AI4 分钟前
机器学习 —— 聚类算法
人工智能·算法·机器学习·聚类
hope_wisdom5 分钟前
C/C++数据结构之树
数据结构·c++·二叉树·
FluxMelodySun11 分钟前
机器学习(三十一) 半监督SVM与图半监督学习
人工智能·算法·机器学习
添尹13 分钟前
Go语言基础之指针
开发语言·后端·golang
2401_8274999916 分钟前
python项目实战10-网络机器人01
开发语言·python