program 3
unknown
csharp
2 years ago
6.0 kB
6
Indexable
using System; class Camera { private int totalFrames; private int currentFrame; public Camera(int initialFrames) { totalFrames = initialFrames; currentFrame = 0; } public void TakePhoto() { if (currentFrame < totalFrames) { Console.WriteLine($"Фотография сделана. Кадр {++currentFrame}/{totalFrames}"); } else { Console.WriteLine("Больше нет доступных кадров. Замените пленку."); } } public void RewindFilm() { if (currentFrame > 0) { Console.WriteLine("Плёнка перемотана на начало."); currentFrame = 0; } else { Console.WriteLine("Плёнка уже в самом начале."); } } } class DigitalCamera : Camera { private int resolution; public DigitalCamera(int initialFrames, int initialResolution) : base(initialFrames) { resolution = initialResolution; } public void SetResolution(int newResolution) { resolution = newResolution; Console.WriteLine($"Разрешение установлено на {resolution} мегапикселей."); } public new void TakePhoto() { base.TakePhoto(); Console.WriteLine($"Цифровая фотография, сделанная с разрешением {resolution} мегапикселей."); } } class Program { static void Main() { Console.WriteLine("Выберите тип камеры:"); Console.WriteLine("1. Плёночный фотоаппарат"); Console.WriteLine("2. Цифровая фотоаппарат"); int choice; if (int.TryParse(Console.ReadLine(), out choice)) { switch (choice) { case 1: RunFilmCamera(); break; case 2: RunDigitalCamera(); break; default: Console.WriteLine("Неверный выбор. Выход из программы."); break; } } else { Console.WriteLine("Недопустимый ввод. Выход из программы."); } } static void RunFilmCamera() { Camera filmCamera = new Camera(20); while (true) { Console.WriteLine("Выберите действие:"); Console.WriteLine("1. Сделать фото"); Console.WriteLine("2. Перемотать плёнку"); Console.WriteLine("3. Выход"); int choice; if (int.TryParse(Console.ReadLine(), out choice)) { switch (choice) { case 1: filmCamera.TakePhoto(); break; case 2: filmCamera.RewindFilm(); break; case 3: return; default: Console.WriteLine("Неверный выбор. Попробуйте еще раз."); break; } } else { Console.WriteLine("Неверный ввод. Попробуйте еще раз."); } } } static void RunDigitalCamera() { Console.WriteLine("Введите начальное разрешение (в мегапикселях):"); int initialResolution; if (int.TryParse(Console.ReadLine(), out initialResolution)) { DigitalCamera digitalCamera = new DigitalCamera(30, initialResolution); while (true) { Console.WriteLine("Выберите действие:"); Console.WriteLine("1. Сделать фото"); Console.WriteLine("2. Установить разрешение"); Console.WriteLine("3. Выход"); int choice; if (int.TryParse(Console.ReadLine(), out choice)) { switch (choice) { case 1: digitalCamera.TakePhoto(); break; case 2: Console.WriteLine("Введите новое разрешение (в мегапикселях):"); int newResolution; if (int.TryParse(Console.ReadLine(), out newResolution)) { digitalCamera.SetResolution(newResolution); } else { Console.WriteLine("Неверный ввод. Попробуйте еще раз."); } break; case 3: return; default: Console.WriteLine("Неверный выбор. Попробуйте еще раз."); break; } } else { Console.WriteLine("Неверный ввод. Попробуйте еще раз."); } } } else { Console.WriteLine("Неверный ввод. Выход из программы."); } } }
Editor is loading...
Leave a Comment