QUIZ 3

--Originally published at blog de Horacio

What to Do

You implement this function in your own program in a file quiz3.cpp.

You should make a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out.

What should you do if the user enters a negative number?

Publish your code on your own blog today (during class time is best) and use the tag #Quiz03 so it shows up nicely in our tag cloud.

captura-de-pantalla-2017-02-01-a-las-19-17-03

code:

#include <iostream>
#include <math.h>
using namespace std;
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 << “introduce un numero” << ‘\n’;
std::cin >> x;
if (x<0) {
std::cout << “error” << ‘\n’;
}else {
std::cout <<square_root(x)<< ‘\n’;
std::cout <<cube_root(x) << ‘\n’;
}
return 0.0;
};


WSQ02 Temperature

--Originally published at blog de Horacio

WHAT TO DO:

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given. Your output might look like the following.

EXPLANATION:

First we name the variables of f and c for the two types of grades respectively, then we gave the task of assigning the formula of the conversion to the variable c in order to convert the degrees Farhenheit to Celcius, we use a condition statement for when the result of The conversion gave a result greater than 100, write a message to inform us that it is boilingcaptura-de-pantalla-2017-02-01-a-las-18-51-39

CODE:

#include <iostream>
using namespace std;
int main() {
int F,C;
std::cout << “dame la temperatura en grados Farhenheit” << ‘\n’;
std::cin >> F;
C = 5*(F-32)/9;
std::cout << “la temperatura de ” <<F<< “grados Farhenheit en grados celcius es:” <<C<< ‘\n’;
if (C>100) {
std::cout << “el agua esta hirviendo compadre!!!” << ‘\n’;
}else {
std::cout << “el agua no hierve” << ‘\n’;
}
return 0;
};