清明节作业

#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;

}

相关推荐
IT猿手13 分钟前
基于强化学习 Q-learning 算法求解城市场景下无人机三维路径规划研究,提供完整MATLAB代码
神经网络·算法·matlab·人机交互·无人机·强化学习·无人机三维路径规划
巨龙之路2 小时前
C语言中的assert
c语言·开发语言
2301_776681653 小时前
【用「概率思维」重新理解生活】
开发语言·人工智能·自然语言处理
熊大如如3 小时前
Java 反射
java·开发语言
万能程序员-传康Kk3 小时前
旅游推荐数据分析可视化系统算法
算法·数据分析·旅游
PXM的算法星球4 小时前
【并发编程基石】CAS无锁算法详解:原理、实现与应用场景
算法
ll7788114 小时前
C++学习之路,从0到精通的征途:继承
开发语言·数据结构·c++·学习·算法
烨然若神人~4 小时前
算法第十七天|654. 最大二叉树、617.合并二叉树、700.二叉搜索树中的搜索、98.验证二叉搜索树
算法
爱coding的橙子4 小时前
每日算法刷题Day2 5.10:leetcode数组1道题3种解法,用时40min
算法·leetcode
我不想当小卡拉米4 小时前
【Linux】操作系统入门:冯诺依曼体系结构
linux·开发语言·网络·c++