1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【超アバウト注意!!】Let's C++プログラミング

Last updated at Posted at 2020-04-18

今回は初心者向けでアバウトな講座です。

今回の講座で

  • C/C++言語非常に簡単に使うことができるようになれます。
  • C/C++での基本的な書き方が学べます。
  • char型の扱い方が学べます。
chara.hpp
# include <string>

class ZipStream
{
public:
	ZipStream(int val);
	ZipStream(std::string val);
	ZipStream(std::string val, bool zipped);
	~ZipStream();
	ZipStream Zipped();
	ZipStream UnZipped();
	ZipStream operator+(ZipStream Z);
	ZipStream operator+=(ZipStream Z);
	inline std::string Get_Value() {
		return this->values;
	}
private:
	std::string values;
	bool now_zip;
	inline char Reter(int Oh) {
		return (char)Oh;
	}
	inline int Purse(char t) {
		return t & 0xff;
	}
};
chara.cpp
# include"chara.hpp"
# include <array>
# include <sstream>
using sstr = std::stringstream;

ZipStream::ZipStream(int val)
	:values(std::to_string(val))
	,now_zip(false)
{
}

ZipStream::ZipStream(std::string val)
	:values(val)
	,now_zip(false)
{
}

ZipStream::ZipStream(std::string val, bool zipped) 
	: values(val)
	,now_zip(zipped)
{

}

ZipStream ZipStream::operator+(ZipStream Z){
    if((Z.now_zip ^ this->now_zip) == false){
        ZipStream V(this->values + '\n' + Z.values,this->now_zip);
        return V;
    }
    else{
        return *this;
    }
}

ZipStream ZipStream::operator+=(ZipStream Z){
    if((Z.now_zip ^ this->now_zip) == false){
        this->values = this->values + '\n' + Z.values;
    }
    return *this;
}

ZipStream::~ZipStream()
{
}

ZipStream ZipStream::Zipped ()
{
	if (this->now_zip)
	{
		return *this;
	}
	sstr ss;
	for (auto l : this->values)
	{
		ss << std::hex << Purse(l) <<",";
	}
	this->values = ss.str();
	this->now_zip = true;
	return *this;
}

ZipStream ZipStream::UnZipped() {
	if (!this->now_zip)
	{
		return *this;
	}
	std::string ok, ret;
	int k;
	for (auto st : this->values)
	{
		if (st == ',') {
			std::istringstream(ok) >> std::hex >> k;
			ret += Reter(k);
			ok = "";
		}
		else
		{
			ok += st;
		}
	}
	this->values = ret.c_str();
	this->now_zip = false;
	return *this;
}

AbeOut.cpp
# include<iostream>
# include"chara.hpp"
using std::cout;
void AbeOut(int num) {
	ZipStream Z("e5,ae,89,e5,80,8d,e3,81,af,e8,be,9e,e3,82,81,e3,82,8d,", true);
	if (num>0)
	{
		cout << Z.UnZipped().Get_Value() << std::to_string(num) << std::endl;
	}
	else
	{
		cout << Z.UnZipped().Get_Value() << std::endl;
	}
}

int main(void) {
	AbeOut(210);
	AbeOut(0);
}
ターミナル
>>> cl /EHsc About.cpp chara.cpp

問題

  1. AbeOut(210)の答えを述べよ
  2. AbeOut(0)の答えを述べよ
1
0
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?