Написал программу по следующему заданию. При компиляции выдает ошибки помогите их исправить пожалуйста. Если возможно, подправите пожалуйста мою программу и выдайте ее правильный вариант. Также покажите пожалуйста как реализовать в program.cs вывод символов в верхнем регистре и результат подсчета количества гласных букв. Задание: Класс инкапсулирует одномерный массив из элементов символьного типа. Создать индексатор, который предотвращает нарушение границы массива и возвращает символ лишь в верхнем регистре. Создать свойство, доступное для чтения закрытого элемента - данного, что содержит количество гласных букв в массиве. Результат выполнение вывести на экран. В Program.cs реализовать сам вывод на экран.
Ошибки:
Цитата | c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:"obj\Debug\laba index.exe" /target:exe Program.cs Properties\AssemblyInfo.cs Row.cs D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(13,33): error CS0236: A field initializer cannot reference the non-static field, method, or property 'laba_index.Row.charray' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(12,16): (Related location) D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(26,31): error CS0029: Cannot implicitly convert type 'bool' to 'int' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(31,31): error CS0029: Cannot implicitly convert type 'bool' to 'int' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(32,28): error CS0031: Constant value '0' cannot be converted to a 'char' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(39,21): error CS0200: Property or indexer 'string.this[int]' cannot be assigned to -- it is read only D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(40,31): error CS0029: Cannot implicitly convert type 'bool' to 'int' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(44,31): error CS0029: Cannot implicitly convert type 'bool' to 'int' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(64,29): error CS0151: A value of an integral type expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(66,30): error CS0029: Cannot implicitly convert type 'char' to 'method group' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(67,30): error CS0029: Cannot implicitly convert type 'char' to 'method group' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Row.cs(70,24): error CS0266: Cannot implicitly convert type 'int' to 'char'. An explicit conversion exists (are you missing a cast?) D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,33): error CS1525: Invalid expression term 'char' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,34): error CS0443: Syntax error; value expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,36): error CS1026: ) expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,46): error CS1525: Invalid expression term '{' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,47): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,51): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,51): error CS1525: Invalid expression term ',' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,53): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,57): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,57): error CS1525: Invalid expression term ',' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,59): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,62): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,62): error CS1525: Invalid expression term ',' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,64): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,67): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,67): error CS1525: Invalid expression term ',' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,69): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,72): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,72): error CS1525: Invalid expression term ',' D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,74): error CS1002: ; expected D:\Мои документы\Visual Studio 2008\Projects\laba index\laba index\Program.cs(12,77): error CS1002: ; expected
|
Код программы:
Код | //Row.cs using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace laba_index { class Row { public int Length; public int errflag; char[] charray; string str = new string(charray);
public Row(string str) { this.str = str; }
public char this[int i] { get { if (ok(i)) { errflag = false; return Char.ToUpper(str[i]); } else { errflag = true; return 0; } } set { if (ok(i)) { str[i] = value; errflag = false; } else { errflag = true; } } } private bool ok(int i)//метод возвращает значение true, если индекс в пределах границ { if (i >= 0 & i < Length) return true; return false; }
public char VowelsCount { get { int count = 0; foreach (char c in charray) { switch (char.ToUpper) { case 'A': count++; break; case 'E': count++; break; } } return count; } } } }
//Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace laba_index { class Program { static void Main(string[] args) { Row r = new Row(char[] charray = {'A' , 'b' , 'E', 'r', 't', 'y'}; } } }
|
|