Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* solarSystemUI.cpp header file
- ======================================================================================================
- ENB241 | QUT Semester 1, 2015 | SolarArray Project
- ======================================================================================================
- This class was assigned to: <Student Name> | <ID Number>
- DESCRIPTION:
- <Brief description of what this file does>
- <Interfaces with user through command line interface, etc>
- ASSUMPTIONS
- *
- *
- *
- NOTES:
- *
- *
- *
- ======================================================================================================
- FILE CREATED: 09-05-2015
- LAST MODIFIED: 24-05-2015 by C. Odsey
- ======================================================================================================
- */
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::cerr;
- using std::endl;
- #include "bank.h"
- #include "power.h"
- // ANSI colour codes
- // These strings are interpreted by the terminal as a change colour command
- const char* DEFAULT = "\033[0m"; // Default White text
- const char* RED = "\033[31m"; // Fail colour - bad :(
- const char* YELLOW = "\033[33m";
- const char* GREEN = "\033[32m"; // Pass colour - good! :)
- const char* BLUE = "\033[34m";
- const char* CYAN = "\033[36m";
- const char* MAGENTA = "\033[35m";
- void StartUI();
- void StandardUI();
- void AdvancedUI();
- int cin_int(string variable);
- double cin_double(string variable);
- float cin_float(string variable);
- int main(int argc, char *argv[])
- {
- int flag = 1;
- cout << BLUE << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << CYAN << " SOLAR SYSTEM CALCULATOR! " << BLUE << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << DEFAULT << endl << endl;
- // Test code!
- while(flag == 1){
- StartUI();
- cout << "Program Complete, would you like to run it again? (1):Yes (2):No\n";
- cin >> flag;
- while(flag < 1 || flag > 2){
- cerr << "Invalid input, please enter 1 or 2 for Yes or No respetively!\n";
- cin >> flag;
- }
- }
- cout << "Program Terminating." << endl;
- return 0;
- }
- void StartUI(){
- cout << "Would you Like to use the (1) Standard or (2) Advanced User Interface?\n";
- int mode = 0;
- mode = cin_int("the mode");
- while(mode < 1 || mode > 2){
- cerr << "Invalid input, please enter 1 or 2 for Standard or Advanced respetively!\n";
- mode = cin_int("the mode");
- }
- if(mode == 1)
- StandardUI();
- else
- AdvancedUI();
- }
- void StandardUI(){
- //Test Standard Functionality
- cout << "---Standard User Interface---\n";
- cout << "-----------------------------\n";
- cout << "You will now be prompted for data, please enter the appropriate values.\n\n";
- //Declare the relevant variables
- int banks;
- double ratedpower, length, invefficiency, wireloss, tiltangle;
- float latitude, longitude, systemdecline, angleloss;
- cout << "Please enter the rated output of the panels: ";
- ratedpower = cin_double("rated output");
- cout << "Please enter the efficiency of the inverter: ";
- cout << "Please enter the loss due to the wire: ";
- cout << "Please enter the angle of tilt on the panels: ";
- cout << "Please enter the latitude of the system location: ";
- latitude = cin_float("latitude");
- cout << "Please enter the latitude of the system location: ";
- latitude = cin_float("latitude");
- cout << "Please enter the system's yearly decline: ";
- cout << "Please enter the loss due to angle: ";
- cout << "-------------------------------------------\n";
- cout << "Thank you, some data will now be processed.\n\n";
- //Call Bank constuctor
- //Call Power constructor
- /*
- Power StandardPower(ratedoutput, systemyearlydecline, angleloss, banks);
- cout << "The average yearly power your system will produce is " << StandardPower.AvgYearlyPow() << " watts per year.\n";
- cout << "The total power your system will produce in its lifetime is " << StandardPower.TotalLifePow() << " watts.\n";
- cout << "The following is a printout table of the projected power production for the life of the system\n";
- StandardPower.PrintTable();\
- */
- }
- void AdvancedUI(){
- //Test Advanced Functionality
- cout << "---Advanced User Interface---\n";
- cout << "-----------------------------\n";
- cout << "You will now be prompted for data, please enter the appropriate values.\n\n";
- //Declare relevant variables
- //Display power stats for the user's system
- /*
- cout << "The average yearly power your system will produce is " << Advanced.AvgYearlyPow() << " watts per year.\n";
- cout << "The total power your system will produce in its lifetime is " << Advanced.TotalLifePow() << " watts.\n";
- cout << "The following is a printout table of the projected power production for the life of the system\n";
- StandardPower.PrintTable();
- */
- //Display the cost-benefit stats for the user's system
- }
- int cin_int(string variable)
- {
- // Validates and returns INT variable input from user
- // Doesn't check for overflow or underflow
- int inNum = 0;
- do
- {
- if (cin.fail())
- {
- cin.clear();
- while (cin.get() != '\n');
- cerr << RED << "ERROR: Invalid input for " << variable << "." << DEFAULT;
- cout << "Please enter a correct value for " << variable << ": ";
- }
- cout << "Enter " << variable << ": " << endl;
- cin >> inNum;
- } while (!cin.good());
- return inNum;
- }
- double cin_double(string variable)
- {
- // Validates and returns DOUBLE variable input from user
- // Doesn't check for overflow or underflow
- double value = 0;
- bool validInput = false;
- char *endPtr = NULL;
- string input;
- while(!validInput)
- {
- value = 0;
- cin.sync();
- getline(cin, input, '\n');
- value = strtod(input.c_str(), &endPtr);
- // Check for characters in input string
- if (endPtr == input || *endPtr != '\0')
- {
- cerr << RED << "ERROR: Invalid input for " << variable << "." << DEFAULT << endl;
- cout << "Please enter a correct value for " << variable << ": ";
- validInput = false;
- }
- // otherwise correct input
- else
- validInput = true;
- }
- return value;
- }
- float cin_float(string variable)
- {
- // Validates and returns FLOAT variable input from user
- // Doesn't check for overflow or underflow
- float value = 0;
- bool validInput = false;
- char *endPtr = NULL;
- string input;
- while(!validInput)
- {
- value = 0;
- cin.sync();
- getline(cin, input, '\n');
- value = strtof(input.c_str(), &endPtr);
- // Check for characters in input string
- if (endPtr == input || *endPtr != '\0')
- {
- cerr << RED << "ERROR: Invalid input for " << variable << "." << DEFAULT << endl;
- cout << "Please enter a correct value for " << variable << ": ";
- validInput = false;
- }
- // otherwise correct input
- else
- validInput = true;
- }
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement