first commit

This commit is contained in:
rasz 2021-09-02 08:31:01 -03:00
commit a065d198ad
22 changed files with 1521 additions and 0 deletions

388
.gitignore vendored Normal file
View File

@ -0,0 +1,388 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Nuget personal access tokens and Credentials
nuget.config
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
.idea/
*.sln.iml

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# A collection of C Sharp terminal "software"
## Author(s): F. Raszeja
Made during the second semester of 2020. Requires .NET Core 3.1, but I wouldn't be surprised if it ran on earlier versions.
Code has portuguese names but it shouldn't be too difficult to understand... I hope!

172
listas/listaexercicio1.cs Normal file
View File

@ -0,0 +1,172 @@
using System;
using System.Linq;
using System.Reflection;
namespace listascs
{
/*
1st Assignment
Author: F. Raszeja
Original delivery date: 25/08/2020
Translated to English: 30/08/2021
Notes: Some of the proposed activities have too many variables so I was lazy and used an array, as it also has extra functions that help me a little bit, like Reverse(), etc.
*/
class Lista1
{
static void exercicio1()
{
string[] info = new string[3];
Console.WriteLine("Name:");
info[0] = Console.ReadLine();
Console.WriteLine("Age:");
info[1] = Console.ReadLine();
Console.WriteLine("City:");
info[2] = Console.ReadLine();
Console.WriteLine("Name: {0}, Age: {1}, City: {2}", info[0], info[1], info[2]);
}
static void exercicio2()
{
int num;
Console.WriteLine("Write a number, then press ENTER:");
num = int.Parse(Console.ReadLine());
Console.WriteLine("Number: {0}, Double: {1}", num, num*2);
}
static void exercicio3()
{
int num;
Console.WriteLine("Write a number, then press ENTER:");
num = int.Parse(Console.ReadLine());
Console.WriteLine("Number: {0}, Number ^ 2: {1}",num,Math.Pow(num,2));
}
static void exercicio4()
{
float[] nums = new float[3];
Console.WriteLine("Insert the values for A, B and C:");
for(int i = 0; i<nums.Length;i++){nums[i] = float.Parse(Console.ReadLine());}
Console.WriteLine("\nResult: " + (((Math.Pow(nums[0],2f)) * 5f) - nums[2])/(nums[1] - (nums[0] % 4f)));
}
static void exercicio5()
{
byte idade;
Console.WriteLine("Write your age, then press ENTER: ");
idade = byte.Parse(Console.ReadLine());
Console.WriteLine( idade < 18 ? "\nYou are a minor." : "\nYou are not a minor.");
}
static void exercicio6()
{
float brl,usd;
Console.WriteLine("Insert the value in Brazilian Reais:");
brl = float.Parse(Console.ReadLine());
Console.WriteLine("\nInsert the current USD/BRL quote");
usd = float.Parse(Console.ReadLine());
Console.WriteLine("R${0:G3} converted to dollars is: ${1}",brl, Math.Round(brl/usd,2));
}
static void exercicio7()
{
string[] nomes = new string[2];
Console.WriteLine("Insert a name and press ENTER, then insert another one and press ENTER.");
for(int i = 0;i<nomes.Length;i++){nomes[i] = Console.ReadLine();}
foreach(string nome in nomes)
{
Console.WriteLine("Uppercase: {0}, Char. Qty.: {1}, First three characters: {2}",
nome.ToUpper(), nome.Length, nome.Substring(0,3));
}
}
static void exercicio8()
{
int[] values = new int[2];
Console.WriteLine("Insert a value, press ENTER, then insert another one and press ENTER.");
for(int i = 0;i<values.Length;i++){values[i] = int.Parse(Console.ReadLine());}
Console.WriteLine("Original values: [{0}], New values: [{1}]",
string.Join(", ", values), // Formatting the array before printing it out
string.Join(", ", values.Reverse()));
}
static void exercicio9()
{
int[] val = new int[4];
Console.WriteLine("Insert the values for W, X, Y and Z");
for(int i = 0;i<val.Length;i++){val[i] = int.Parse(Console.ReadLine());}
bool res = ((val[1] >= val[2]) && (val[3] <= val[1])) ? true : false;
bool res2 = ((val[1] == val[0]) && (val[2] == val[3])) ? true : false;
Console.WriteLine(res || res2);
}
static bool ParseStr(string val)
{
if (!val.Any(x=> char.IsLetter(x) ||
x.Equals('0')) // using Linq to check if it has any 0's or if it's a letter.
&& !System.Text.RegularExpressions.Regex.IsMatch(val, @"^[1-9]{2,}$")){return true;}
return false;
}
static void Main(string[] args)
// UI Code here.
{
string sel = "";
do{
// Cleaning the console up before anything
Console.Clear();
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("Select one of the examples");
Console.ResetColor();
Console.WriteLine("\n1-9\tExample 1-9");
Console.WriteLine("\texit\tClose this program");
Console.Write("--> ");
sel = Console.ReadLine();
if(sel != "exit" && ParseStr(sel)){
Type typesPrograma = typeof(Lista1);
MethodInfo aInvocar = typesPrograma.GetMethod(
"exercicio"+sel, BindingFlags.Static | BindingFlags.NonPublic);
aInvocar.Invoke(null, null);
/*
typeof - get the object type of something, in this case, something from the "Program" class.
MethodInfo - information related to the invoked method, in this case, we'll be using GetMethod to look up the methods with the name "exercicio" and the number (sel),
e.g. exercicio1, exercicio2
Since I'm using only static methods, I have to filter it out using the binding flags.
Then it's easy, just invoke the "aInvocar" MethodInfo, it shouldn't have any parameters or submethods so we'll give it null instead.
*/
}
Console.WriteLine("\nPress any key to Continue...");
Console.ReadKey();
}
while(sel.ToLower() != "exit");
}
}
}

