adding cs142 code

This commit is contained in:
dm
2016-04-06 20:45:34 -07:00
parent 552d456d53
commit 8e52ce1982
174 changed files with 14064 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
CPPFLAGS=-Wall -g -std=c++0x
all: timer temperature binary
binary: binary.cpp
temperature: temperature.cpp
timer: timer.cpp
clean:
rm -rv timer temperature binary
+57
View File
@@ -0,0 +1,57 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
int value;
int first, second, third, fourth, fifth;
vector<int> final;
cout << "please insert your number between 0 and 31" << endl;
cin >> value;
int prin = value%2;
value = value/2;
if(prin >=1)
first = 1;
else
first = 0;
final.push_back(first);
prin = value%2;
value = value/2;
if(prin >=1)
second = 1;
else
second = 0;
final.push_back(second);
prin = value%2;
value = value/2;
if(prin >= 1)
third = 1;
else
third = 0;
final.push_back(third);
prin = value%2;
value = value/2;
if(prin >= 1)
fourth = 1;
else
fourth = 0;
final.push_back(fourth);
prin = value%2;
value = value/2;
if(prin >= 1)
fifth = 1;
else
fifth = 0;
final.push_back(fifth);
cout <<fifth<<fourth<<third<<second<<first << endl;
// for(unsigned int i = 0 ; i<final.size();i++) {
// cout << final[i];
// }
cout << "\n";
}
+20
View File
@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main() {
double temperature;
cout << "please enter a temperature in degress Fahrenheit:" << endl;
cin >> temperature;
double celsius = (temperature-32) * 5/9;
cout << "This is Fahrenheit as an int:" << endl;
cout << (int) temperature << endl;
cout << "This is Celsius as a double:" << endl;
cout << celsius << endl;
cout << "This is Celsius as an int:" << endl;
cout << (int) celsius << endl;
}
+30
View File
@@ -0,0 +1,30 @@
#include <iostream>
#include <cmath>
using namespace std;
void calculate (int a) {
int hours, minutes, seconds;
hours = (a / 3600);
minutes = (a / 60) - (hours * 60);
seconds = a % 60;
cout << "hours: " << hours << " minutes: " << minutes << " seconds: " << seconds << endl;
};
int main() {
int time;
cout << "please enter a number of seconds" << endl;
cin >> time;
cout << time << endl;
cout << "absolute value of input " << abs (time) << endl;
calculate(time);
cout << "now with sqrt: " << endl;
calculate(sqrt(time));
}