Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unistd.h>
- #include <time.h>
- #include <fstream>
- using namespace std;
- void phase_newmoon()
- {
- cout << " _..._ " << endl;
- cout << " .:::::::. " << endl;
- cout << ":::::::::::" << endl;
- cout << ":::::::::::" << endl;
- cout << "`:::::::::'" << endl;
- cout << " `':::'' " << endl;
- cout << "N E W M O O N" << endl;
- }
- void phase_waxingcrescent()
- {
- cout << " _..._ " << endl;
- cout << " .::::. `. " << endl;
- cout << ":::::::. :" << endl;
- cout << ":::::::: :" << endl;
- cout << "`::::::' .'" << endl;
- cout << " `'::'-' " << endl;
- cout << "W A X I N G C R E S C E N T" << endl;
- }
- void phase_firstquarter()
- {
- cout << " _..._ " << endl;
- cout << " .:::: `. " << endl;
- cout << ":::::: :" << endl;
- cout << ":::::: :" << endl;
- cout << "`::::: .'" << endl;
- cout << " `'::.-' " << endl;
- cout << "F I R S T Q U A R T E R" << endl;
- }
- void phase_waxinggibbous()
- {
- cout << " _..._ " << endl;
- cout << " .::' `. " << endl;
- cout << "::: :" << endl;
- cout << "::: :" << endl;
- cout << "`::. .'" << endl;
- cout << " `':..-' " << endl;
- cout << "W A X I N G G I B B O U S" << endl;
- }
- void phase_fullmoon()
- {
- cout << " _..._ " << endl;
- cout << " .' `. " << endl;
- cout << ": :" << endl;
- cout << ": :" << endl;
- cout << "`. .'" << endl;
- cout << " `-...-' " << endl;
- cout << "F U L L M O O N" << endl;
- }
- void phase_waninggibbous()
- {
- cout << " _..._ " << endl;
- cout << " .' `::. " << endl;
- cout << ": :::" << endl;
- cout << ": :::" << endl;
- cout << "`. .::'" << endl;
- cout << " `-..:'' " << endl;
- cout << "W A N I N G G I B B O U S" << endl;
- }
- void phase_lastquarter()
- {
- cout << " _..._ " << endl;
- cout << " .' ::::. " << endl;
- cout << ": ::::::" << endl;
- cout << ": ::::::" << endl;
- cout << "`. :::::'" << endl;
- cout << " `-.::'' " << endl;
- cout << "L A S T Q U A R T E R" << endl;
- }
- void phase_waningcrescent()
- {
- cout << " _..._ " << endl;
- cout << " .' .::::. " << endl;
- cout << ": ::::::::" << endl;
- cout << ": ::::::::" << endl;
- cout << "`. '::::::'" << endl;
- cout << " `-.::'' " << endl;
- cout << "W A N I N G C R E S C E N T" << endl;
- }
- void phase_cycleall()
- {
- while (true)
- {
- phase_newmoon(); usleep(370000);
- phase_waxingcrescent(); usleep(370000);
- phase_firstquarter(); usleep(370000);
- phase_waxinggibbous(); usleep(370000);
- phase_fullmoon(); usleep(370000);
- phase_waninggibbous(); usleep(370000);
- phase_lastquarter(); usleep(370000);
- phase_waningcrescent(); usleep(370000);
- }
- }
- // *****************************************************************************
- // *****************************************************************************
- int main()
- {
- // decorative cycling function
- //phase_cycleall();
- // decorative cycling function
- // get the current date
- time_t theTime = time(NULL);
- struct tm *aTime = localtime(&theTime);
- int day = aTime->tm_mday;
- int month = aTime->tm_mon + 1;
- int year = aTime->tm_year + 1900;
- // get the current date
- // set up the previous date
- int prev_day = --aTime->tm_mday;
- int prev_month = aTime->tm_mon + 1;
- int prev_year = aTime->tm_year +1900;
- // set up the previous date
- // open the file for the year
- fstream inFile;
- if (year == 2017)
- {
- inFile.open("percent2017.txt");
- }
- if (year == 2018)
- {
- inFile.open("percent2018.txt");
- }
- if (year == 2019)
- {
- inFile.open("percent2019.txt");
- }
- if (year == 2020)
- {
- inFile.open("percent2020.txt");
- }
- // open the file for the year
- // variable for tracking the percentage
- float percentagevar;
- float yest_percentagevar;
- // variable for tracking the percentage
- // locate the correct percentage
- for (int i = 0; i < (day-1)*13+2+(month-1); i++)
- {
- inFile >> percentagevar;
- }
- // locate the correct percentage
- // close the file and clear the stream
- inFile.close();
- inFile.clear();
- // close the file and clear the stream
- // open the file for reading #2
- if (prev_year == 2017)
- {
- inFile.open("percent2017.txt");
- }
- if (prev_year == 2018)
- {
- inFile.open("percent2018.txt");
- }
- if (prev_year == 2019)
- {
- inFile.open("percent2019.txt");
- }
- if (prev_year == 2020)
- {
- inFile.open("percent2020.txt");
- }
- // locate the correct percentage, yesterday
- for (int i = 0; i < (prev_day-1)*13+2+(prev_month-1); i++)
- {
- inFile >> yest_percentagevar;
- }
- // locate the correct percentage, yesterday
- // close the file
- inFile.close();
- // close the file
- // determine if the moon is waxing
- int waxing_binary;
- if (yest_percentagevar > percentagevar) waxing_binary = 0;
- else waxing_binary = 1;
- // determine if the moon is waxing
- // UP TO THIS POINT WE HAVE READ THE FILE AND GOTTEN THE PERCENTAGE, STORED AS percentagevar.
- // AS WELL AS THE PERCENTAGE YESTERDAY. WE USED THIS TO DETERMINE waxing_binary
- // THE GOAL IS NOW TO CONVERT THIS PERCENTAGE TO AN ACTUAL MOON PHASE
- cout << "* * " << percentagevar*100 << "% ILLUMINTATED * *" << endl;
- if (percentagevar >= 0 && percentagevar < .08) // NEW MOON
- {
- phase_newmoon();
- }
- if (percentagevar >= .08 && percentagevar < .25 && waxing_binary == 1) // WAXING CRESCENT
- {
- phase_waxingcrescent();
- }
- if (percentagevar >= .25 && percentagevar <.6 && waxing_binary == 1) // FIRST QUARTER
- {
- phase_firstquarter();
- }
- if (percentagevar >= .6 && percentagevar < .9 && waxing_binary == 1) // WAXING GIBBOUS
- {
- phase_waxinggibbous();
- }
- if (percentagevar >= .9 && percentagevar < 1) // FULL MOON
- {
- phase_fullmoon();
- }
- if (percentagevar >= .6 && percentagevar < .9 && waxing_binary == 0) // WANING GIBBOUS
- {
- phase_waninggibbous();
- }
- if (percentagevar >= .25 && percentagevar < .6 && waxing_binary == 0) //LAST QUARTER
- {
- phase_lastquarter();
- }
- if (percentagevar >= .08 && percentagevar < .25 && waxing_binary == 0) //WANING CRESCENT
- {
- phase_waningcrescent();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement