sexta-feira, 3 de abril de 2020

C# - salários - tempos e porcentagens

Este programinha foi escrito por mim mesmo
originalmente em linguagem C, hoje depois
de alguns anos resolvi traduzi-lo em C#,
é indicado a iniciantes em C# especialmente,
mas a parte lógica com poucas modificações
pode ser reescrito em C ou C++, ou java e etc...
Acompanhem seu funcionamento no vídeo:





using System;
using System.Collections;

class Arr {
    public const int TAM = 100;
    int [ ] Salario = new int [ TAM ];
    int resp = 0, Asal = 0, Bsal = 0, Csal = 0, i = 0, Atemp = 0,
            Btemp = 0, Ctemp = 0;
    int igual = 0, Igual = 0, superior = 0, Superior = 0, inferior = 0,Inferior = 0;
      
       /*=============================================================================*/
       void Barra ( int lin, int col ) {
        int i, j;
        for ( i = 0; i < lin; i++ )
            for ( j = 0; j < col; j++ ) {
                Console.SetCursorPosition ( i, j );
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                Console.Write ( " " );
            }
    }
    /*============================================================*/
    void Informe ( ) {
        Console.SetCursorPosition ( 20, 28 );
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "Por: " );
        Console.SetCursorPosition ( 25, 28 );
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.Write ( "Samuel Lima" );
        Console.SetCursorPosition ( 20, 29 );
        Console.ForegroundColor = ConsoleColor.Black;
        Console.Write ( "sa_sp10@hotmail.com" );
        Console.SetCursorPosition ( 38, 31 );
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "MUITO OBRIGADO" );
    }
    /*==============================================================*/
    void Moldura ( int tam_lin_ini, int tam_lin_fim, int tam_ini_col,
        int tam_fim_col ) {
        int i, c;
        for ( i = tam_lin_ini; i < tam_lin_fim; i++ ) {
            for ( c = tam_ini_col; c < tam_fim_col; c++ ) {
                Console.SetCursorPosition ( c, i );
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write ( " " );
            }
        }
    }
    /*=================================================================*/
    void Ini_Array ( ) {
             int calc;
             Console.BackgroundColor = ConsoleColor.White;
             Console.ForegroundColor = ConsoleColor.Blue;
             Console.SetCursorPosition ( 17, 4 );
             Console.Write ( "Faremos cálculos para quantos empregados? " );
             Console.ForegroundColor = ConsoleColor.Red;
             calc = int.Parse ( Console.ReadLine ( ) );
             Console.ForegroundColor = ConsoleColor.Blue;

             for ( i = 0; i < calc; i++ ) {
                    Console.SetCursorPosition ( 17, 6 );
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write ( String.Format ( "Digite o salário do {0}º empregado:  ", i + 1 ) );
                    Console.ForegroundColor = ConsoleColor.Red;
                    Salario [ i ] = int.Parse ( Console.ReadLine ( ) );
                    Console.SetCursorPosition ( 50, 6 );
                    Console.Write ( "         " );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] == 1000 )
                           Asal++;
             }
             for ( i = 0; i < calc; i++ ) {
                    igual = Asal * 100 / ( i + 1 );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] > 1000 )
                           Bsal++;
             }
             for ( i = 0; i < calc; i++ ) {
                    superior = Bsal * 100 / ( i + 1 );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] < 1000 )
                           Csal++;
             }
             for ( i = 0; i < calc; i++ ) {
                    inferior = Csal * 100 / ( i + 1 );
             }
             Console.Write ("\n" );
             for ( i = 0; i < calc; i++ ) {
                    Console.SetCursorPosition ( 17, 8 );
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write ( "Digite o Tempo de serviço do {0}º empregado em mêses:  ", i + 1 );                 
                    Console.ForegroundColor = ConsoleColor.Red;
                    Salario [ i ] = int.Parse ( Console.ReadLine ( ) );
                    Console.SetCursorPosition ( 70, 8 );
                    Console.Write ( "      " );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] == 24 )
                           Atemp++;
             }
             for ( i = 0; i < calc; i++ ) {
                    Igual = Atemp * 100 / ( i + 1 );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] > 24 )
                           Btemp++;
             }
             for ( i = 0; i < calc; i++ ) {
                    Superior = Btemp * 100 / ( i + 1 );
             }
             for ( i = 0; i < calc; i++ ) {
                    if ( Salario [ i ] < 24 )
                           Ctemp++;
                    resp += Salario [ i ];
             }
             for ( i = 0; i < calc; i++ ) {
                    Inferior = Ctemp * 100 / ( i + 1 );
             }

        Console.ForegroundColor = ConsoleColor.Blue;
             Console.SetCursorPosition ( 7, 10 );
            
             Console.WriteLine ( "Existem {0} empregado (s) com salário  igual de 1000", Asal );
             Console.SetCursorPosition ( 7, 11 );
             Console.WriteLine ( "Existem {0} empregado (s) com salário superior a 1000", Bsal );
             Console.SetCursorPosition ( 7, 12 );
             Console.WriteLine ( "Existem {0} empregado (s) com salário inferior a 1000", Csal );
             Console.ReadKey ( );

             Console.SetCursorPosition ( 7, 14 );
             Console.WriteLine ( "A porcentagem de empregado (s) que recebem salário igual a 1000 e:  {0}%", igual );
             Console.SetCursorPosition ( 7, 15 );
             Console.WriteLine ( "A porcentagem de empregado (s) que recebem salário superior a 1000 e:  {0}%", superior );
             Console.SetCursorPosition ( 7, 16 );
             Console.WriteLine ( "A porcentagem de empregado (s) que recebem salário inferior a 1000 e:  {0}%", inferior );
        Console.ReadKey ( );
            
             Console.SetCursorPosition ( 7, 18 );
             Console.WriteLine ( "Existem {0} empregado (s) com tempo igual a 24 mêses", Atemp );
             Console.SetCursorPosition ( 7, 19 );
             Console.WriteLine ( "Existem {0} empregado (s) com tempo maior a 24 mêses", Btemp );
             Console.SetCursorPosition ( 7, 20 );
             Console.WriteLine ( "Existem {0} empregado (s) com tempo inferior a 24 mêses", Ctemp );
             Console.ReadKey ( );

             Console.SetCursorPosition ( 7, 22 );
             Console.WriteLine ( "A porcentagem de empregado (s) com tempo igual a 24 mêses e:  {0}%", Igual );
             Console.SetCursorPosition ( 7, 23 );
             Console.WriteLine ( "A porcentagem de empregado (s) com tempo superior a 24 mêses e:  {0}%", Superior );
             Console.SetCursorPosition ( 7, 24 );
             Console.WriteLine ( "A porcentagem de empregado (s) com tempo inferior a 24 mêses e:  {0}%", Inferior );
             Console.ReadKey ( );

             Console.SetCursorPosition ( 7, 26 );
             Console.WriteLine ( "O tempo médio de serviço dos empregados e: {0} mêses", resp / 5 );
       }
    /*========================================================================================*/
    public static void Main ( ) {
        Console.Title = ( "C# - SALÁRIOS, TEMPOS E PORCENTAGENS" );
        Arr array = new Arr ( );
        array.Moldura ( 1, 33, 2, 84 );
             Console.SetCursorPosition ( 26, 2 );
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "C# - SALÁRIOS, TEMPOS E PORCENTAGENS" );
             array.Informe ( );
             array.Ini_Array ( );
             //Segura a execução do programa
             Console.ReadKey ( );
             Environment.Exit ( 0 );
       }
}
/*===========================================================================================*/