11
listas/listascs.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<AssemblyName>TerminaisFatec</AssemblyName>
<Authors>F. Raszeja</Authors>
</PropertyGroup>
</Project>

214
listas2/listaexercicios2.cs Normal file
View File

@ -0,0 +1,214 @@
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
namespace listas2
{
/*
Author: F. Raszeja
2nd Assignment List delivery date: 10/09/2020
Translated to English: 30/08/2021
*/
class Lista2
{
static void exercicio1(){
for(int i = 11; i <= 250; i++)
{
if(i % 2 == 0)Console.WriteLine(i + " is even");
}
}
static void exercicio2(){
int a,b,tmp;
Console.WriteLine("Write a number, then press ENTER.");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
if (a < b)
{
tmp = a;
a = b;
b = tmp;
}
// b -- lowest value; a -- highest value
for(int i = a; i >= b; i--)
{
if(!(i % 2 == 0))Console.WriteLine(i + " is odd");
}
}
static void exercicio3(){
int a;
Console.WriteLine("Write a number, then press ENTER.");
a = int.Parse(Console.ReadLine());
for(int i = 1; i <= 10; i++)
{
Console.WriteLine("{0} x {1} = {2}",a,i,a*i);
}
}
static void exercicio4(){
int a,b,tmp,c = 0;
Console.WriteLine("Write a number, then press ENTER.");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
if (a < b)
{
tmp = a;
a = b;
b = tmp;
}
// b -- lowest value; a -- highest value
for(int i = a; i >= b; i--)
{
if(!(i % 2 == 0))c++;
}
Console.WriteLine("{0} odd numbers",c);
}
static void exercicio5(){
int[] input = new int[15];
int val = 0;
Console.WriteLine("Insert 15 numbers");
for(int i = 0; i < input.Length; i++)
{
input[i] = int.Parse(Console.ReadLine());
}
// Easier for me to just use Linq
// Console.WriteLine(input.Max());
// But I'll instead use a foreach
foreach(int num in input)
{
if(num > val)val = num;
}
Console.WriteLine(val + " is the biggest number.");
}
static void exercicio6(){
int[] notas = new int[10];
int cur, med, cou;
med = cou = 0;
while(cou < notas.Length){
Console.WriteLine("Insert a Grade (0-10)");
cur = int.Parse(Console.ReadLine());
if(!(cur <= 10 && cur >= 0))
{
Console.WriteLine("Invalid value. Try again.");
}
else
{
notas[cou] = cur;
cou++;
}
}
// Linq -> notas.Sum();
foreach(int e in notas)
{
med += e;
}
Console.WriteLine("The sum of all grades: {0}, Avg. grade: {1:N2}",med,(double)med/notas.Length);
}
static void exercicio7(){
for(int i = 1; i <= 100; i++)
{
if(i % 10 == 0)Console.WriteLine("{0} is a multiple of 10",i);
}
}
static void exercicio8(){
int val,fat = 1;
Console.WriteLine("Insert a value");
val = int.Parse(Console.ReadLine());
for(int i = 1; i <= val; i++)
{
fat *= i;
}
Console.WriteLine("{0}! = {1}",val,fat);
}
static void exercicio9(){
List<int> vals = new List<int>();
// Making a list to help me out
ConsoleKeyInfo sel;
int countA,countB,countC,countD;
countA=countB=countC=countD=0;
Console.Clear();
do
{
Console.WriteLine("\n------------------");
Console.WriteLine("Insert a number.");
vals.Add(int.Parse(Console.ReadLine()));
Console.WriteLine("Added. Continue (Y/N)?");
sel = Console.ReadKey();
} while(sel.Key == ConsoleKey.Y);
foreach(int e in vals)
{
if(e % 2 == 0){countA++;}else{countB++;}
if(e >= 0){countC++;}else{countD++;}
}
Console.WriteLine("\nFrom the list, {0} even numbers, {1} odd, {2} positives, {3} negatives",countA,countB,countC,countD);
}
static void exercicio10(){
int c, n;
double e = 0;
ConsoleKeyInfo sel;
do{
Console.Clear();
Console.WriteLine("Employee No.:");
c = int.Parse(Console.ReadLine());
Console.WriteLine("Worked hours:");
n = int.Parse(Console.ReadLine());
for(int i = 1; i <= n; i++)
{
if(i > 50){e+=20;}else{e = 0;}
}
Console.WriteLine("No. {0}, Regular Salary {1}, Exceeding Salary {2}, Total Salary {3}",c,(n*10),e, (n*10)+e);
Console.WriteLine("Continue (Y/N)?");
sel = Console.ReadKey();
} while(sel.Key == ConsoleKey.Y);
}
static bool ParseStr(string val)
{
if (!val.Any(x=> char.IsLetter(x))){
int tmp = int.Parse(val);
if (tmp != 0 && tmp <= 10) return true;
}
return false;
}
static void Main(string[] args)
// UI code again...
{
string sel = "";
do{
Console.Clear();
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("Select one of the Examples");
Console.ResetColor();
Console.WriteLine("\n1-10\tExamples 1-10");
Console.WriteLine("\texit\tQuit to desktop.");
Console.Write("--> ");
sel = Console.ReadLine();
if(sel != "exit" && ParseStr(sel)){
Type typesPrograma = typeof(Lista2);
MethodInfo aInvocar = typesPrograma.GetMethod(
"exercicio"+sel, BindingFlags.Static | BindingFlags.NonPublic);
aInvocar.Invoke(null, null);
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
while(sel.ToLower() != "exit");
}
}
}

8
listas2/listas2.csproj Normal file
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

8
listas3/listas3.csproj Normal file
View 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
View 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");
}
}
}

View 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);
}
}
}

View 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;
}
}
}

View 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);
}
}
}

View 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;}
}
}
}

View 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()
{
}
}
}

View 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;
}
}
}

View 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';
}
}
}

View 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));
}
}
}

49
listas4/Program.cs Normal file
View 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
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

View 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++;
}
}
}
}

View 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);
}
}
}

View 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);
}
}
}

View 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;
}
}
}
}