first commit
This commit is contained in:
49
listas4/Program.cs
Normal file
49
listas4/Program.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using exercicios;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
namespace listas4
|
||||
{
|
||||
class Program
|
||||
{
|
||||
// Made by F. Raszeja
|
||||
static bool ParseStr(string val)
|
||||
{
|
||||
if (!val.Any(x=> char.IsLetter(x))){
|
||||
int tmp = int.Parse(val);
|
||||
if (tmp != 0 && tmp <= 7) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string sel = "";
|
||||
do{
|
||||
Console.Clear();
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
Console.WriteLine("Fourth Assignment List");
|
||||
Console.ResetColor();
|
||||
|
||||
Console.WriteLine("\n1-7\tExamples 1-7");
|
||||
Console.WriteLine("\texit\tQuit to Desktop");
|
||||
|
||||
Console.Write("--> ");
|
||||
sel = Console.ReadLine();
|
||||
|
||||
if(sel != "exit" && ParseStr(sel)){
|
||||
Type typesPrograma = Type.GetType("exercicios.exercicio"+sel);
|
||||
MethodInfo aInvocar = typesPrograma.GetMethod(
|
||||
"Init", BindingFlags.Static | BindingFlags.Public);
|
||||
aInvocar.Invoke(null, null);
|
||||
}
|
||||
Console.WriteLine("\nPress any key to continue...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
while(sel.ToLower() != "exit");
|
||||
}
|
||||
}
|
||||
}
|
8
listas4/listas4.csproj
Normal file
8
listas4/listas4.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
86
listas4/src/exercicios1-3.cs
Normal file
86
listas4/src/exercicios1-3.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class exercicio1
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
int[] valores = new int[15];
|
||||
|
||||
Console.WriteLine("Insert a value, press enter. Goes up to 15 values");
|
||||
|
||||
for(int i = 0; i < valores.Length; i++)
|
||||
{
|
||||
valores[i] = int.Parse(Console.ReadLine());
|
||||
}
|
||||
for(int i = 0; i < valores.Length; i++)
|
||||
{
|
||||
if(i % 2 == 0)Console.WriteLine("{0} has an even index number in the array.",valores[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class exercicio2
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
float[] notas = new float[15];
|
||||
float media;
|
||||
int QtdAbaixo = 0, QtdAcima = 0;
|
||||
|
||||
Console.WriteLine("Insert the grade, press enter. Goes up to 15 values");
|
||||
|
||||
for(int i = 0; i < notas.Length; i++)
|
||||
{
|
||||
notas[i] = float.Parse(Console.ReadLine());
|
||||
}
|
||||
|
||||
media = notas.Sum() / notas.Length;
|
||||
|
||||
foreach(float i in notas)
|
||||
{
|
||||
if(i > media)QtdAcima++;
|
||||
if(i < media)QtdAbaixo++;
|
||||
}
|
||||
Console.WriteLine("Avg. : {0:N2}, Students below: {1}, Students above: {2}",media,QtdAbaixo,QtdAcima);
|
||||
}
|
||||
}
|
||||
public class exercicio3
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
string[] nome = new string[10];
|
||||
float[] preco = new float[10];
|
||||
float srch;
|
||||
int e = 0;
|
||||
|
||||
Console.WriteLine("Insert a name, press enter. Goes up to 10 values.");
|
||||
|
||||
for(int i = 0; i < nome.Length; i++)
|
||||
{
|
||||
nome[i] = Console.ReadLine();
|
||||
}
|
||||
|
||||
Console.WriteLine("Insert a price, press enter. Goes up to 10 values.");
|
||||
|
||||
for(int i = 0; i < preco.Length; i++)
|
||||
{
|
||||
preco[i] = float.Parse(Console.ReadLine());
|
||||
}
|
||||
|
||||
Console.WriteLine("Insert the highest possible price to search with.");
|
||||
|
||||
srch = float.Parse(Console.ReadLine());
|
||||
|
||||
while(e < preco.Length)
|
||||
{
|
||||
if(preco[e] <= srch)
|
||||
{
|
||||
Console.WriteLine("{0}: $ {1:N2}",nome[e],preco[e]);
|
||||
}
|
||||
e++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
76
listas4/src/exercicios4-5.cs
Normal file
76
listas4/src/exercicios4-5.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class exercicio4
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
int[,] valores = new int[5,5];
|
||||
int somaTot = 0, somaLin = 0;
|
||||
|
||||
Console.WriteLine("Insert a value, press enter. End goal is to fill a 5x5 matrix.");
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = int.Parse(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
foreach(int i in valores)
|
||||
{
|
||||
somaTot += i;
|
||||
}
|
||||
Console.WriteLine("Total sum:{0}",somaTot);
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
somaLin = 0;
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
somaLin += valores[k,l];
|
||||
}
|
||||
Console.WriteLine("Line: {0}, Sum: {1}",k,somaLin);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class exercicio5
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
int[,] valores = new int[4,5];
|
||||
int ParMed, ImparMed, QtdPar, QtdImpar;
|
||||
ParMed = ImparMed = QtdImpar = QtdPar = 0;
|
||||
|
||||
Console.WriteLine("Insert a value, press enter. End goal is to fill a 4x5 matrix.");
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = int.Parse(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
foreach(int i in valores)
|
||||
{
|
||||
if(i % 2 == 0)
|
||||
{
|
||||
QtdPar++;
|
||||
ParMed += i;
|
||||
}
|
||||
else
|
||||
{
|
||||
QtdImpar++;
|
||||
ImparMed += i;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Odd: {0}, Even: {1}, Sum Odd: {2}, Sum Even: {3}, Avg. Odd: {4:N2}, Avg. Even: {5:N2}",
|
||||
QtdImpar,QtdPar,ParMed,ImparMed,(double)ImparMed/QtdImpar,(double)ParMed/QtdPar);
|
||||
}
|
||||
}
|
||||
}
|
44
listas4/src/exercicios6.cs
Normal file
44
listas4/src/exercicios6.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class exercicio6
|
||||
{
|
||||
public static void Init(){
|
||||
int[,] valores = new int[5,5];
|
||||
int sumP = 0, sumS = 0;
|
||||
Random random = new Random();
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = random.Next(1,25);
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = random.Next(1,25);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("\nPrimary diagonal");
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
sumP += valores[k,k];
|
||||
Console.Write("{0}\t\n",valores[k,k]);
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("\nSecondary diagonal");
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
sumS += valores[k,valores.GetLength(0)-k-1];
|
||||
Console.Write("{0}\t\n",valores[k,valores.GetLength(0)-k-1]);
|
||||
}
|
||||
Console.WriteLine("\n{0} - Sum Primary, {1} - Sum Secondary", sumP, sumS);
|
||||
}
|
||||
}
|
||||
}
|
54
listas4/src/exercicios7.cs
Normal file
54
listas4/src/exercicios7.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class exercicio7
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("Insert a name, then 3 grades.\nYou'll have to do this 10 times.");
|
||||
string[] nome = new string[10];
|
||||
float[,] nota = new float[10,3];
|
||||
float sum = 0;
|
||||
|
||||
for(int k = 0; k < nota.GetLength(0); k++)
|
||||
{
|
||||
Console.WriteLine("\nInsert a name.");
|
||||
nome[k] = Console.ReadLine();
|
||||
for(int l = 0; l < nota.GetLength(1); l++)
|
||||
{
|
||||
// Original portuguese code had a {0}ª, representing what exam/assignment you're grading. Can't be arsed to localise this.
|
||||
Console.WriteLine("Insert the grade.");
|
||||
nota[k,l] = float.Parse(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
for(int k = 0; k < nota.GetLength(0); k++)
|
||||
{
|
||||
for(int i = 0; i < nota.GetLength(1); i++)
|
||||
{
|
||||
sum += nota[k,i];
|
||||
}
|
||||
|
||||
if((sum/3) >= 7)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
}
|
||||
|
||||
Console.Write("\nStudent: {0}:\t", nome[k]);
|
||||
for(int l = 0; l < nota.GetLength(1); l++)
|
||||
{
|
||||
Console.Write("{0:N2}\t",nota[k,l]);
|
||||
}
|
||||
Console.Write("{0:N2}",sum/3);
|
||||
sum = 0;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user