首页 > 其他分享 >实验三

实验三

时间:2022-10-20 22:12:12浏览次数:42  
标签:info cout text 实验 && include string

task5:

info.hpp

#pragma once

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class info
{
public:
info(string nickname,string contack,string city,int n):
nickname{nickname},contack{contack},city{city},n{n}{}
void print();
private:
string nickname,contack,city;
int n;
};
void info::print()
{
cout<<"昵称:\t\t"<<nickname<<endl;
cout<<"联系方式:\t"<<contack<<endl;
cout<<"所在城市:\t"<<city<<endl;
cout<<"预订人数:\t"<<n<<endl;
}

task5.cpp

#include"info.hpp"
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
const int capacity=100;
int n,count=0;
string nickname,contack,city;
vector<info>audience_info_list;
cout<<"录入信息:"<<endl;
cout<<"昵称\t\t"<<"联系方式(邮箱/手机号)\t"<<"所在城市\t"<<"预定参加人数\t"<<endl;
while(cin>>nickname)
{
cin>>contack>>city>>n;
count+=n;
if(capacity-count>=0)
{
info p=info(nickname,contack,city,n);
audience_info_list.push_back(p);
}
else
{
string choice;
count-=n;
cout<<"对不起,只剩"<<capacity-count<<"个位置"<<endl;
cout<<"1.输入u,更新(update)预定信息"<<endl;
cout<<"2.输入q,退出预定"<<endl;
cout<<"你的选择:" ;
cin>>choice;
if(choice=="q")
break;
else if(choice=="u")
{
cout<<"录入信息:"<<endl;
continue;
}
}
}
cout<<"截至目前,一共有"<<count<<"位听众预定参加。预定听众信息如下:"<<endl;
for(int i=0;i<audience_info_list.size();i++)
{
audience_info_list.at(i).print();
cout<<endl;
}

}

 

 

 

 

 

 task6:

 

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

#pragma once
#include<iostream>
#include<string>
class TextCoder()
{
public:
TextCoder(string text):text{text}{}
string get_ciphertext();
string get_deciphertext();
private:
string text;
void encoder();
void decoder();
};
string TextCoder::get_ciphertext()
{
encoder();
return text;
}
string TextCoder::get_deciphertext()
{
encoder();
return text;
}
void TextCoder::encoder()
{
for(auto &i:text)
{
if(i>='a'&&i<='u')
{
i+=5;
}
else if(i>='v'&&i<='z')
{
i-=21;
}
else if(i>='A'&&i<='U')
{
i+=5;
}
else if(i>='V'&&i<='Z')
{
i-=21;
}
}
}
void TextCoder::decoder()
{
for(auto &i:text)
{
if(i>='f'&&i<='z')
{
i-=5;
}
else if(i>='a'&&i<='e')
{
i+=21;
}
else if(i>='F'&&i<='Z')
{
i-=5;
}
else if(i>='A'&&i<='E')
{
i+=21;
}
}
}

 

标签:info,cout,text,实验,&&,include,string
From: https://www.cnblogs.com/CYYyyds030711/p/16810898.html

相关文章

  • 实验三
    实验任务五   info.hpp#pragmaonce#include<bits/stdc++.h>usingnamespacestd;classInfo{ public: Info(stringnick0,stringcontact0,stringcity0,int......
  • 实验5:开源控制器实践——POX
    基础要求只需要提交h1pingh2、h2和h3的tcpdump抓包结果截图,外加L2_learning模块代码流程图,其余文字请勿赘述;h1pingh2h1pingh3结论:无论h1pingh2还是h1ping......
  • 实验3 数组、指针与现代C++标准库
    实验任务五:Info.hpp:#pragmaonce#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classInfo{private:stringnickname,cont......
  • Python第七章实验报告
    一、实验题目Python第七章实例和实战作业二、实验目的和要求1.熟悉Pycharm的运行环境2.学习并掌握Python的面向对象程序设计三、主要仪器设备联想小新air15硬件:AMD......
  • 实验2
    1:生成随机数并赋给number2:生成学号随机数第i行有2(n-i)+1个数 ......
  • 第三次实验
    task5:#include<iostream>#include<vector>#include<string>#include"5.1.h"usingnamespacestd;intmain(){cout<<"录入信息:"<<endl;cout<<"昵称"<<"......
  • 实验3 数组、指针与现代C++标准库
    实验5#pragmaonce#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classinfo{public:info(stringnickname0,stringcontact......
  • 实验3
    实验任务51#pragmaonce23#include<iostream>4#include<iomanip>5#include<string>67usingstd::cout;8usingstd::endl;9usingstd::cin;1......
  • 实验五:开源控制器实践——POX
    (一)基本要求1、POX的forwarding.hubh1pingh2h1pingh3h2pingh3结论:将数据包广播转发2、POX的forwarding.l2_learningh1pingh2h1pingh3h2pingh3......
  • 实验三
    Info.hpp#include<iostream>#include<string>usingnamespacestd;classInfo{public:Info(stringname="",stringcon="",stringci="",intnu=0):ni......