trung0246 / cs-a150 Goto Github PK
View Code? Open in Web Editor NEWStuff for the class...
License: The Unlicense
Stuff for the class...
License: The Unlicense
#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;
}
h08.cpp
#define HW
#include "../../tools.hpp"
//ONLY for example purpose, please don't copy the code directly :)
using namespace std;
string STUDENT = "";
#include "h08.h"
std::string dataSets(const std::string & fileName) {
double sum = 0, count = 0;
int real = 0, set = 1;
string rel;
ifstream istrm(fileName, ios_base::binary);
if (!istrm.is_open()) {
cout << "Failed to open " << fileName << '\n';
return fileName + " cannot be opened.";
}
string data;
char ch, prev = ' ';
while (istrm.get(ch)) {
if (prev == ' ' && ch == '0' && istrm.peek() == ' ') {
ostringstream temp;
temp << "data set " << set << ": total values = " << count <<
"\naverage value = " << fixed << setprecision(4) << sum / count << "\n\n";
rel += temp.str();
count = 0;
sum = 0;
set++;
istrm.get(ch);
prev = ch;
}
if (!(isdigit(ch) || ch == '.') && isdigit(prev)) {
if (real > 0) {
sum += real * atof(data.c_str());
real = 0;
} else {
real = atoi(data.c_str());
count += real;
}
data = "";
} else {
data += ch;
}
prev = ch;
}
istrm.close();
if (rel.size() > 0) {
rel.erase(rel.size() - 1, 1);
}
return rel;
}
tools.hpp
#define _USE_MATH_DEFINES
#include <string>
#include <cmath> //https://stackoverflow.com/questions/10694255/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <functional>
#if (__cplusplus == 201103L) //https://stackoverflow.com/questions/2324658/
//remove_all to guarantee for always pure type https://stackoverflow.com/questions/14522496
#include <type_traits>
#endif
//#pragma warning(push)
//#pragma warning(disable: 3338)
template<class T> struct remove_all { typedef T type; };
template<class T> struct remove_all<T*> : remove_all<T> {};
template<class T> struct remove_all<T&> : remove_all<T> {};
//template<class T> struct remove_all<T&&> : remove_all<T> {};
template<class T> struct remove_all<T const> : remove_all<T> {};
template<class T> struct remove_all<T volatile> : remove_all<T> {};
template<class T> struct remove_all<T const volatile> : remove_all<T> {};
//#pragma warning(pop)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.