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 remember that in that type of INT functionwith 3 variables you have to declarate your variable in the main and in the other or others functions and in the main you have to call the name of these functions like these examples:

x= minimumThree (x,y,z); //CALL THE FUNCTION OF THE MINIUM VALUE OF THE NUMBERS

y = sumSquares(x,y,z); //CALL THE FUNCTION OF THE SUM OF THE NUMBERS

YOU CALL THE FUNCTION WITH THE NAME OF THESE FUNCTIONS THAT ARE x= minimumThree (x,y,z); AND y = sumSquares(x,y,z);  AND YOU PUT THE NAME OF THE X ,Y ,Z VARIABLES AND ASSIGNS TO THE VARIABLE X AND Y.

IN THE PART OF THE FUNCTION THAT MAKES THE MINIMUM OF NUMBERS YOU HAVE TO USE INSIDE OF YOUR IF CONDITION YOUR AND OPERATOR && with just 3 simple conditions. ONE FIRST NUMBER IS MINOR WITH THE COMPARITION OF THE 2 OTHER NUMBERS.THEN THE SECOND NUMBER IS MINOR WITH THE COMPARITION OF THE TWO OTHER NUMBERS AND SOMETHING ELSE HAPPENS IS BECAUSE THE FINAL NUMBER IS THE SMALLEST.

 

int minimumThree(int x, int y, int z){

if(x<=y && x<=z)
{

result=x;

}
else if(y<=x && y<=z)
{

result=y;

}

else
{

result=z;

}

} // returns the value that is smallest of x, y and z

IN THE PART OF THE SUM SQUARE YOU HAVE TO MAKE THE RETURN OPERATION:

return (x*x + y*y + z*z); // returns the value of the sum of squares of x, y, z

WITH THIS YOU SEND THE RESULT OF THE VALUE IN THE Y VARIABLE IN INT MAIN

LINK OF THE CODE IN GITHUB: quiz4.cpp

ALSO THE CODE IS HERE:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01 and #Mastery08 (Importing and using libraries)

using namespace std;

int result,result2;

int minimumThree(int x, int y, int z){

if(x<=y && x<=z)
{

result=x;

}


else if(y<=x && y<=z)
{

result=y;

}

else
{

result=z;

}

} // returns the value that is smallest of x, y and z

int sumSquares(int x, int y, int z) {

return (x*x + y*y + z*z);



} // returns the value of the sum of squares of x, y, z


int main()
{
int x, y, z;

cout<<"GIVE A FIRST NUMBER:";
cin>>x;

cout<<"Give A SECOND NUMBER:";

cin>>y;

cout<<"GIVE A THIRD NUMBER:";
cin>>z;

x= minimumThree (x,y,z); //CALL THE FUNCTION OF THE MINIUM VALUE OF THE NUMBERS


cout<<"THE MINIUM VALUE OF THE NUMBERS:"<<result<<endl; //CALL THE FUNCTION OF THE MINIUM VALUE OF THE NUMBERS

y = sumSquares(x,y,z); //CALL THE FUNCTION OF THE SUM OF THE NUMBERS

cout<<"THE SUM OF THE NUMBERS:"<<y<<endl; //CALL THE FUNCTION OF THE SUM OF THE NUMBERS




return 0;



}





Anuncio publicitario

4 comentarios en “#Quiz04

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s