Вывести на экран фамилию, имя и адрес учеников, у которых нет домашнего телефона - C# (195310)
Формулировка задачи:
Условие:Известны данные о 25 учениках класса: фамилия, имя, отчество, адрес и домашний телефон, если он есть. Вывести на экран фамилию, имя и адрес учеников, у которых нет домашнего телефона. нужно решить с использованием структуры. вот пробою решать но при заполнении данными выдает ошибку. в чем проблема???
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Studients_strukt
{
public struct Studient
{
public string f;
public string im;
public string o;
public string adress;
public int tel;
}
class Program
{
static Studient[] i = new Studient[3];//массив
static int t = 0;
static int s =0;
static void Main(string[] args)
{
Programm();
}
static void Add()
{
i[t] = new Studient();
Console.Write("Введите Фамилию: ");
i[t].f = Console.ReadLine();
Console.Write("Введите Имя: ");
i[t].im = Console.ReadLine();
Console.Write("Введите Отчество: ");
i[t].o = Console.ReadLine();
Console.Write("Введите Адресс: ");
i[t].adress = Console.ReadLine();
Console.Write("Введите Телефон?, а если его нет - поставьте '0' ");
i[t].tel = Convert.ToInt32(Console.ReadLine());
t++;
Programm();
}
static void Programm()
{
Console.WriteLine("1-Ввести данные,2-Выйти");
int k = Convert.ToInt32(Console.ReadLine());
switch (k)
{
case 1: Add(); break;
case 2: break;
}
}
private static void Class()
{
for (int j = 0; j < t; j++)
if (i[t].tel == s)
Console.WriteLine(" ");
Console.WriteLine("{0}\n{1}\n{2}\n{3}\n\n", i[t].f, i[t].im, i[t].o, i[t].adress);
Programm();
}
}
}Решение задачи: «Вывести на экран фамилию, имя и адрес учеников, у которых нет домашнего телефона»
textual
Листинг программы
using System;
namespace Students
{
public struct Student
{
private string _firstName;
private string _secondName;
private string _thirdName;
private string _adress;
private string _telephone;
public string Familiya
{
get { return _secondName; }
}
public String Telephone
{
get { return _telephone; }
}
public void Add()
{
Console.ForegroundColor=ConsoleColor.DarkMagenta;
Console.Write("Введите Фамилию: ");
_firstName = Console.ReadLine();
Console.Write("Введите Имя: ");
_secondName = Console.ReadLine();
Console.Write("Введите Отчество: ");
_thirdName = Console.ReadLine();
Console.Write("Введите Адресс: ");
_adress = Console.ReadLine();
Console.Write("Введите Телефон?, а если его нет - поставьте '0' ");
_telephone = Console.ReadLine();
Console.ForegroundColor=ConsoleColor.Gray;
}
public override string ToString()
{
Console.ForegroundColor=ConsoleColor.Magenta;
return String.Format("Имя-{0}\nФамилия-{1}\nОтчество-{2}\nАдресс-{3}\nТелефон-{4}\n\n", _firstName, _secondName,
_thirdName, _adress, _telephone);
}
}
class Program
{
static void Main(string[] args)
{
int count;
do
{
Console.BackgroundColor=ConsoleColor.Black;
Console.Clear();
Console.BackgroundColor=ConsoleColor.DarkRed;
Console.Write("Введите количество студентов:");
} while (!int.TryParse(Console.ReadLine(), out count) || count < 1);
Console.BackgroundColor = ConsoleColor.Black;
var students = new Student[count];
for (int i = 0; i < count; i++)
{
int k;
do
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("1-Ввести данные для {0} студента",i+1);
Console.WriteLine("2-Exit");
Console.ForegroundColor=ConsoleColor.Gray;
} while (!int.TryParse(Console.ReadLine(), out k));
switch (k)
{
case 1: students[i].Add(); break;
case 2: return;
}
Console.Clear();
}
Console.WriteLine(new string('-',30));
Console.WriteLine("Сохраненные данные");
Console.WriteLine(new string('-', 30));
for (int i = 0; i < count; i++)
{
Console.Write(students[i]);
}
foreach (var student in students)
{
if (student.Telephone.Equals("0") || String.IsNullOrEmpty(student.Telephone))
{
Console.WriteLine("У студента с фамилией {0} нет номера",student.Familiya);
}
}
}
}
}