diff options
| author | levidavis04 <[email protected]> | 2022-11-14 15:41:02 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-14 15:41:02 -0800 |
| commit | d82e1b71f7d003eead5d5350aaf7da41b142ae15 (patch) | |
| tree | 1dfe52fe23521322eaf7660a020555f1c65226d1 | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab2-levidavis04-master.tar.xz cst116-lab2-levidavis04-master.zip | |
| -rw-r--r-- | CST116-Lab2-Davis-PSEUDOCODE.rtf | 234 | ||||
| -rw-r--r-- | CST116-Lab2-Davis.cpp | 163 |
2 files changed, 397 insertions, 0 deletions
diff --git a/CST116-Lab2-Davis-PSEUDOCODE.rtf b/CST116-Lab2-Davis-PSEUDOCODE.rtf new file mode 100644 index 0000000..e7c1fb4 --- /dev/null +++ b/CST116-Lab2-Davis-PSEUDOCODE.rtf @@ -0,0 +1,234 @@ +{\rtf1\ansi\ansicpg1252\cocoartf2639 +\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Menlo-Regular;\f2\fnil\fcharset0 Menlo-Bold; +} +{\colortbl;\red255\green255\blue255;\red252\green106\blue93;\red31\green31\blue36;\red230\green255\blue218; +\red255\green255\blue255;\red252\green95\blue163;\red208\green191\blue105;\red108\green121\blue134;\red103\green183\blue164; +} +{\*\expandedcolortbl;;\csgenericrgb\c98912\c41558\c36568;\csgenericrgb\c12054\c12284\c14131;\cspthree\c93335\c100000\c89365; +\csgenericrgb\c100000\c100000\c100000\c85000;\csgenericrgb\c98839\c37355\c63833;\csgenericrgb\c81498\c74939\c41233;\csgenericrgb\c42394\c47462\c52518;\csgenericrgb\c40538\c71705\c64209; +} +\margl1440\margr1440\vieww9000\viewh8400\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 + +\f0\fs24 \cf0 Lab 2 Pseudo-code\ +\ +declares use of cout cin and endl\ +\ +after main run getdata then printdata\ +\ +const int Cmax = 49.5 Cmin = -62 Fmax = 121 Fmin = -80\ +\ +int main\ +\{\ +variables temp, choice, windspeed, and windchill = 0\ +\ +run getdata then print data\ +\ +return nothing to main;\ +\}\ +int getdata\ +\{\ + +\f1 \cf2 \cb3 \cf4 print\cf2 "Hello!"\cf5 \ +\pard\tx593\pardeftab593\pardirnatural\partightenfactor0 +\cf5 \cb3 print \cf2 "Will you be using Celsius or Fahrenheit? Please enter a '1' for Celsius and '2' for Fahrenheit"\cf5 \ + user input = choice;\ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (choice == \cf7 \cb3 1\cf5 \cb3 ) \cf8 \cb3 //finding if the user wants C or F\cf5 \cb3 \ + \{\ + print \cf2 "What is the temperature? Please enter a value between "\cf5 <<\cf9 \cb3 CMIN\cf5 \cb3 <<\cf2 " and "\cf5 <<\cf9 \cb3 CMAX\cf5 \cb3 <<\ + user input = temperature; \cf8 \cb3 //getting temp off of C\cf5 \cb3 \ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature < \cf9 \cb3 CMIN\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a larger number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature >\cf9 \cb3 CMAX\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a smaller number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + temperature = ((\cf7 \cb3 9\cf5 \cb3 /\cf7 \cb3 5\cf5 \cb3 ) * temperature + \cf7 \cb3 32\cf5 \cb3 );\ + \}\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (choice == \cf7 \cb3 2\cf5 \cb3 )\ + \{\ + print \cf2 "What is the temperature? Please enter a value between "\cf5 <<\cf9 \cb3 FMIN\cf5 \cb3 <<\cf2 " and "\cf5 <<\cf9 \cb3 FMAX\cf5 \cb3 <<\ + user input = temperature; \cf8 \cb3 //getting temp off of F\cf5 \cb3 \ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature < \cf9 \cb3 FMIN\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a larger number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature > \cf9 \cb3 FMAX\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a smaller number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + print \cf2 "Perfect!"\cf5 \ + \}\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (choice > \cf7 \cb3 2\cf5 \cb3 or choice < \cf7 \cb3 1\cf5 \cb3 )\ + \{\ + +\f2\b \cf6 \cb3 do +\f1\b0 \cf5 \cb3 \ + \{\ + print \cf2 "Please enter 1 or 2"\cf5 \ + user input = choice;\ + \}\ + +\f2\b \cf6 \cb3 while +\f1\b0 \cf5 \cb3 (choice > \cf7 \cb3 2\cf5 \cb3 || choice < \cf7 \cb3 1\cf5 \cb3 );\ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (choice == \cf7 \cb3 1\cf5 \cb3 ) \cf8 \cb3 //finding if the user wants C or F\cf5 \cb3 \ + \{\ + print \cf2 "What is the temperature? Please enter a value between "\cf5 <<\cf9 \cb3 CMIN\cf5 \cb3 <<\cf2 " and "\cf5 <<\cf9 \cb3 CMAX\cf5 \cb3 <<\ + user input = temperature; \cf8 \cb3 //getting temp off of C\cf5 \cb3 \ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature < \cf9 \cb3 CMIN\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a larger number"\cf5 \ + user input = temperature\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature > \cf9 \cb3 CMAX\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a smaller number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + temperature = ((\cf7 \cb3 9\cf5 \cb3 /\cf7 \cb3 5\cf5 \cb3 ) * temperature + \cf7 \cb3 32\cf5 \cb3 );\ + \}\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (choice == \cf7 \cb3 2\cf5 \cb3 )\ + \{\ + print \cf2 "What is the temperature? Please enter a value between "\cf5 <<\cf9 \cb3 FMIN\cf5 \cb3 <<\cf2 " and "\cf5 <<\cf9 \cb3 FMAX\cf5 \cb3 <<\ + user input = temperature; \cf8 \cb3 //getting temp off of F\cf5 \cb3 \ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature < \cf9 \cb3 FMIN\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a larger number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (temperature > \cf9 \cb3 FMAX\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a smaller number"\cf5 \ + user input = temperature;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + print \cf2 "Perfect!"\cf5 \ + \}\ + \}\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + print \cf2 "uhhhh something went wrong"\cf5 \ + \}\ + print \cf2 "Now what is the windspeed in MPH? Please enter a value less than 231 and greater than 0"\cf8 \cb3 //finding windspeed\cf5 \cb3 \ + user input = windspeed;\ + +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (windspeed > \cf7 \cb3 231\cf5 \cb3 )\ + \{\ + print \cf2 "Please enter a smaller value"\cf5 \ + user input = windspeed;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 +\f2\b \cf6 \cb3 if +\f1\b0 \cf5 \cb3 (windspeed < \cf7 \cb3 0\cf5 \cb3 )\ + \{\ + print \cf2 "please enter a larger number"\cf5 \ + user input = windspeed;\ + \}\ + +\f2\b \cf6 \cb3 else +\f1\b0 \cf5 \cb3 \ + \{\ + windchill = (\cf7 \cb3 35.74\cf5 \cb3 + \cf7 \cb3 0.6215\cf5 \cb3 * (temperature) - \cf7 \cb3 35.75\cf5 \cb3 * ((windspeed)^\cf7 \cb3 16\cf5 \cb3 ) + \cf7 \cb3 0.4275\cf5 \cb3 * (temperature) * ((windspeed)^\cf7 \cb3 16\cf5 \cb3 )); \cf8 \cb3 //getting windchill\cf5 \cb3 \ + \} +\f0 \cf0 \cb1 \ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 +\cf0 \ +return choice, temperature, windspeed, and windchill to main\ +\}\ +void printdata\ +\{\ +if choice == 1\ + \{\ + print +\f1 \cf2 \cb3 "You chose to input your temperature in Celsius. The program has convertered the temp into Fahrenheit and the temperature is "\cf5 <<temperature<< +\f0 \cf0 \cb1 \ +\}\ +else if choice == 2\ +\{\ +print +\f1 \cf2 \cb3 "You chose to input your temperature in Fahrenheit. You input "\cf5 <<temperature<< +\f0 \cf0 \cb1 \ +\}\ +else \ +\{\ +print +\f1 \cf2 \cb3 "Something went wrong..."\ + +\f0 \cf0 \cb1 \} \ +print +\f1 \cf2 \cb3 "You put "\cf5 <<windspeed<<\cf2 " for your windspeed"\cf5 \ +\pard\tx593\pardeftab593\pardirnatural\partightenfactor0 +\cf5 \cb3 print \cf2 "Based off your temperature and windspeed, the windchill is "\cf5 <<windchill<< +\f0 \cf0 \cb1 \ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 +\cf0 \}}
\ No newline at end of file diff --git a/CST116-Lab2-Davis.cpp b/CST116-Lab2-Davis.cpp new file mode 100644 index 0000000..6ce6be0 --- /dev/null +++ b/CST116-Lab2-Davis.cpp @@ -0,0 +1,163 @@ +// Lab 2; Baby it's cold outside + +#include <iostream> + +using std::cout; +using std::cin; +using std::endl; + +const int FMIN = -80; +const int FMAX = 121; +const int CMIN = -62; +const float CMAX = 49.5; + +int getdata (int (choice), float (temperature), float (windchill), int (windspeed)); +void printdata(float (temperature), float (windchill), int (windspeed), int (chocie)); + +int main() +{ + float temperature = 0.0; + int choice = 0; + int windspeed = 0; + float windchill = 0.0; + + getdata(int (choice), float (temperature), float (windchill), int (windspeed)); + printdata(float (temperature), float (windchill), int (windspeed), int (choice)); + return 0; +} +int getdata(int (choice), float (temperature), float (windchill), int (windspeed)) +{ + cout <<"Hello!"<< endl; + cout <<"Will you be using Celsius or Fahrenheit? Please enter a '1' for Celsius and '2' for Fahrenheit"<<endl; + cin >> choice; + if (choice == 1) //finding if the user wants C or F + { + cout << "What is the temperature? Please enter a value between "<<CMIN<<" and "<<CMAX<<endl; + cin >> temperature; //getting temp off of C + if (temperature < CMIN) + { + cout <<"Please enter a larger number"<<endl; + cin >> temperature; + } + else if (temperature >CMAX) + { + cout << "Please enter a smaller number"<<endl; + cin >> temperature; + } + else + { + temperature = ((9/5) * temperature + 32); + } + } + else if (choice == 2) + { + cout << "What is the temperature? Please enter a value between "<<FMIN<<" and "<<FMAX<<endl; + cin >> temperature; //getting temp off of F + if (temperature < FMIN) + { + cout <<"Please enter a larger number"<<endl; + cin >> temperature; + } + else if (temperature > FMAX) + { + cout << "Please enter a smaller number"<<endl; + cin >> temperature; + } + else + { + cout << "Perfect!"<<endl; + } + } + else if (choice > 2 || choice < 1) + { + do + { + cout << "Please enter 1 or 2"<<endl; + cin >> choice; + } + while (choice > 2 || choice < 1); + if (choice == 1) //finding if the user wants C or F + { + cout << "What is the temperature? Please enter a value between "<<CMIN<<" and "<<CMAX<<endl; + cin >> temperature; //getting temp off of C + if (temperature < CMIN) + { + cout <<"Please enter a larger number"<<endl; + cin >> temperature; + } + else if (temperature > CMAX) + { + cout << "Please enter a smaller number"<<endl; + cin >> temperature; + } + else + { + temperature = ((9/5) * temperature + 32); + } + } + else if (choice == 2) + { + cout << "What is the temperature? Please enter a value between "<<FMIN<<" and "<<FMAX<<endl; + cin >> temperature; //getting temp off of F + if (temperature < FMIN) + { + cout <<"Please enter a larger number"<<endl; + cin >> temperature; + } + else if (temperature > FMAX) + { + cout << "Please enter a smaller number"<<endl; + cin >> temperature; + } + else + { + cout << "Perfect!"<<endl; + } + } + } + else + { + cout << "uhhhh something went wrong"<<endl; + } + cout << "Now what is the windspeed in MPH? Please enter a value less than 231 and greater than 0"<<endl; //finding windspeed + cin >> windspeed; + if (windspeed > 231) + { + cout << "Please enter a smaller value"<<endl; + cin >> windspeed; + } + else if (windspeed < 0) + { + cout <<"please enter a larger number"<<endl; + cin >> windspeed; + } + else + { + windchill = (35.74 + 0.6215 * (temperature) - 35.75 * ((windspeed)^16) + 0.4275 * (temperature) * ((windspeed)^16)); //getting windchill + } + return choice; + return temperature; + return windchill; + return windspeed; +} +void printdata(float (temperature), float (windchill), int (windspeed), int (choice)) +{ + if (choice == 1) + { + cout << "You chose to input your temperature in Celsius. The program has convertered the temp into Fahrenheit and the temperature is "<<temperature<<endl; +//print celcius choice in fahrenheit + } + else if (choice == 2) + { + cout << "You chose to input your temperature in Fahrenheit. You input "<<temperature<<endl; + // prints fahrenheit input + } + else + { + cout << "Something went wrong..."<<endl; + } + cout << endl; + cout << "You put "<<windspeed<<" for your windspeed"<<endl; //prints windspeed + cout << endl; + cout << "Based off your temperature and windspeed, the windchill is "<<windchill<<endl; +} |