Parcourir la source

Загрузить файлы 'moon'

miket il y a 1 an
Parent
commit
f55593c7eb
3 fichiers modifiés avec 405 ajouts et 0 suppressions
  1. 255 0
      moon/datetime.cpp
  2. 62 0
      moon/datetime.h
  3. 88 0
      moon/moon.cpp

+ 255 - 0
moon/datetime.cpp

@@ -0,0 +1,255 @@
+#include "datetime.h"
+#include <string.h>
+
+
+//Конструкторы
+
+//создать из трёх чисел
+void date::create_from_numbers(int ayear, int amonth, int adate) {
+	unsigned long long a, y, m;
+
+
+	//промежуточные
+	a = (14 - (double)amonth) / 12;
+
+	y = ayear + 4800 - a;
+
+	m = amonth + 12 * a - 3;
+
+	julian = adate + (153 * m + 2) / 5 + 365 * y + y / 4 - 32083;
+
+
+	//обратно в дату
+	date_from_julian();
+
+
+	if (ayear != year || amonth != month || adate != day) {
+
+		cout << year << " " << month << " " << day;
+		throw date_exception();
+	}
+
+
+};
+//в дату из юлианского
+void date::date_from_julian() {
+	unsigned long long m, c, d, e;
+	c = julian + 32082;
+
+	d = (4 * c + 3) / 1461;
+
+	e = c - (1461 * d) / 4;
+
+	m = (5 * e + 2) / 153;
+
+	day = e - (153 * m + 2) / 5 + 1;
+
+	month = m + 3 - 12 * (m / 10);
+
+	year = d - 4800 + m / 10;
+
+}
+
+//конструктор даты из интов
+date::date(int ayear, int amonth, int adate) {
+	create_from_numbers(ayear, amonth, adate);
+
+
+}
+
+//конструктор даты из массива символов
+date::date(char word[]) {
+	int index = 0, max = 0, spaces = 0, dots = 0;
+	while (word[index] != '\0') {
+		max = max > (int)(word[index]) ? max : (int)(word[index]);
+		spaces = word[index] == ' ' ? spaces + 1 : spaces;
+		dots = word[index] == '.' ? dots + 1 : dots;
+		index++;
+
+	}
+
+	//конструктор типа dd.mm.yyyy
+	if (max <= 57 && max >= 46 && dots == 2) {
+		date_split(word, '.');
+	}
+	//конструктор типа d месяц y
+	else if (spaces == 2) {
+		date_words(word);
+	}
+	else {
+		throw date_exception();
+	}
+
+}
+
+//по умолчанию
+date::date() {
+	create_from_numbers(0, 1, 1);
+}
+
+
+//вспомогательные
+//перевод в инт
+int char_to_int(char word[], int index, char splitter) {
+	index--;
+	int dec = 1, ret = 0;
+	while (index != -1 && word[index] != splitter) {
+		int cur = (int)(word[index]) - 48;
+		ret += cur * dec;
+
+
+		dec *= 10;
+		index--;
+	}
+
+	return ret;
+}
+
+//перевод месяца
+int word_to_int(char word[], int index, char splitter) {
+	index++;
+	int cur_index = index;
+	char word_tmp[80];
+	while (word[cur_index] != splitter) {
+		word_tmp[cur_index - index] = word[cur_index];
+		cur_index++;
+	}
+
+
+
+
+	for (int i = 0; i <= 11; i++) {
+		bool swch = 1;
+		cur_index = 0;
+		while (word_tmp[cur_index] != -52) {
+
+			if (word_tmp[cur_index] != MONTHS[i][cur_index]) {
+				swch = 0;
+				break;
+			}
+
+			if (swch)
+				return i + 1;
+			cur_index++;
+		}
+	}
+	throw date_exception();
+}
+
+
+
+
+
+
+
+
+
+//разница дней
+const unsigned long long& date::operator-(const date& d)
+{
+	// TODO: вставьте здесь оператор return
+	unsigned long long j1, j2;
+	j1 = this->julian;
+	j2 = d.julian;
+
+
+	return j1 > j2 ? (j1 - j2) : (j2 - j1);
+}
+
+
+//получить день недели
+void date::week_day() {
+	int index = 0;
+	while (DAYS[julian % 7 + 1][index] != '\0') {
+		cout << DAYS[julian % 7 + 1][index];
+		index++;
+	}
+	cout << endl;
+}
+
+//пасха
+const date& date::get_dates_year_easter() {
+	int a = year % 19;
+	int b = year % 4;
+	int c = year % 7;
+	int d = (19 * a + 15) % 30;
+	int e = (2 * b + 4 * c + 6 * d + 6)%7;
+	int f = d + e;
+
+	
+	if (f<=9)
+		return date(year,3,22+f);
+	return date(year, 4, f - 9);
+
+
+}
+
+
+
+
+
+
+
+
+
+//приватные
+
+//формат dd mm yyyy
+void date::date_split(char word[], char splitter) {
+	int index = 0, swich = 0;
+
+	int full_date[3];
+
+	while (word[index] != '\0') {
+		if (word[index] == splitter) {
+			full_date[swich] = char_to_int(word, index, splitter);
+			swich++;
+		}
+
+		index++;
+	}
+	full_date[2] = char_to_int(word, index, splitter);
+
+	full_date[2] = full_date[2] / 100 == 0 ? full_date[2] + 2000 : full_date[2];
+
+	create_from_numbers(full_date[2], full_date[1], full_date[0]);
+
+	delete[] word;
+
+}
+
+
+//формат 1 месяц 2021
+void date::date_words(char word[])
+{
+	char splitter = ' ';
+	int full_date[3];
+	int index = 0;
+	bool swch = 1;
+
+
+	while (word[index] != '\0') {
+
+		if (word[index] == splitter && swch) {
+
+			full_date[0] = char_to_int(word, index, splitter);
+			full_date[1] = word_to_int(word, index, splitter);
+
+			swch = !swch;
+		}
+
+		index++;
+
+	}
+	full_date[2] = char_to_int(word, index, splitter);
+
+	create_from_numbers(full_date[2], full_date[1], full_date[0]);
+	delete[] word;
+
+}
+
+ostream& operator<<(ostream& os, date& d)
+{
+	os << d.day << "." << d.month << "." << d.year;
+	return os;
+}

