Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h09 #3

Open
Trung0246 opened this issue Mar 8, 2019 · 0 comments
Open

h09 #3

Trung0246 opened this issue Mar 8, 2019 · 0 comments

Comments

@Trung0246
Copy link
Owner

#include "h09.h"
#include BOOST_MODULE(array)

std::string STUDENT = "";

#define FUNC (const std::string& msg) { prssPrmt(msg);

void prssPrmt(const std::string& msg) {
	std::cout << msg;
	if (!msg.empty() && msg.at(msg.size() - 1) != ' ') std::cout << ' ';
}

std::string getData(bool isStr) {
	std::string data, prev;

	while (getline(std::cin, data)) std::swap(prev, data);

	if (!data.empty() && (isStr || (std::isdigit(data.at(0)) || !std::isalpha(data.at(0)))))
		return data;

	return prev;
}

std::string getLine FUNC
	std::string data;
	getline(std::cin, data);
	return data;
}

int getInt FUNC
	return std::stoi(getData(false));
}

double getReal FUNC
	return std::stod(getData(false));
}

const boost::array<std::string, 6> TRUTHY {{
	"y", "yes", "yep", "ok", "fine", "true",
}};

bool getYN FUNC
	std::string data = getData(true);

	data.erase(std::remove_if(data.begin(), data.end(), ::isspace), data.end());
	std::transform(data.begin(), data.end(), data.begin(), ::tolower);

	for (const std::string& str: TRUTHY) {
		if (data == str) return true;
	}
	return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant