Opzione & 2

This commit is contained in:
La Programmatrice Verde
2025-03-14 16:02:49 +01:00
parent a42c0b4ffd
commit 09c2790b64
20 changed files with 295 additions and 6 deletions

View File

@@ -1,9 +1,197 @@
namespace matrix_4;
using System.Net;
namespace matrix_4;
class Program {
static void Main(string[] args) {
Console.Clear();
int scelta, lineaAutobus, fermataAutobus;
(string[], string[], bool[,]) configurazione = Configurazione();
string[] fermateAutobus = configurazione.Item1, lineeAutobus= configurazione.Item2;
bool[,] corrispondenzaLineaFermata = configurazione.Item3;
do {
Console.WriteLine("Debug: corrispondenzaLineaFermata");
MostraMatrice(corrispondenzaLineaFermata);
Console.WriteLine("Inserire un'opzione:");
Console.WriteLine("1. La linea passa per la fermata?");
Console.WriteLine("2. Quali linee passano per la fermata?");
Console.WriteLine("3. Quali e quante sono le fermate per la linea?");
Console.WriteLine("4. Due linee hanno fermate in comune?");
Console.WriteLine("5. oh hell nah");
Console.WriteLine("0. Esci");
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
switch (scelta) {
case 0:
break;
case 1:
Console.Clear();
lineaAutobus = SelezionaElementoArray(lineeAutobus);
fermataAutobus = SelezionaElementoArray(fermateAutobus);
if (corrispondenzaLineaFermata[lineaAutobus, fermataAutobus]) {
Console.WriteLine($"La linea {lineeAutobus[lineaAutobus]} passa per la fermata {fermateAutobus[fermataAutobus]}");
}
else {
Console.WriteLine($"La linea {lineeAutobus[lineaAutobus]} non passa per la fermata {fermateAutobus[fermataAutobus]}");
}
Pausa();
break;
case 2:
Console.Clear();
fermataAutobus = SelezionaElementoArray(fermateAutobus);
Console.WriteLine($"Per la fermata {fermateAutobus[fermataAutobus]} passano le linee:");
for (int i = 0; i < corrispondenzaLineaFermata.GetLength(1); i++) {
if (corrispondenzaLineaFermata[fermataAutobus, i]) {
Console.WriteLine(lineeAutobus[i]);
}
}
Pausa();
break;
case 3:
Console.Clear();
Pausa();
break;
case 4:
Console.Clear();
Pausa();
break;
case 5:
Console.Clear();
Pausa();
break;
}
}
while (scelta != 0);
}
static void MostraMatrice(bool[,] p_matrice) {
for (int r = 0; r < p_matrice.GetLength(0); r++) {
for (int c = 0; c < p_matrice.GetLength(1); c++) {
Console.Write(p_matrice[r, c] + " ");
}
Console.WriteLine();
}
}
static void Pausa() {
Console.WriteLine("Premere un tasto per continuare. . .");
Console.ReadKey();
Console.Clear();
}
static (string[], string[], bool[,]) Configurazione() {
int dimensione1, dimensione2, r = 0, c = 0, scelta;
(string[], string[], bool[,]) ritorno;
Console.Clear();
do {
Console.Write("Quante sono le fermate dell'autobus? ");
dimensione1 = Convert.ToInt32(Console.ReadLine());
if (dimensione1 <= 0) {
Console.WriteLine("Errore: non è possibile inserire un numero minore o uguale a zero.");
Pausa();
}
}
while (dimensione1 <= 0);
ritorno.Item1 = new string[dimensione1];
for (int i = 0; i < dimensione1; i++) {
Console.Write($"Inserire la fermata n. {i + 1}: ");
ritorno.Item1[i] = Console.ReadLine();
}
Console.Clear();
do {
Console.Write("Quante sono le linee dell'autobus? ");
dimensione2 = Convert.ToInt32(Console.ReadLine());
if (dimensione2 <= 0) {
Console.WriteLine("Errore: non è possibile inserire un numero minore o uguale a zero.");
Pausa();
}
}
while (dimensione2 <= 0);
ritorno.Item2 = new string[dimensione2];
for (int i = 0; i < dimensione2; i++) {
Console.Write($"Inserire la linea n. {i + 1}: ");
ritorno.Item2[i] = Console.ReadLine();
}
ritorno.Item3 = new bool[dimensione1, dimensione2];
Console.Clear();
while (r < dimensione1) {
while (c < dimensione2) {
Console.WriteLine($"Debug: r: {r}\tc: {c}\t dimensione1: {dimensione1}\t dimensione2: {dimensione2}");
Console.WriteLine($"La linea {ritorno.Item2[c]} si ferma alla fermata {ritorno.Item1[r]}?");
Console.WriteLine("[0] Sì\t[1] No");
scelta = Convert.ToInt32(Console.ReadLine());
switch (scelta) {
case 0:
ritorno.Item3[r, c] = true;
c++;
Console.Clear();
break;
case 1:
ritorno.Item3[r, c] = false;
c++;
Console.Clear();
break;
default:
Console.WriteLine("Opzione non valida.");
Pausa();
break;
}
}
r++;
c = 0;
}
return ritorno;
}
static void StampaArray(string[] p_array) {
for (int j = 0; j < p_array.Length; j++) {
Console.WriteLine("Elemento " + j + ": " + p_array[j]);
}
}
static void StampaArraySoloElementi(string[] p_array) {
for (int j = 0; j < p_array.Length; j++) {
Console.WriteLine(p_array[j]);
}
}
static int SelezionaElementoArray(string[] p_array) {
int ritorno;
do {
Console.WriteLine("Quale elemento selezionare?");
StampaArray(p_array);
ritorno = Convert.ToInt32(Console.ReadLine());
if (ritorno < 0 || ritorno > p_array.Length) {
Console.WriteLine("La scelta inserita non è valida.");
Pausa();
}
} while (ritorno < 0 || ritorno > p_array.Length);
return ritorno;
}
static void MostraLineeFermata(bool[,] p_matrice, int p_indiceFermata) {
bool[] ritorno = new bool[p_matrice.GetLength(1)];
for (int i = 0; i < p_matrice.GetLength(1); i++) {
if (p_matrice[p_indiceFermata, i]) {
ritorno[i] = true;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}

BIN
bin/Debug/net9.0/matrix_4 Executable file

Binary file not shown.

View File

@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"matrix_4/1.0.0": {
"runtime": {
"matrix_4.dll": {}
}
}
}
},
"libraries": {
"matrix_4/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

BIN
obj/Debug/net9.0/apphost Executable file

Binary file not shown.

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_4")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a42c0b4ffd82a599b51f6765da5945ea7350602c")]
[assembly: System.Reflection.AssemblyProductAttribute("matrix_4")]
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_4")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -0,0 +1 @@
d061d27a38797d544dcf00937cd4c8003e45f3c6fe40193cae0f0c8b0bc62771

View File

@@ -0,0 +1,15 @@
is_global = true
build_property.TargetFramework = net9.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = matrix_4
build_property.ProjectDir = /home/Verde/git/matrix_4/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@@ -0,0 +1 @@
9608c8ef14e9ba316fc42458522ae7c6f42771a0c1dedb67789fbf8695cb812b

View File

@@ -0,0 +1,14 @@
/home/Verde/git/matrix_4/bin/Debug/net9.0/matrix_4
/home/Verde/git/matrix_4/bin/Debug/net9.0/matrix_4.deps.json
/home/Verde/git/matrix_4/bin/Debug/net9.0/matrix_4.runtimeconfig.json
/home/Verde/git/matrix_4/bin/Debug/net9.0/matrix_4.dll
/home/Verde/git/matrix_4/bin/Debug/net9.0/matrix_4.pdb
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.GeneratedMSBuildEditorConfig.editorconfig
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.AssemblyInfoInputs.cache
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.AssemblyInfo.cs
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.csproj.CoreCompileInputs.cache
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.dll
/home/Verde/git/matrix_4/obj/Debug/net9.0/refint/matrix_4.dll
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.pdb
/home/Verde/git/matrix_4/obj/Debug/net9.0/matrix_4.genruntimeconfig.cache
/home/Verde/git/matrix_4/obj/Debug/net9.0/ref/matrix_4.dll

Binary file not shown.

View File

@@ -0,0 +1 @@
4f95fa8dc890848e7a8bfe126e89b34a58486b3d8b2f57a9a9f9eab0fc5429b4

Binary file not shown.

Binary file not shown.

Binary file not shown.