+ 62 - 0
moon/datetime.h

@@ -0,0 +1,62 @@
+#include<iostream>
+#include <string>
+//êåñëè þçàþ ñëîâàðè - íàäî äîêàçàòü
+
+
+
+using namespace std;
+
+const char MONTHS[12][80] = { {"January"},{"Febuary"},{"March"},{"April"},{"May"},{"June"},{"July"},{"August"},{"September"},{"October"},{"November"},{"December"} };
+const char DAYS[7][80] = { {"Monday"},{"Tuesday"},{"Wednesday"},{"Thursday"},{"Friday"},{"Saturday"},{"Sunday"} };
+#pragma once
+class date
+{
+private:
+	unsigned long long julian;
+
+	void date_split(char word[], char splitter);
+
+	void date_words(char word[]);
+
+
+	void create_from_numbers(int, int, int);
+
+	void date_from_julian();
+
+
+public:
+	int day, month, year;
+
+	void week_day();
+
+	char actual[];
+
+
+
+
+	date();
+
+
+	date(char word[]);
+
+
+	date(int year, int month, int date);
+
+
+	const date& get_dates_year_easter();
+
+	
+	const unsigned long long& operator - (const date& d);
+	
+
+
+	friend ostream& operator <<(ostream& os, date& d);
+
+
+
+
+};
+
+class date_exception {
+
+};

+ 88 - 0
moon/moon.cpp

@@ -0,0 +1,88 @@
+// moon.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
+//
+
+#include <iostream>
+#include <fstream>
+#include "datetime.h"
+
+
+
+using namespace std;
+
+
+int skip_col(string, int);
+
+int main()
+{
+	ifstream data_file;
+	data_file.open("./Moon/moon1998.dat");
+	if (!data_file.is_open()) {
+		cout << "not opened";
+		return -1;
+	
+	}
+
+	string line;
+	date line_date;
+
+
+
+
+	getline(data_file, line);
+	while (getline(data_file, line)) {
+
+		int year, month, day;
+
+		year = (line[0] - 48) * 1000 + (line[1] - 48) * 100 + (line[2] - 48) * 10 + (line[3] - 48);
+
+		month = (line[4] - 48) * 10 + (line[5] - 48);
+
+		day = (line[6] - 48) * 10 + (line[7] - 48);
+
+
+		cout << year << "-" << month << "-" << day << '\n';
+
+
+
+
+
+		line_date = date(year,month,day);
+
+		int el = skip_col(line, 4);
+		cout << line <<  '\t' << line_date << '\t' << line[el] << endl;
+
+
+
+
+
+	}
+
+
+
+
+}
+
+int skip_col(string line, int amount) {
+	int i = 0;
+	for (int j = 0; j < amount; j++) {
+		while (line[i] >= 45 && line[i] <= 57)
+			i++;
+		while (!(line[i] >= 45 && line[i] <= 57)) {
+			i++;
+		}
+	
+	}
+	return i;
+
+}
+
+// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
+// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
+
+// Советы по началу работы 
+//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
+//   2. В окне Team Explorer можно подключиться к системе управления версиями.
+//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
+//   4. В окне "Список ошибок" можно просматривать ошибки.
+//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
+//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.