Tag Archives: mastery27

#Mastery27 – Validated user input in C++

Validar inputs de usuario en c++

En C++ tenemos la opcion de validar datos alfanumericos o los llamados strings. Estos inputs se comportan como cualquier número, por lo que su uso no es muy dificil. Primero debemos conocer las reglas básicas:

Reglas basicas:

  • No deje pasar los datos no válidos en adelante
  • Validar los datos en el momento de entrada.
  • Siempre dar la retroalimentación significativa usuario
  • Dígale al usuario lo que usted espera de leer como entrada

Ejemplos:

/* example one, a simple continue statement */
  

main()
{
	int     valid_input;    /* when 1, data is valid and loop is exited */
	char    user_input;     /* handles user input, single character menu choice */

	valid_input = 0;
	while( valid_input == 0 ) {
		printf("Continue (Y/N)?n");
		scanf("  %c", &user_input );
		user_input = toupper( user_input );
		if((user_input == 'Y') || (user_input == 'N') )  valid_input = 1;
		else  printf("07Error: Invalid choicen");
	}
}
Salida del programa:
Continuar (Y / N) ?
b
Error: eleccion no válida
Continuar (Y / N) ?
N


 

Aqui otro ejemplo:

/* example two, getting and validating choices */
  

main()
{
	int     exit_flag = 0, valid_choice;
	char    menu_choice;
	
	while( exit_flag == 0 ) {
		valid_choice = 0;
		while( valid_choice == 0 ) {
			printf("nC = Copy FilenE = ExitnM = Move Filen");
			printf("Enter choice:n");
			scanf("   %c", &menu_choice );
			if((menu_choice=='C') || (menu_choice=='E') || (menu_choice=='M'))
				valid_choice = 1;
			else
				printf("07Error. Invalid menu choice selected.n");
		}
		switch( menu_choice ) {
			case 'C' : ....................();    break;
			case 'E' : exit_flag = 1;  break;
			case 'M' : ....................();  break;
			default : printf("Error--- Should not occur.n"); break;
		}
	}
}

Salida del programa 
C = Copiar archivo
E = Salir
M = Mover archivo
Introduzca elección :
x
Error . Opción de menú seleccionada no válida 
C = Copiar archivo
E = Salir
M = Mover archivo
Introduzca elección :
E

 

Referencias: http://ftp.tuwien.ac.at/languages/c/programming-bbrown/c_032.htm

27 1017

Creation and use of dictionaries in Python #Mastery27

Here’s a video I made about the creation and use of dictionaries in Python:

https://www.youtube.com/watch?v=P3YPtW8c_qA

Oscar Ricardo López López A01229116

27

Mastery 27

Validated user input in C++

For this mastery, I found  a super useful video that taught me how to make a validation for a user input

Here is also an example code with a validation user input code:

 

 
 

int main(){
    bool valid = false;
    int input;
    while(!valid){
        if(std::cin>>input){//this checks whether an integer was entered
            if(input  0) valid = true;//then we have to see if this integer is in range
        }else std::cin.clear();//some cleaning up
		
        std::cin.ignore(std::numeric_limits<:streamsize>::max(), 'n');//empty input stream

        if(!valid) std::cout "this input is not validn";
    }
    std::cout " is between 1 and 5n";
    std::cin.get();
    return 0;
}

 

Credits:

https://www.youtube.com/watch?v=YIX7UhIKEIk

1017 27

Mastery27

Diccionarios

Se trata que cuando tienes una lista que a su vez tiene categorías, al momento de imprimir el pograma, te dara el valor de la categoría que indicaste. 

Link: https://github.com/LizethAcosta/Tareas/blob/master/Mastery27

27

Mastery 27

Creation and use of dictionaries in Python


Link To My Youtube Video:

Mastery 27

Creation and use of dictionaries in Python


Link To My Youtube Video:

Mastery 27

Creation and use of dictionaries in Python


Link To My Youtube Video:

#Mastery27

I also learned a lot from this video.

#Mastery27

I also learned a lot from this video.

#Mastery27

I also learned a lot from this video.