first commit
This commit is contained in:
8
listas3/listas3.csproj
Normal file
8
listas3/listas3.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
49
listas3/main.cs
Normal file
49
listas3/main.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using exercicios;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
namespace principal
|
||||
{
|
||||
class Programa
|
||||
{
|
||||
// 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 <= 8) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string sel = "";
|
||||
do{
|
||||
Console.Clear();
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
Console.WriteLine("Third Assignment List - 17/09/2020");
|
||||
Console.ResetColor();
|
||||
|
||||
Console.WriteLine("\n1-8\tExamples 1-8");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
36
listas3/source/exercicio1.cs
Normal file
36
listas3/source/exercicio1.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
class Exercicio1{
|
||||
public static void Init()
|
||||
{
|
||||
string nome;
|
||||
|
||||
Console.WriteLine("Write a Name");
|
||||
nome = Console.ReadLine();
|
||||
|
||||
double media = lerNota();
|
||||
|
||||
Console.WriteLine("Student: {0}, Avg. Grade: {1:N2}",nome,media);
|
||||
Console.WriteLine(media > 7 ? "PASS" : "FAIL");
|
||||
}
|
||||
static double lerNota()
|
||||
{
|
||||
|
||||
float n1,n2;
|
||||
|
||||
Console.WriteLine("Insert the grades (2)...");
|
||||
n1 = float.Parse(Console.ReadLine());
|
||||
n2 = float.Parse(Console.ReadLine());
|
||||
|
||||
return calcularMedia(n1,n2);
|
||||
|
||||
}
|
||||
|
||||
static float calcularMedia(float i, float i2)
|
||||
{
|
||||
return ((i+i2)/2);
|
||||
}
|
||||
}
|
||||
}
|
27
listas3/source/exercicio2.cs
Normal file
27
listas3/source/exercicio2.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
class Exercicio2{
|
||||
public static void Init()
|
||||
{
|
||||
int n;
|
||||
Console.WriteLine("Insert a value");
|
||||
n = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0}! = {1}",n,calcularFatorial(n));
|
||||
|
||||
}
|
||||
static int calcularFatorial(int n)
|
||||
{
|
||||
int fat = 1;
|
||||
|
||||
for(int i = 1; i <= n; i++)
|
||||
{
|
||||
fat *= i;
|
||||
}
|
||||
|
||||
return fat;
|
||||
}
|
||||
}
|
||||
}
|
24
listas3/source/exercicio3.cs
Normal file
24
listas3/source/exercicio3.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class Exercicio3{
|
||||
public static void Init()
|
||||
{
|
||||
double i,i2;
|
||||
Console.WriteLine("Insert the values (2)...");
|
||||
i = double.Parse(Console.ReadLine());
|
||||
i2 = double.Parse(Console.ReadLine());
|
||||
diferenca(i,i2);
|
||||
}
|
||||
static void diferenca(double n, double n2)
|
||||
{
|
||||
double val = 0;
|
||||
val = n > n2 ? n - n2 : n2 - n;
|
||||
|
||||
Console.WriteLine("The result being zero means the numbers are equal.");
|
||||
Console.WriteLine("The difference between {0:N2} and {1:N2} is {2:N2}",
|
||||
n,n2,val);
|
||||
}
|
||||
}
|
||||
}
|
63
listas3/source/exercicio4.cs
Normal file
63
listas3/source/exercicio4.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
class Exercicio4{
|
||||
public static void Init()
|
||||
{
|
||||
double a,b,c;
|
||||
|
||||
Console.WriteLine("Insert the triangle's dimensions (A,B,C)");
|
||||
|
||||
a = double.Parse(Console.ReadLine());
|
||||
b = double.Parse(Console.ReadLine());
|
||||
c = double.Parse(Console.ReadLine());
|
||||
|
||||
|
||||
|
||||
if(a < (b+c) && b < (a+c) && c < (a+b))
|
||||
{
|
||||
Console.WriteLine(TriEquil(a,b,c) == true ?
|
||||
"Equilateral" : TriIso(a,b,c) == true ?
|
||||
"Isosceles" : TriEsc(a,b,c) == true ?
|
||||
"Scalene" : "N. A.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not a triangle.");
|
||||
}
|
||||
|
||||
}
|
||||
static bool TriEquil(double a, double b, double c)
|
||||
{
|
||||
if (a == b && b == c)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static bool TriIso(double a, double b, double c)
|
||||
{
|
||||
if (a == b || a == c || b == c)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static bool TriEsc(double a, double b, double c)
|
||||
{
|
||||
|
||||
if((TriIso(a,b,c) && TriEquil(a,b,c)) == false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else {return false;}
|
||||
}
|
||||
}
|
||||
}
|
106
listas3/source/exercicio5.cs
Normal file
106
listas3/source/exercicio5.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
class Exercicio5
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
string sel = "";
|
||||
|
||||
Console.WriteLine("Select an operation:"+
|
||||
"\n1 - Sum"+
|
||||
"\n2 - Subtract"+
|
||||
"\n3 - Divide"+
|
||||
"\n4 - Multiply"+
|
||||
"\n5 - Div. Remains"+
|
||||
"\n6 - Double"+
|
||||
"\n7 - Squared"+
|
||||
"\n8 - Cubed"+
|
||||
"\n9 - Square Root"+
|
||||
"\n0 - Exit");
|
||||
|
||||
sel = Console.ReadLine();
|
||||
if(sel != "0"){
|
||||
Console.WriteLine("Insert a value and press Enter (2)");
|
||||
Type typesPrograma = typeof(Exercicio5);
|
||||
MethodInfo aInvocar = typesPrograma.GetMethod(
|
||||
"op"+sel, BindingFlags.Static | BindingFlags.NonPublic);
|
||||
aInvocar.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
static void op1()
|
||||
{
|
||||
int i, i2;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
i2 = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0} + {1} = {2}",i,i2,i+i2);
|
||||
}
|
||||
static void op2()
|
||||
{
|
||||
int i, i2;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
i2 = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0} - {1} = {2}",i,i2,i-i2);
|
||||
}
|
||||
static void op3()
|
||||
{
|
||||
int i, i2;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
i2 = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0} / {1} = {2:N2}",i,i2,(double)i/i2);
|
||||
}
|
||||
static void op4()
|
||||
{
|
||||
int i, i2;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
i2 = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0} * {1} = {2}",i,i2,i*i2);
|
||||
}
|
||||
static void op5()
|
||||
{
|
||||
int i, i2;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
i2 = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0} % {1} = {2}",i,i2,(double)i%i2);
|
||||
}
|
||||
static void op6()
|
||||
{
|
||||
int i;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0}*2 = {1}",i,i*2);
|
||||
}
|
||||
static void op7()
|
||||
{
|
||||
int i;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("{0}^2 = {1}",i,i*i);
|
||||
}
|
||||
static void op8()
|
||||
{
|
||||
int i;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
Console.WriteLine("{0}^3 = {1}",i,i*i*i);
|
||||
|
||||
}
|
||||
static void op9()
|
||||
{
|
||||
int i;
|
||||
i = int.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("Sqrt({0}) = {1}",i,Math.Sqrt(i));
|
||||
}
|
||||
static void op10()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
36
listas3/source/exercicio6.cs
Normal file
36
listas3/source/exercicio6.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class Exercicio6
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
string sexo;
|
||||
float i_altura;
|
||||
|
||||
Console.WriteLine("Biological sex (male/female):");
|
||||
sexo = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Height (in meters):");
|
||||
i_altura = float.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("\n{0:N2} is the ideal weight for a {1}, with the height of: {2}m",
|
||||
calcularPesoIdeal(i_altura,sexo),sexo,i_altura);
|
||||
}
|
||||
static float calcularPesoIdeal(float i, string s)
|
||||
{
|
||||
switch(s.ToLower())
|
||||
{
|
||||
case "male":
|
||||
return (72.7f*i)-58f;
|
||||
case "female":
|
||||
return (62.1f*i)-44.7f;
|
||||
default:
|
||||
Console.WriteLine("\nWrite a valid value!");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
31
listas3/source/exercicio7.cs
Normal file
31
listas3/source/exercicio7.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class Exercicio7
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
float x,y;
|
||||
Console.WriteLine("Write the values for X and Y");
|
||||
x = float.Parse(Console.ReadLine());
|
||||
y = float.Parse(Console.ReadLine());
|
||||
Console.WriteLine("(x{0:N2};y{1:N2}) is in quadrant {2}",
|
||||
x,y,verificaQuadrante(x,y));
|
||||
}
|
||||
static char verificaQuadrante(float x, float y)
|
||||
{
|
||||
if (x > 0)
|
||||
{
|
||||
if(y >= 0)return '1';
|
||||
else if(y < 0)return '4';
|
||||
}
|
||||
else if (x < 0)
|
||||
{
|
||||
if(y >= 0)return '2';
|
||||
else if(y < 0)return '3';
|
||||
}
|
||||
return 'N';
|
||||
}
|
||||
}
|
||||
}
|
25
listas3/source/exercicios8.cs
Normal file
25
listas3/source/exercicios8.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
class Exercicio8
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
float b,a;
|
||||
Console.WriteLine("Hypotenuse Calculator\nInsert the values for b (triangle base) & a (triangle height).");
|
||||
|
||||
b = float.Parse(Console.ReadLine());
|
||||
a = float.Parse(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("\nTriangle base {0}, Height {1}, Hypotenuse {2:N2}",
|
||||
b,
|
||||
a,
|
||||
hipotenusa(a,b));
|
||||
}
|
||||
static float hipotenusa(float b, float a)
|
||||
{
|
||||
return (float)Math.Sqrt((b*b)+(a*a));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user