码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 清明作业 c++


    1.封装一个类,实现对一个数求累和阶乘质数 

    1. #include
    2. using namespace std;
    3. int mproduct(int a){
    4. if(a>1){
    5. return a*mproduct((a-1));
    6. }else{
    7. return 1;
    8. }
    9. }
    10. class number{
    11. int a;
    12. public:
    13. number():a(5){};
    14. number(int a):a(a){}
    15. void set(int a){this->a=a;}
    16. void sum(){
    17. int sun=0;
    18. for(int i=1;i<=a;i++){
    19. sun+=i;
    20. }
    21. cout<<"sun="<
    22. }
    23. void product(){
    24. cout<<mproduct(a)<
    25. }
    26. void primeNumber(){
    27. for(int j=1;j
    28. if(a%j==0){
    29. continue;
    30. }else{
    31. cout<" ";
    32. }
    33. }
    34. cout<
    35. }
    36. };
    37. int main()
    38. {
    39. number num;
    40. num.set(12);
    41. num.sum();
    42. num.product();
    43. num.primeNumber();
    44. return 0;
    45. }

    2.封装两个类,实现字符串交错输出 

    1. #include
    2. using namespace std;
    3. class A{
    4. string str;
    5. int a;
    6. public:
    7. A():str("abcdefghijklmnopqrstuvwxyz"),a(0){}
    8. void mygetchar(){
    9. cout <at(a)<<" ";
    10. a=(a+1)%26;
    11. }
    12. };
    13. class B{
    14. string str;
    15. int a;
    16. public:
    17. B():str("1234567890"),a(0){}
    18. void mygetchar(){
    19. cout<at(a)<<" ";
    20. a=(a+1)%10;
    21. }
    22. };
    23. int main()
    24. {
    25. A a;
    26. B b;
    27. int i=0;
    28. int len;
    29. cin>>len;
    30. while(i++
    31. a.mygetchar();
    32. b.mygetchar();
    33. }
    34. return 0;
    35. }

     

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

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. class A{
    6. string a;
    7. public:
    8. A(){
    9. }
    10. void myinsert(char c){
    11. a+=c;
    12. }
    13. void show(){
    14. cout<
    15. }
    16. };
    17. class B{
    18. string b;
    19. public:
    20. B(){}
    21. void myinsert(char c){
    22. b+=c;
    23. }
    24. void show(){
    25. cout<
    26. }
    27. public:
    28. };
    29. int main()
    30. {
    31. string str;
    32. A A;
    33. B B;
    34. //char a[128];
    35. cin>>str;
    36. cout<<"字符串输入成功"<
    37. for(unsigned int i=0;ilength();i++){
    38. if(str.at(i)<'9'&&str.at(i)>'0'){
    39. A.myinsert(str.at(i));
    40. }else{
    41. B.myinsert(str.at(i));
    42. }
    43. }
    44. A.show();
    45. B.show();
    46. return 0;
    47. }

  • 相关阅读:
    python中的模块与包
    lintcode 3605 · 二维网格偏移 【数组相关,模拟即可】
    基于火鹰优化算法的函数寻优算法
    通过Power Platform自定义D365CE业务需求 - 1. Microsoft Power Apps 简介
    Leetcode链表相关题目
    hive和hbase的使用问题
    GBASE 8A v953报错集锦43--使用 gcdump 指定参数 ignore-table 不导出指定的 表或视图
    ESP32基础应用之使用两个ESP32通过阿里云物联网平台实现相互通信
    6.S081 附加Lab4 从源代码看进程退出——exit,wait,kill
    C++: multiple and virtual inheritance under the hood
  • 原文地址:https://blog.csdn.net/m0_60953264/article/details/137395615
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号