首页 > 其他分享 >实验三

实验三

时间:2022-10-25 20:47:11浏览次数:33  
标签:info ci string int void 实验 include

task5:

//info.hpp

#include<iostream>
#include<string>
using namespace  std;
class info {
private:
    string nickname, contact, city;
    int n;
    static int a;
public:
    info(string ni, string co, string ci, int nn) :nickname(ni), contact(co), city(ci), n(nn) { a += n; }
    info() :nickname("n"), contact("co"), city("ci"), n(0) {}
    void print()const;
    static void printa();
    static int geta() { return a; }
};
int info::a = 0;
void info::print()const {
    cout << "昵称:     " << nickname << endl;
    cout << "联系方式: " << contact << endl;
    cout << "城市:     " << city << endl;
    cout << "预定人数:  " <<n<<endl << endl;
}
void info::printa() {
    cout << "截至目前,一共有" << a << "位听众预定参加。预定听众信息如下:"<<endl;
}

//task5.cpp

#include<iostream>
#include<string>
#include<iomanip>
#include"info.hpp"
using namespace std;
const int capacity = 100;
int main() {
    string ni, co, ci, choose;
    int nn, f = 1, l = 0;
    info vector[capacity];
    cout << "录入信息:" << endl << endl;
    cout <<  "昵称\t\t"<< "联系方式(邮箱/手机号)\t\t" << "所在城市\t\t" << "预定参加人数\t\t" << endl;
    while (cin >> ni>>co>> ci>> nn) {
        if (info::geta()+nn> 100) { f = 0; break; }
        info i(ni, co, ci, nn);
        vector[l] = i;
        l++;
    }
    if (f == 0) {
        cout << "对不起,只剩" << capacity - info::geta() << "个位置。" << endl << "1.输入u,更新预定信息" << endl << "2.输入q,退出预定" << endl << "你的选择:";
        cin >> choose;
        cout << endl << endl;
    }
    info::printa();
    for (int j = 0; j < l; j++) {
        vector[j].print();
    }
}

运行结果:

 

task6:

//textcoder.hpp

#include<iostream>
#include<string>
using namespace std;
class TextCoder {
public:
    TextCoder(){}
    TextCoder(string t):text(t){}
    string get_ciphertext();
    string get_deciphertext();
private:
    string text;
    void encoder();//形参列表为空!
    void decoder();
};

void TextCoder::encoder() {
    for (int i = 0; i < text.length(); i++) {
        if (('a' <= text[i] && text[i] <= 'z') || ('A' <= text[i] && text[i] <= 'Z')) {
            if (('v' <= text[i] && text[i] <= 'z') || ('V' <= text[i] && text[i] <= 'Z')) { text[i] = text[i] - 21; }
            else { text[i] = text[i] + 5;}
        }
    }
    
}
string TextCoder::get_ciphertext() {
    
    encoder();
    return text;
}
string TextCoder::get_deciphertext() {
    
    decoder();
    return text;
}
void TextCoder::decoder() {
    for (int i = 0; i <text.length(); i++) {
        if (('a' <= text[i] && text[i] <= 'z') || ('A' <= text[i] && text[i] <= 'Z')) {
            if (('f' <= text[i] && text[i] <= 'z') || ('F' <= text[i] && text[i] <= 'Z')) { text[i] = text[i] - 5; }
            else { text[i] = text[i] + 21;}
        }    
    }
}

//task6.cpp

#include "textcoder.hpp"
#include <iostream>
#include <string>
void test() {
    using namespace std;
    string text, encoded_text, decoded_text;
    cout << "输入英文文本: ";
    while (getline(cin, text)) {
        encoded_text = TextCoder(text).get_ciphertext(); // 这里使用的是临时无名对象
            cout << "加密后英文文本:\t" << encoded_text << endl;
        decoded_text = TextCoder(encoded_text).get_deciphertext(); // 这里使用的是临时无名对象
            cout << "解密后英文文本:\t" << decoded_text << endl;
        cout << "\n输入英文文本: ";
    }
}
int main() {
    test();
}

运行结果:

 

 

标签:info,ci,string,int,void,实验,include
From: https://www.cnblogs.com/jww12/p/16819794.html

相关文章

  • 实验3
    #include"info.hpp"#include<iostream>#include<vector>#include<cstring>intmain(){intcount=0;constintcapacity=100;vector<Info>audience_......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBox或......
  • 实验7:基于REST API的SDN北向应用实践
    实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。实验要求(一)基本要求编写Python程序,调用OpenDayl......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境1.下载虚拟机软件OracleVisua......
  • 决策树算法实验
     【实验目的】理解决策树算法原理,掌握决策树算法框架;理解决策树学习算法的特征选择、树的生成和树的剪枝;能根据不同的数据类型,选择不同的决策树算法;针对特定应用场......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i)......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......
  • 实验3
    一、实验目的知道什么是类模板,会正确定义和使用简单的类模板能够描述数组的特性,会使用C++语法正确定义和访问内置数组,知道其局限性能够解释指针变量的特性,会使用C++语......