WSQ_05_On_To_Functions

This program is similar to WSQ 01 but, instead of writing the direct operations, it calculates the sum, difference, product, quotient and residue through functions.

This link was really helpful to write this program.  http://www.cplusplus.com/forum/beginner/44001/

I’d like to share my favorite quote from Bertrand Russell.

Mathematics, rightly viewed, possesses not only truth, but supreme beauty—a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of painting or music, yet sublimely pure, and capable of a stern perfection such as only the greatest art can show.”
― Bertrand Russell, A History of Western Philosophy.

 

On to Functions code

Final Project – Arc Reactor

Hi, I´m Franco and this is my final project for TC1017. 

Cardiovascular diseases are the number one cause of death worldwide. File_000These problems affect a lot of kids as well. Cardiovascular diseases in kids mean that they cannot do activities that require a high level of exercise for a prolonged period of time, like running or playing outside. It would be easier for parents to take care of their kid´s health if they could oversee their kid´s heart rate easily.

My solution to this problem was to create a wearable light feedback monitor that constantly measures the patient’s pulse and emits a light at the same rhythm.

As it is intended for kids (cool kids), I made it in the form of Ironman´s arc reactor and big enough for parents to see it at a distance.

It is a completely original design. I designed the hardware, the electrical circuit, and the code.

If you would like to know more about this project, please come visit me at ExpoIngeniería.

File_001 (27)File_000 (37)ECG

MeArm

Check this out! I know a lot of us are beginners in programing and robotics so I found this simple project useful to start learning, specially mechatronics students.

This project consists of a simple and small robot arm. I attached links to the gitHub page so you can download the code and schematics. You should try building it!

https://github.com/mimeindustries/MeArm

http://microbotlabs.com/armuno-arduino-schematic.html

https://shop.mime.co.uk/

mearm

WSQ 04 Sum of Numbers

I’m so sorry to upload this program like this. I know it looks like it was written by before fire was discovered. Well, this program asks the user for a

Well, this program asks the user for a lower bound and an upper bound. Then it sums every number between them including both bounds. If the user sets a lower bound greater than the upper bound the program returns an ERROR message.

I had to split the las cout in six lines instead of one because it just wouldn’t let me write it in a single line. If I wrote it in a single line my result would change to an evil six digit number.

sum-of-numbers-codesum-of-numbers-terminal

WSQ 01 Fun with Numbers

This was the first assignment, I did it long ago but I deleted it by accident. I re-upload it to have every assignment on my blog. Now my blog has no chronological order and my OCD is worse than ever.

Anyway, the program asks the user for two numbers and then it adds, substract, multiply, divide and gives the reminder of their division.

 

#include <iostream>

int main() {

int num1;
int num2;

std::cout << “Enter first number:” << ‘\n’;
std::cin >> num1;
std::cout << “Enter second number:” << ‘\n’;
std ::cin >> num2;
std::cout << “Sum, difference, product, quotient, reminder, respectively.” << ‘\n’;

std::cout << num1 + num2 << ‘\n’;
std::cout << num1 – num2 << ‘\n’;
std::cout << num1 * num2 << ‘\n’;
std::cout << num1 / num2 << ‘\n’;
std::cout << num1 % num2 << ‘\n’;

return 0;
}

 

fun-with-numbers-codefun-with-numbers-terminal

Quiz Week 3 – Square/Cube Root

This program calculates the square root and cube root of a number given by the user. I included #include <math.h> so I could use sqrt() and cbrt(). Although it is recommended to use #include <cmath> instead. The code recognizes if the user inserts a negative number, therefore it tells the user that the square root is not calculable.

#include <iostream>
#include <math.h>

double square_root(double x){
double square_root = sqrt(x);
return square_root;
}

double cube_root(double x){
double cube_root = cbrt(x);
return cube_root;
}

int main() {

double x;

std::cout << “SQUARE ROOT AND CUBE ROOT CALCULATOR” << ‘\n’;
std::cout << “Insert a number” << ‘\n’;
std::cin >> x;

if (x < 0) {
std::cout << “Square root: ERROR: number cannot be negative.” << ‘\n’;
std::cout << “Cube root: “<< cube_root(x) << ‘\n’;
} else {
std::cout << “Square root: “<< square_root(x) << ‘\n’;
std::cout << “Cube root: ” << cube_root(x) << ‘\n’;
}

return 0;
}

 

quiz-3-codequiz-3-terminal

WSQ 03 Pick a Number

 

morfeo

Man up! Chose the red one!

 

This program selects a random number every time the user runs it. I had difficulties at first because the program selected the same number everytime. This link helped me solve this http://www.cplusplus.com/reference/cstdlib/rand/ .

The program tells the user if his/her guess is too high or too low until he/she gets the right answer.

 

#include <iostream>
#include <stdlib.h> /*rand, srand*/
#include <stdio.h> /*NULL*/
#include <time.h> /*time*/

int main() {

int usernum;  /* This is the user input*/
int morfeosnum;  /* This variable will contain the random number*/

std::cout << “Hello Neo, I have a number between 1 and 100 in my head. Can you guess which is it?” << ‘\n’;

srand(time(NULL));  /* This makes a new random number everytime I run the code*/

morfeosnum = rand() % 100 + 1;  /* This sets my range of random numbers*/

do {
std::cin >> usernum;
if (usernum > morfeosnum) {
std::cout << “Your number is too high. Try again…” << ‘\n’;
} else if (usernum < morfeosnum) {
std::cout << “Your number is too low. Try again…” << ‘\n’;
} else {
std::cout << “You answered right, that is my number. Now… choose a pill…” << ‘\n’;
}
} while(morfeosnum != usernum);

return 0;
}

pick-a-number-code-blogpick-a-number-terminal-blog

WSQ 02 Temperature

Fahrenheit to Celsius Converter. The user gives the Fahrenheit value, the program converts it to Celsius and if it is above 100 degrees Celsius, the program tells the user that water will boil at that temperature, otherwise it will tell the user that water will not boil at room temperature.

This program was easy as there is a formula to convert Fahrenheit to Celsius. I didn’t need any libraries so I only included #include

#include

int main() {

float tempF;
float tempC;

std::cout << “Fahrenheit to Celsius Converter” << ‘\n’;

std::cout << “Enter temperature in Fahrenheit: ” << ‘\n’; std::cin >> tempF;

tempC = 5 * (tempF – 32) / 9;

std::cout << “A temperature of ” << tempF << ” degrees Fahrenheit is ” << tempC << ” degrees Celsius.” << ‘\n’; if (tempC > 100) {
std::cout << “Water would boil at this temperature.” << ‘\n’;
} else {
std::cout << “Water would not boil at this temperature. (25C and 1atm)” << ‘\n’;
}

return 0;
}

temperature-code-blogtemperature-terminal-blog