Bläddra i källkod

moon_not_optimized

m513t20 11 månader sedan
förälder
incheckning
89702fd102
3 ändrade filer med 115 tillägg och 9 borttagningar
  1. 30 0
      moon/datetime.cpp
  2. 5 0
      moon/datetime.h
  3. 80 9
      moon/moon.cpp

+ 30 - 0
moon/datetime.cpp

@@ -157,6 +157,36 @@ const unsigned long long& date::operator-(const date& d)
 }
 
 
+
+const bool& date::operator<(const date& d)
+{
+	return julian < d.julian;
+}
+
+const bool& date::operator>=(const date& d)
+{
+	return julian >= d.julian;
+}
+
+const bool& date::operator>(const date& d)
+{
+	return julian > d.julian;
+}
+
+const bool& date::operator<=(const date& d)
+{
+	return julian <= d.julian;
+}
+
+const bool& date::operator==(const date& d)
+{
+	return julian == d.julian;
+}
+
+
+
+
+
 //получить день недели
 void date::week_day() {
 	int index = 0;

+ 5 - 0
moon/datetime.h

@@ -48,6 +48,11 @@ public:
 	
 	const unsigned long long& operator - (const date& d);
 	
+	const bool& operator<(const date& d);
+	const bool& operator>(const date& d);
+	const bool& operator>=(const date& d);
+	const bool& operator<=(const date& d);
+	const bool& operator==(const date& d);
 
 
 	friend ostream& operator <<(ostream& os, date& d);

+ 80 - 9
moon/moon.cpp

@@ -11,24 +11,44 @@ using namespace std;
 
 
 int skip_col(string, int);
+void take_moon_survey(date);
+double get_EL(string, int);
 
 int main()
 {
+
+	date examp(2023, 03, 9);
+	take_moon_survey(examp);
+
+
+
+}
+
+
+void take_moon_survey(date some_date){
 	ifstream data_file;
-	data_file.open("./Moon/moon1998.dat");
+	data_file.open("./Moon/moon2023.dat");
 	if (!data_file.is_open()) {
-		cout << "not opened";
-		return -1;
-	
+		cout << "not opened\n";
+		return;
+
 	}
 
 	string line;
 	date line_date;
+	date prev_date;
+	prev_date = date(some_date.year,01,01);
+	string rise_set = "Moon rising: ";
 
+	unsigned long long length_day=0,cur_length;
+	bool flag = 1;
 
 
-
+	cout << "date: " << some_date << endl;
 	getline(data_file, line);
+	double prev_val = -100.0;
+
+
 	while (getline(data_file, line)) {
 
 		int year, month, day;
@@ -39,29 +59,80 @@ int main()
 
 		day = (line[6] - 48) * 10 + (line[7] - 48);
 
+		line_date = date(year, month, day);
 
-		cout << year << "-" << month << "-" << day << '\n';
 
 
+		if (line_date == some_date)
+		{
 
+			int el = skip_col(line, 4);
+			double EL_val = get_EL(line, el);
+			if (prev_val > 0 && EL_val < 0)
+			{
+				cout << "Moon sets: " << line << endl;
+			}
 
+			if (prev_val < 0 && EL_val > 0)
+			{
+				cout << "Moon rises: " << line << endl;
+			}
 
-		line_date = date(year,month,day);
+			prev_val = EL_val;
 
-		int el = skip_col(line, 4);
-		cout << line <<  '\t' << line_date << '\t' << line[el] << endl;
 
 
+			//cout << line << '\t' << line_date  << '\t' << EL_val << endl;
+		}
+		else if (flag) {
+			length_day++;
+			flag = (line_date == prev_date);
+			
+		}
+		else {
+			for (unsigned long long i = 1; i < length_day; i++)
+				getline(data_file, line);
 
+		}
 
+	}
+	data_file.close();
+}
 
+double get_EL(string line, int index)
+{
+	double res = 0.0;
+	bool neg = (line[index] == 45);
+	int dot = neg ? index + 1 : index;
+	double dec_post_dot=1.0;
+	while (line[dot] !=46) {
+		dot++;
+	}
+	int start = dot + 1;
+	for ( start; line[start] < 58 && line[start]>45; start++) {
+		dec_post_dot /= 10;
 	}
+	start--;
+	for (start; line[start] < 58 && line[start] > 47; start--) {
+		res =res+ (line[start] - 48) * dec_post_dot;
+		dec_post_dot *= 10;
+	}
+	start--;
+	for (start; line[start] < 58 && line[start] > 47; start--) {
+		res += (line[start] - 48) * dec_post_dot;
+		dec_post_dot *= 10;
+	}
+
+
+	return neg? -1.0*res:res;
+
 
 
 
 
 }
 
+
 int skip_col(string line, int amount) {
 	int i = 0;
 	for (int j = 0; j < amount; j++) {