1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algo2023_2_HirecheDjamaleddine
{
class Program
{
static void Main(string[] args)
{
MyUtilsExam utils = new MyUtilsExam();
Console.WriteLine("Introduisez votre nom ou pseudo");
string pseudo = Console.ReadLine();
//Console.WriteLine("Introduisez une phrase");
string phrase = Console.ReadLine();
Console.WriteLine("Introduisez 3 nombres entiers, séparés par une virgule");
string intsString = Console.ReadLine();
int[] intArray = utils.TransformToInt(intsString);
// on affiche le plus grand des 3 nombres
int max = utils.NombreMax(intArray);
Console.WriteLine("Le plus grand nombre est " + max);
// on affiche le plus petit des 3 nombres
int min = NombreMin(intArray);
Console.WriteLine("Le plus petit nombre est " + min);
// on affiche combien de nombres sont divisibles par 3
int divisibles = utils.NombreDivisiblesPar3(intArray);
Console.WriteLine(divisibles + " nombres sont divisibles par 3");
// on affiche un des 3 nombres de façon aléatoire
int nbrAleatoire = utils.NombreAleatoire(intArray);
Console.WriteLine("Le nombre aleatoire est " + nbrAleatoire);
// on affiche le nombre de caractères dans la phrase, y compris espaces, signes de ponctuation...
int nbrChars = utils.NbrChars(phrase);
Console.WriteLine("Nombre de caracteres : " + nbrChars);
// on affiche la phrase inversée, par exemple 'ceci est une phrase' devient 'esarhp enu tse icec'
string inverse = utils.InversePhrase(phrase);
Console.WriteLine("Inverse : " + inverse);
// on sauvegarde la demande dans un fichier "c://temp/myUtilsExam.utils" sous la forme:
// Votre pseudo = DiabloX9
// Votre phrase = Ceci est ma phrase
// Vos numéros = 3,9,23
//Le code ne va pas fonctionner car la variable "intsTring" n'est pas bien noté. On pourrait régler ça en créant une instruction
//avec le try catch pour créer une exception qui montrera la ligne qui est fausse
SaveResult(phrase, intsTring, pseudo);
}
Random rnd = new Random();
internal class MyUtilsExam
{
public static void TransformToInt(string strInt)
{
int[] ints = int32.Parse(intsString);
Console.WriteLine(ints);
}
public static void SaveResult(string phrase, object intsTring, string pseudo)
{
string save = @"C:\Users\djelectro95\Documents\Examen\myUtilsExam.utils";
string[] saving = { pseudo, intsString, phrase };
for (int i = 0; i < saving.Length; i++)
File.WriteAllLines(save, saving);
}
public string InversePhrase(string phrase)
{
char[] stringArray = message.ToCharArray();
string reverse = String.Empty;
for (int i = stringArray.Length - 1; i >= 0; i--)
{
reverse += stringArray[i];
}
Console.WriteLine(reverse);
}
public static int NbrChars(string phrase)
{
string phrase = Console.ReadLine();
int nbrChars = phrase.Length;
Console.WriteLine(nbrChars);
}
public static int NombreAleatoire(int[] intArray)
{
int[] intArray = int32.Parse(intsString);
int aleatoire = rnd.Next(intArray.Length);
Console.WriteLine(aleatoire);
}
public static int NombreDivisiblesPar3(int[] intArray)
{
int[] intArray = int32.Parse(intsString);
int divisible = intArray.Length;
if(divisible % 3 == 0)
{
divisible = divisible / 3;
}
Console.Writeline(divisible);
}
public static int NombreMin(int[] intArray)
{
string intsString = Console.ReadLine();
int[] intArray = Int32.Parse(intsString);
int min = intArray.Min();
Console.WriteLine(min);
}
public static int NombreMax(int[] intArray)
{
string intsString = Console.ReadLine();
int[] intArray = Int32.Parse(intsString);
int max = intArray.Max();
Console.WriteLine(max);
}
}
}
} |
Partager