首页 > 其他分享 >实验四

实验四

时间:2023-11-30 19:56:53浏览次数:31  
标签:26 cout int text 实验 include string

实验任务5

实验代码:

textcoder.hpp

#pragma once

#include <iostream>
#include <vector>
#include <array>
#include <string>
using namespace std;

class TextCoder
{
private:
string text;
void encoder()
{
for(auto i=0; i<text.size(); i++) {
if(text.at(i) >= 'a' && text.at(i) <= 'z') {
text.at(i) = 'a' + (text.at(i) - 'a' + 7) % 26;
}
else if(text.at(i) >= 'A' && text.at(i) <= 'Z') {
text.at(i) = 'A' + (text.at(i) - 'A' + 7) % 26;
}
}
}
void decoder()
{
for(auto i=0; i<text.size(); i++) {
if(text.at(i) >= 'a' && text.at(i) <= 'z') {
text.at(i) = 'a' + (text.at(i)-'a' +26- 7) % 26;
}
else if(text.at(i) >= 'A' && text.at(i) <= 'Z') {
text.at(i) = 'A' + (text.at(i) -'A'+26 - 7) % 26;
}
}
}
public:
string get_ciphertext()
{
encoder();
return text;
}
string get_deciphertext()
{
decoder();
return text;
}
TextCoder(string a):text{a}{}
TextCoder(const TextCoder& b):text{b.text}{}

 


};

textcoder.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();
}

实验结果:

实验任务6

实验代码:

info.hpp

#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Info
{
public:
Info(string name, string contact, string city, int n);
void print();
private:
string name, contact, city;
int n;
};
Info::Info(string name, string contact, string city, int n)
{
this->name = name; this->contact = contact; this->city = city; this->n = n;
}
void Info::print()
{
cout << "昵称: " << name << endl;
cout << "联系方式: " << contact << endl;
cout << "所在城市: " << city << endl;
cout<<"预定人数: " << n << endl;
}

.cpp

#include<iostream>
#include<string>
#include<vector>
#include"info.hpp"
int main()
{
string a, b, c; int d,sum=0;
int const capacitd = 100;
vector<Info> x;
cout << "录入信息:" << endl<<endl;
cout << "昵称\t " << "联系方式(邮箱/手机号)\t " << "所在城市\t " << "预定参加人数\t" << endl;
for ( sum ;;)
{
cin >> a >> b>> c >> d;
Info z(a, b, c, d);
int y = sum;
if (sum+d > capacitd)
{
cout << "对不起,只剩" << capacitd - y << "个位置" << endl;
cout << "1.输入u,更新(update)预定信息" << endl;
cout << "2.输入o,退出(out)预定" << endl; char s;
cout << "您的选择:"; cin >> s;
if (s == 'u') continue; cout << endl;
break;
}
else
{
sum += d;
x.push_back(z);
}
}
cout << "截至目前,一共有" << sum << "听众预定参加。预定听众信息如下。" << endl;
for (int i = 0; i < x.size(); i++)
{
x[i].print();
cout<<endl;
}
}

实验结果:

 

标签:26,cout,int,text,实验,include,string
From: https://www.cnblogs.com/lwjddd/p/17868124.html

相关文章

  • 实验4 现代C++标准库与类模板
    四、实验内容1.实验任务1//在C++中定义和使用类模板task1_1.cpp#include<iostream>usingnamespacestd;//类A的定义classA{public:A(intx0,inty0):x{x0},y{y0}{}voidshow()const{cout<<x<<","<<y<<endl;}p......
  • 实验4 现代C++标准库与类模板
    实验任务1task1task1_1.cpp#include<iostream>usingstd::cout;usingstd::endl;classA{public:A(intx0,inty0):x{x0},y{y0}{}voidshow()const{cout<<x<<","<<y<<endl;}private:in......
  • 第三方实验室LIMS管理系统源码
    LIMS实验室信息管理系统源码LIMS系统的功能根据实验室的规模和任务而有所不同,其系统主要功能包括:系统维护、基础数据编码管理,样品管理、数据管理、报告管理、报表打印、实验材料管理、设备管理等。它可以取代传统的手工管理模式而给检测实验室带来巨大的变化,提高检测实验室的整体......
  • SSL——ASA防火墙——Cisco实验(详解)
    SSLVPN一、理论部分定义:SSLVPN,操作在OSI模型的会话层,可以使用户通过浏览器对VPN进行连接,但是没有隧道。使用https加密的范式进行数据传输,跨平台性强,只要终端设备有浏览器,能够上网,就可以进行VPN连接,并访问资源。扩展:可以通过DNS进行访问,或者使用花生壳注册免费域名进行访问ssl(......
  • LIMS实验室信息管理系统源码,支持二次开发
    LIMS实验室信息管理系统源码,支持二次开发LIMS实验室信息管理系统是一种软件类型,旨在通过跟踪与样品、实验、实验室工作流程和仪器相关的数据,提高实验室产能和效率。覆盖实验室从合同审批、委托下单、样品管理、生产调度、检测记录、报告管理、财务开票结算等全业务的过程管理。1、......
  • 实验四
    实验五TextCoder.hpp点击查看代码#include<string>classTextCoder{private:std::stringtext;voidencoder(){for(char&c:text){if(c>='a'&&c<='z'){c=((c......
  • 实验四-现代C++标准库与类模板
    TextCoder.hpp1#include<string>23classTextCoder{4private:5std::stringtext;67voidencoder(){8for(char&c:text){9if(c>='a'&&c<='z'){10......
  • 11.29实验21
    实验21:观察者模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解观察者模式的动机,掌握该模式的结构;2、能够利用观察者模式解决实际问题。[实验任务一]:股票提醒当股票的价格上涨或下降5%时,会通知持有该股票的股民,当股民听到价格上涨的消息时会买股票,当价格下降时......
  • 11.29实验22
    实验22:状态模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解状态模式的动机,掌握该模式的结构;2、能够利用状态模式解决实际问题。[实验任务一]:银行账户用Java代码模拟实现课堂上的“银行账户”的实例,要求编写客户端测试代码模拟用户存款和取款,注意账户对象状态......
  • 11.29实验23
    实验23:策略模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解策略模式的动机,掌握该模式的结构;2、能够利用策略模式解决实际问题。[实验任务一]:旅行方式的选择旅游的出行方式有乘坐飞机旅行、乘火车旅行和自行车游,不同的旅游方式有不同的实现过程,客户可以根据自......