Quiz 04

--Originally published at Programming course

So during class I started my code and I thought I was done but the time was over, so as soon as I got home I started compiling my program, but the trouble started. I had many error and the program couldn’t run, so i went line by line trying to figure out what was wrong. At the end I only had one error about a “{” symbol, but if I moved it or delete it, I would have 19 errors, at the end I noticed I had a “;” before that “{” and I could finish.

captura-de-pantalla-2017-02-02-a-las-19-37-38 captura-de-pantalla-2017-02-02-a-las-19-37-53 captura-de-pantalla-2017-02-02-a-las-19-38-00

Me llaman me llaman me llaman ♪♫ (Jammin Bob Marley)

--Originally published at Adal´s Blog

En la clase de hoy tuvimos un quiz el cual dice:


En pocas palabras, lo que tenemos que hacer es una función que nos diga cual es el numero menor de una lista de tres números, y con estos mismos saber la suma de sus cuadrados.

En términos simples, una función es un pedazo de código que nos retorna un o mas valores específicos esto con el fin de ayudarnos a no escribir lineas de código una y otra vez 

Quiz #4

--Originally published at my programming blog

Today I did the quiz #4in which I needed to do a program that asked the user for 3 integers and then returned the smallest integer and the sum of squares of the three of them.

First I did the function to find the smallest value, what I did was import a library called “algorithm”, where I could use the function “min” that returns the smaller value between two values, but because I had three values I used the “min” function two times as you can see in the code (to get the min between two numbers and then get the min between the other number and the result of the first min.). I learned this method because I googled it, thanks to this page:

http://stackoverflow.com/questions/9424173/c-find-the-smallest-amongst-3-numbers

The I imported another library called “cmath” that allows me to use the function “pow”, so in the second function to calculate the sum of squares I wrote pow 2 for each value (x, y and z) and then I added the results of the pow.

Here’s my code:

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int minimumThree(int x, int y, int z){
return min(x, min(y, z));
}
int sumSquares( int x, int y, int z){
return pow(x,2)+ pow(y,2)+ pow(z,2);
}

int main ()
{
int x, y, z;
cout<< “I’m going to calculate the sum of squares of three numbers.”<<endl;
cout<< “And I’ll tell you which one of those three numbers is the smallest.”<<endl;
cout<<“Please give me the first number:”<<endl;
cin>> x;
cout<< “Please give me the second number:”<<endl;
cin>> y;
cout<<“Please give me the third number:”<<endl;
cin>> z;
cout<< “The minimum is: “<< minimumThree(x, y, z)<<endl;
cout<< “The sum of squares is: “<<sumSquares(x, y, z)<<endl;

return 0;
}

screen-shot-2017-02-02-at-3-23-27-pmscreen-shot-2017-02-02-at-3-24-22-pm


#Quiz04

--Originally published at Solving Problems with Programming

PICTURE OF AUTOR

THIS IS THE #QUIZ4 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 .

This #QUIZ04 makes a main routine that asks the user for three numbers and then calls the functions to return the value that is smallest of x, y and z and returns the value of the sum of squares of x, y, z  which should *RETURN* the value and prints it in the main program.(#Mastery11).

Pictures of the quiz:

quiz4v1

quiz4v2

quiz4v3

FIRST TO DO THIS #QUIZ04 I HAVE TO DECLARATE A GLOBAL VARIABLE AND THE NEXT THING YOU DO THE SAME AS OTHER PREVIEW CODES DECLARATE YOUR TYPE OF VARIABLE AND YOUR VARIABLE AND ASK THE USER TO GIVE YOU THE 3 NUMBERS

AFTER THAT YOU HAVE TO CALL YOUR CREATED FUNCTIONS THAT WERE:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

YOU HAVE TO KNOW THAT USING THESE 2 FUNCTIONS IS OTHER EXTERNAL FUNCTIONS FROM THE MAIN THAT HAS A INT FUNCTION VALUE OF 16 BITS AND DECLARING INT VARIABLES X,Y,Z INSTEAD OF USING THE VOID MAIN THAT HAS 0 BITS OR DOUBLE OF 32 BITS.

TO CALL THE FUNCTION IN THE MAIN YOU USE x= minimumThree (x,y,z);//CALL THE FUNCTION OF THE MINIUM VALUE OF THE NUMBERS AND y = sumSquares(x,y,z); //CALL THE FUNCTION OF THE SUM OF THE NUMBERS AND AT THE BEGINNING OF THE PAGE, YOU HAVE TO DECLARATE AGAIN THE INT VARIABLES OF X,Y,Z BECAUSE THE INT MAIN DOES NOT KNOW AT FIRST WHAT X,Y,Z STAND FOR AND WITH THOSE COMMANDS IT TELLS THE INT MAIN THAT IS IT CALLED.

Like i said before, you must

Continue reading "#Quiz04"

#Quiz04

--Originally published at Solving Problems with Programming

PICTURE OF AUTOR

THIS IS THE #QUIZ4 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 .

This #QUIZ04 makes a main routine that asks the user for three numbers and then calls the functions to return the value that is smallest of x, y and z and returns the value of the sum of squares of x, y, z  which should *RETURN* the value and prints it in the main program.(#Mastery11).

Pictures of the quiz:

quiz4v1

quiz4v2

quiz4v3

FIRST TO DO THIS #QUIZ04 I HAVE TO DECLARATE A GLOBAL VARIABLE AND THE NEXT THING YOU DO THE SAME AS OTHER PREVIEW CODES DECLARATE YOUR TYPE OF VARIABLE AND YOUR VARIABLE AND ASK THE USER TO GIVE YOU THE 3 NUMBERS

AFTER THAT YOU HAVE TO CALL YOUR CREATED FUNCTIONS THAT WERE:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

YOU HAVE TO KNOW THAT USING THESE 2 FUNCTIONS IS OTHER EXTERNAL FUNCTIONS FROM THE MAIN THAT HAS A INT FUNCTION VALUE OF 16 BITS AND DECLARING INT VARIABLES X,Y,Z INSTEAD OF USING THE VOID MAIN THAT HAS 0 BITS OR DOUBLE OF 32 BITS.

TO CALL THE FUNCTION IN THE MAIN YOU USE x= minimumThree (x,y,z);//CALL THE FUNCTION OF THE MINIUM VALUE OF THE NUMBERS AND y = sumSquares(x,y,z); //CALL THE FUNCTION OF THE SUM OF THE NUMBERS AND AT THE BEGINNING OF THE PAGE, YOU HAVE TO DECLARATE AGAIN THE INT VARIABLES OF X,Y,Z BECAUSE THE INT MAIN DOES NOT KNOW AT FIRST WHAT X,Y,Z STAND FOR AND WITH THOSE COMMANDS IT TELLS THE INT MAIN THAT IS IT CALLED.

Like i said before, you must

Continue reading "#Quiz04"

Quiz 04 “Minimum and Squares”

--Originally published at blog de Horacio

What to do:

You implement these function in your own program in a file quiz4.cpp.

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

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

captura-de-pantalla-2017-02-02-a-las-13-30-43

#include <iostream>
#include <cmath>
using namespace std;
int sumSquares(int x, int y, int z) {
return pow (x,2)+pow(y,2)+pow(z,2);
}
int minimumThree(int x, int y, int z){
int num;
if (x<=y && y<=z) {
num=x;
}
if (y<=x && x<=z) {
num=y;
}
if (z<=y && y<=x) {
num=z;
}
return num;
}
int main()
{
int x,y,z;
std::cout << “give me the x variable” << ‘\n’;
std::cin >> x;
std::cout << “give me the y variable” << ‘\n’;
std::cin >> y;
std::cout << “give me the z variable” << ‘\n’;
std::cin >> z;
std::cout << “the sum of squares are: ” <<sumSquares(x,y,z)<< ‘\n’;
std::cout << “the minimun of the three numbers is: ” <<minimumThree(x,y,z)<< ‘\n’;
return 0;
}

 


(Quiz 4) Minimum and double of bla bla bla

--Originally published at Programming Path

The quiz today, #quiz4, was to run a program where the user inputs three numbers (x, y and z) and give you the minimum number and the sum of its squares. We didn’t use any library like the last quiz, but we used functions. These was to return the minimum and the result of the sum.

Here is the code:

Click to view slideshow.

And here as well:

#include <iostream>
using namespace std;

int minimunThree (int, int, int);
int sumSquares (int, int, int);
int main () {
int x, y, z, m, ss;
cout << “Please give me x: “;
cin >> x;
cout << “Please give me y: “;
cin >> y;
cout << “Please give me z: “;
cin >> z;
m = minimunThree (x, y, z);
ss = sumSquares (x, y, z);
cout << endl << “The minimum number is: ” << m << endl;
cout << “The sum of squares is: ” << ss;
return 0;
}
int minimunThree (int x, int y, int z) {
int rm;
if (x < y && x < z) {
rm = x;
}
else if (y < x && y < z) {
rm = y;
}
else if (z < x && z < y) {
rm = z;
}
return rm;
}
int sumSquares (int x, int y, int z) {
int sx, sy, sz, rs;
sx = x * x;
sy = y * y;
sz = z * z;
rs = sx + sy + sz;
return rs;
}

The result is like this:

Please give me x: 9
Please give me y: 4
Please give me z: 12

The minimum number is: 4
The sum of squares is: 241

This covers #Mastery12. If you have any doubts, don’t hesitate in asking.


Quiz 4

--Originally published at The Clueless Programmer

Tricky quiz today, seemed easy at first but it turned out pretty hard. Well played. Here is the code:

#include <iostream>
using namespace std;
int minimumThree(int x, int y, int z)
{
int j;
if(x<y)
{
if(x<z)
{
j=x;
}
else
{
j=z;
}
}
else if(y<z)
{
j=y;
}
else
{
j=z;
}
if((x==y)&&(y==z))
{
j=0;
}
return j;
}
int sumSquares(int x, int y, int z)
{
int sum;
sum=(x*x)+(y*y)+(z*z);
return sum;
}
int main()
{
int n1, n2, n3, a, b;
cout<<“This program will tell you the minimun of the three numbers you write and the sum of squares of those three numbers”<<endl;
cout<<“Give me your first number: “;
cin>>n1;
cout<<“The second one: “;
cin>>n2;
cout<<“The third one: “;
cin>>n3;
a= minimumThree(n1, n2, n3);
b= sumSquares(n1, n2, n3);
if (a==0)
{
cout<<“Your numbers are the same, there is no minimum”<<endl;
cout<<“The sum of squares is: “<<b<<endl;
}
else
{
cout<<“The minimum number is: “<<a<<endl;
cout<<“The sum of squares is: “<<b<<endl;
}
}

imagen1

And there is the code ran with all the possible solutions the may give.

So the first thing you want to do is create your functions. Here is the first tricky part, because your functions can´t print, and I hadn´t done that yet, but it is not that hard. As you can see in the first function I do a bunch of ifs to find the smallest of the three numbers, while everytime that I found a small number, I save ir in a variabla “j” that I named independently at the start, and that I return at the end. I save “j” as 0 when the three numbers are the same.

The sum of squares is pretty simple as well, I do the same trick of saving the independent variable and then returning it.

Continue reading "Quiz 4"

Quiz 4

--Originally published at Tec Life

For this quiz we have to do this:

For this quiz I want you to (in class) create a program with two functions:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

So I started writing my program normally, declaring my variables, naming my functions and to make the user to write the three numbers.

captura-de-pantalla-2017-02-02-a-las-09-28-40

Then I make what my functions would do, that says in the first function that I am going to multiplied my variables with the function “pow” and in a parenthesis my variable “,” and the number I want to multiplied my variable, in this case 2 for square and the sum the operations.

And on my second function I put conditions with if and else to make the program know what number is bigger than the other and finally printed on the result.

captura-de-pantalla-2017-02-02-a-las-09-28-52Image from: http://www.quizfactor.com/quiz/general-knowledge/5

#Quiz04