目录

清明节作业

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

}

本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
Brookty35 分钟前
【算法】归并排序
数据结构·算法·排序算法
·醉挽清风·36 分钟前
学习笔记—C++—模板初阶
开发语言·c++·笔记·学习
User_芊芊君子37 分钟前
跨平台开发选Java还是C?应用场景与性能深度对比
java·c语言·开发语言
一只小松许️2 小时前
Rust泛型与特性
java·开发语言·rust
虾球xz2 小时前
游戏引擎学习第216天
服务器·c++·学习·游戏引擎
星星火柴9363 小时前
数据结构:哈希表 | C++中的set与map
数据结构·c++·笔记·算法·链表·哈希算法·散列表
搬砖工程师Cola4 小时前
<C#>在 C# .NET 6 中,使用IWebHostEnvironment获取Web应用程序的运行信息。
开发语言·c#·.net
没有啥的昵称5 小时前
从源码安装ROS的serial包(替换github的方案)
c++
CS创新实验室5 小时前
数据结构:最小生成树的普里姆算法和克鲁斯卡尔算法
数据结构·算法·图论·计算机考研
八了个戒6 小时前
「数据可视化 D3系列」入门第三章:深入理解 Update-Enter-Exit 模式
开发语言·前端·javascript·数据可视化