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;
};


Quiz 3

--Originally published at The Talking Chalk

#include
#include

using namespace std;
double square_root (double x)
{
double y;
y= sqrt(x);
return y;
}
double cubic_root (double x)
{
double y;
y = cbrt(x);
return y;
}
int main()
{
double x=0;
cout<<“Give me a number which I can take its square root and cubic root please.”<<endl; cin>> x;

if(x>=0)
{
cout<<“Its square root is “<<square_root(x)<<“.”<<endl;
cout<<“Its cubic root is “<<cubic_root(x)<<“.”<<endl;
}
else if (x<0)
{
cout<<“You, gave a negative number, your square root result is an imaginary number and your cubic root result is a negative number!”<<endl;
cout<<“For you to know, the square root of a negative number is the square root of its absolute value multiplied per i, i is the square root of -1.”<<endl;
cout<<“Thus, if you multiply i per i, your result is -1.”<<endl;
}
else
{
cout<<“That’s no number”<<endl;
}
return 0;
}

capturaquiz


Quiz 3

--Originally published at RAMGGV

En este quiz el profesor nos pidió que hiciéramos un programa que pudiera calcular tanto la raíz cuadrada, como la cubica del mismo numero.

quiz3

Para esto utilice variables tipo double y así tener una mayor precisión sobre el resultado. El programa lo hice lo mas sencillo posible para poder entenderlo más fácilmente.


Quiz 3

--Originally published at My awesome Blog!

Quiz 3 :
First i added the library “cmath” so i can use the functions for square and cubic root , then i declared some variables for to use as shown.

Inside the main function i ask the user for the value of x, then i send the value of x to the function Square_root , that returns the value for the result for the square root . when it finishes it goes back to the main and then sends the value of x to the function Cubic_root and returns a value for the result.

i have an if-else to decide if the x value is negative to decide if its a imaginary root.

Enjoy!
CODE HERE:
#include <iostream>
#include <cmath>
using namespace std;
double x1,x2,x, squareroot , cubicroot ;
double Square_root (double x) {
squareroot = sqrt( x );
return squareroot ;
}
double Cubic_root (double x) {
cubicroot = cbrt (x);
return cubicroot;
}
int main()
{
cout << “Escribe el valor de x” << endl;
cin >> x;
   x1 =  Square_root(x);
x2 = Cubic_root(x);
    if (x >0  ) {
    cout << “la raiz cuadrada de  ” << x << “es  ” << x1 << endl;
cout << “la raiz cubica de  ” << x << “es  ” << x2 << endl;
    }
else {
cout << “La raiz es imaginaria ” << endl;
}
return 0;
}

Quiz3

--Originally published at Programing 101

The difficult part of this quiz was know the difference between a variable and input:

first I was really confuse because when i declare my variable of square-root I didn’t know what was the wrong part, then I realized that i dint declared it in the right place, I had put it inside the int main so the terminal didn’t know what variable I was talking about.

screen-shot-2017-01-26-at-14-56-33

terminal

The easy part:

finally when I got the point of every command I copy paste. after that I was experimenting.

this side really help me with all the commands that i didn’t know

>>>>c++ page command<<<<

screen-shot-2017-01-26-at-14-38-02


Quiz #3

--Originally published at My life @ TEC

My first real quiz!! it was hard at the beggining and I was driving nuts! but I DID IT!!! ?

#include <iostream>
#include <math.H>
using namespace std;

double square_root(double x){
double param;
param=sqrt(x);
return param;
}
double cube_root(double x) {
double param;
param=cbrt(x);
return param;
}
int main () {
double x;
cout<<“hey, give a number!”<<endl;
cin>>x;
cout<<“the square root of “<<x<<” is: “<<square_root(x)<<endl;
cout<<“the cube root of “<<x<<” is: “<<cube_root(x);

return 0;
}