Skip to content

Instantly share code, notes, and snippets.

@murevg
Last active February 10, 2025 17:29
Show Gist options
  • Save murevg/f3371f35a6ec0709b9ae713bbff9af88 to your computer and use it in GitHub Desktop.
Save murevg/f3371f35a6ec0709b9ae713bbff9af88 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Globalization;
namespace FirstModule
{
internal class FirstTask
{
static void Main(string[] args)
{
//Console.InputEncoding = Encoding.Unicode;
//Console.OutputEncoding = Encoding.Unicode;
/*
a. Объявить и проинициализировать 10 переменных. Среди них обязательно должны
быть int, float, string и char.
*/
Console.WriteLine("Задание A:\n");
int a = 1, b = 2, c = 3;
float af = 1.5f, bf = 2.5f, cf = 3.5f;
string firsMsg = "Hello", secondMsg = "My", thirdMsg = "Dear";
char symbol = 'j';
Console.WriteLine($"Переменные типа int: {a}, {b}, {c}.");
Console.WriteLine($"Переменные типа float: {af}, {bf}, {cf}.");
Console.WriteLine($"Переменные типа string: {firsMsg}, {secondMsg}, {thirdMsg}.");
Console.WriteLine($"Переменная типа char: {symbol}.");
/*
b. Далее отработать приведение типов. Заведите и проинициализируйте отдельно int
и float переменные и попробуйте присвоить интовой переменной, переменную
типа float
*/
Console.WriteLine("\nЗадание B:\n");
int i = 10;
float f = 1.58f;
Console.WriteLine($"Переменная float = {f}");
i = (int)f;
Console.WriteLine($"c потерей дробной части = {i}");
i = (int)MathF.Round(f);
Console.WriteLine($"c округлением в бОльшую сторону = {i}");
/*
c.Заведите строковую переменную, проинициализируйте ее следующей строкой
“1234.10”, далее создайте float переменную и попробуйте в нее распарсить
данную строку
*/
Console.WriteLine("\nЗадание С:\n");
string numberStr = "1234.10";
float floatValue = float.Parse(numberStr, CultureInfo.InvariantCulture);
Console.WriteLine($"Распарсил строковый тип в float: {floatValue}");
}
}
}
using System;
using System.Text;
namespace FirstModule
{
internal class SecondTask
{
static void Main(string[] args)
{
//Console.InputEncoding = Encoding.Unicode;
//Console.OutputEncoding = Encoding.Unicode;
string
name, // Как вас зовут?
age, // Сколько вам лет?
city, // Где вы живёте?
job, // Кто вы по профессии?
traits, // Какие три слова лучше всего вас описывают?
hobby, // Чем вам нравится заниматься в свободное время?
quote, // Есть ли у вас любимая цитата, которая вас вдохновляет?
favoriteMovie, // Какой фильм или сериал произвёл на вас сильное впечатление?
favoriteBook, // Какую книгу вы бы порекомендовали прочитать каждому?
musicTaste, // Какую музыку вы чаще всего слушаете?
dreamLocation, // Если бы у вас была возможность жить в любом месте, где бы это было?
perfectDay, // Каким был бы ваш идеальный день?
dreamTrip; // О каком путешествии вы мечтаете?
Console.WriteLine("Привет!\nМеня зовут Женя,\nа как тебя зовут?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите ваше имя: ");
Console.ResetColor();
name = Console.ReadLine();
Console.Clear();
Console.WriteLine($"Приятно познакомиться {name}, я здесь чтобы узнать больше о тебе.");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 1/12\n");
Console.ResetColor();
Console.WriteLine("Сколько тебе лет?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите ваш возраст: ");
Console.ResetColor();
age = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 2/12\n");
Console.ResetColor();
Console.WriteLine("Где вы живёте?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите ваш город: ");
Console.ResetColor();
city = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 3/12\n");
Console.ResetColor();
Console.WriteLine("Кто вы по профессии?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите вашу профессию: ");
Console.ResetColor();
job = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 4/12\n");
Console.ResetColor();
Console.WriteLine("Какие три слова лучше всего вас описывают?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
traits = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 5/12\n");
Console.ResetColor();
Console.WriteLine("Чем вам нравится заниматься в свободное время?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
hobby = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 6/12\n");
Console.ResetColor();
Console.WriteLine("Есть ли у вас любимая цитата, которая вас вдохновляет?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
quote = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 7/12\n");
Console.ResetColor();
Console.WriteLine("Какой фильм или сериал произвёл на вас сильное впечатление?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
favoriteMovie = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 8/12\n");
Console.ResetColor();
Console.WriteLine("Какую книгу вы бы порекомендовали прочитать каждому?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
favoriteBook = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 9/12\n");
Console.ResetColor();
Console.WriteLine("Какую музыку вы чаще всего слушаете?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
musicTaste = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 10/12\n");
Console.ResetColor();
Console.WriteLine("Если бы у вас была возможность жить в любом месте, где бы это было?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
dreamLocation = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 11/12\n");
Console.ResetColor();
Console.WriteLine("Каким был бы ваш идеальный день?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
perfectDay = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nВопрос 12/12\n");
Console.ResetColor();
Console.WriteLine("О каком путешествии вы мечтаете?");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("\nВведите: ");
Console.ResetColor();
dreamTrip = Console.ReadLine();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("ВАША АНКЕТА ГОТОВА:\n");
Console.ResetColor();
Console.WriteLine($"Вас зовут {name}, Вам {age} лет, и вы живёте в городе {city}. \nПо профессии вы {job}, но друзья вас знают как настоящего изобретателя. \nТри слова, которые вас описывают: {traits}.\n\nВ свободное время {name} увлекается такими хобби как: {hobby}.\nВас вдохновляет цитата: \"{quote}\" \nФильм, который произвёл на вас сильное впечатление, — \"{favoriteMovie}\", \nа ваша любимая книга — \"{favoriteBook}\". \nКогда вы отдыхаете, в ваших наушниках чаще всего играет {musicTaste}. \n\nЕсли бы у вас была возможность жить где угодно, вы бы выбрали {dreamLocation}. \nВаш идеальный день — {perfectDay}. \nНо ваша самая заветная мечта — {dreamTrip}.");
}
}
}
using System;
using System.Text;
using System.Globalization;
namespace FirstModule
{
internal class ThirdTask
{
static void Main(string[] args)
{
//Console.InputEncoding = Encoding.Unicode;
//Console.OutputEncoding = Encoding.Unicode;
float length = 1, width = 2; //длина и ширина
float boxArea;
//Ввод Длины
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("Введите длину дома: ");
Console.ResetColor();
length = float.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
Console.Clear();
Console.WriteLine($"Длина дома = {length}");
//Ввод Ширины
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("Введите ширину дома: ");
Console.ResetColor();
width = float.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
Console.Clear();
Console.WriteLine($"Длина дома = {length}\nШирина дома = {width}");
//Результат площадь дома
float houseArea = length * width;
Console.WriteLine($"\nПлощадь дома = {houseArea} м²\n");
//Ввод площади коробки
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("Введите площадь одной коробки мармелада: ");
Console.ResetColor();
boxArea = float.Parse(Console.ReadLine(),CultureInfo.InvariantCulture);
Console.Clear();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine($"Длина дома = {length}\nШирина дома = {width}\nПлощадь коробки = {boxArea} м²\n");
Console.ResetColor();
//Результат Кол-ва коробок способных поместитья в доме
Console.Write($"Макс. кол-во коробок способных поместиться в доме = ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{MathF.Floor(houseArea / boxArea)} шт.");
Console.ResetColor();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment