2012-05-08 5 views
0

Мне нужна помощь в получении этого кода для отображения массивов, но структура кода должна оставаться неизменной. я создал два массива, и мне нужно, чтобы отобразить как из отдельных методов, и я также нужно искать и показывать следы студентов вошли это мой первый код, который я сделал, и действительно нужна помощь, спасибоне может быть отображен

class Program 
{ 
    static void Main() 
    { 
     collectStudentDetails(); 
     promptForStudentQuery(); 
     printStudentsmarks(); 
     Console.ReadLine(); 
    } 

    public static void collectStudentDetails() 
    { 
     Console.WriteLine("Please Specifiy How Many Student Details You Wish To  Enter"); 
     Console.WriteLine(""); 
     int n = SafeReadInteger(0); 
     int[] StudentMarks = new int[n]; 
     string[] StudentNames = new string[n]; 

     for (int i = 0; i < StudentNames.Length; i++) 
     { 
      Console.WriteLine("Enter Name for student {0}", i + 1); 
      StudentNames[i] = SafeReadString(null); 
      Console.WriteLine("Enter Mark for Student {0}: ", i + 1); 
      StudentMarks[i] = SafeReadInteger(0); 
     } 
    } 

    static void findStudentmark() 
    { 
     bool foundStudent = false; 
     Console.WriteLine("Please Enter The Students Name To Find Their Marks"); 
     Console.WriteLine("Please Press Enter To Continue"); 
     Console.ReadLine(); 
    } 

    static void printStudentsmarks() 
    { 
     Console.WriteLine("\nStudent Mark List"); 
     Console.WriteLine("Please Press Enter To Continue"); 
     Console.ReadLine(); 
     promptForStudentQuery(); 
    } 

    static bool promptForStudentQuery() 
    { 
     bool promptAgain = true; 
     Console.WriteLine(); 
     Console.WriteLine(" 1. find a student's mark "); 
     Console.WriteLine(" 2. print all student marks"); 
     Console.WriteLine(" 3. exit "); 
     Console.WriteLine(); 
     int choice = SafeReadInteger(0); 
     if (choice == 1) 
     { 
      findStudentmark(); 
     } 
     else if (choice == 2) 
     { 
      printStudentsmarks(); 
     } 
     else if (choice == 3) 
     { 
      Environment.Exit(0); 
     } 
     else if (choice == 0) 
     { 
      Console.WriteLine("you entered an invalid option try again"); 
     } 
     return promptAgain; 
    } 

    public static int SafeReadInteger(int defaultVal) 
    { 
     try 
     { 
      return int.Parse(System.Console.ReadLine()); 
     } 
     catch 
     { 
      return defaultVal; 
     } 
    } 

    public static string SafeReadString(string defaultVal) 
    { 
     string temp = ""; 
     temp = Console.ReadLine(); 
     while (temp == "") 
     { 
      Console.WriteLine("You have entered nothing. Please enter a correct value."); 
      temp = Console.ReadLine(); 
     } 
     return temp; 
    } 

    static void DisplayArray(int[] inputarray) 
    { 
     foreach (int x in inputarray) 
     { 
      Console.Write(" {0} ", x); 
     } 
     Console.WriteLine(""); 
    } 

    static void DisplayArray2(string[] inputarray) 
    { 
     foreach (string x in inputarray) 
     { 
      Console.Write(" {0} ", x); 
     } 
     Console.WriteLine(""); 
    } 
} 
+0

Вы действительно думаете, 6 страниц кода является ** ** минимум мы должны увидеть, чтобы помочь вам? – Snowbear

+0

извините за то, что так долго, и я не могу использовать список, который должен быть в этой структуре. – mitch

+0

@nadirs, thats not true – Habib

ответ

1

Ниже приведен пример грубого способа сделать это. Сначала определите StudentName и StudentMarks на уровне класса.

class Program 
{ 
    static int[] StudentMarks; 
    static string[] StudentNames; 
    static void Main() 
    { 

     collectStudentDetails(); 
     promptForStudentQuery(); 
     printStudentsmarks(); 
     Console.ReadLine(); 
    } 

Вам необходимо обновить метод printStudentsmarks() и findStudentmark() как:

static void findStudentmark() 
{ 
    Console.WriteLine("Please Enter The Students Name To Find Their Marks"); 
    Console.WriteLine("Please Press Enter To Continue"); 
    string stdName = Console.ReadLine(); 
    int i = 0; 
    for (i = 0; i < StudentNames.Length; i++) 
    { 
     if (string.Compare(stdName, StudentNames[i], true)==0) 
     { 
      break; 
     } 
    } 
    Console.WriteLine(StudentNames[i]); 
    Console.WriteLine(StudentMarks[i]); 
} 
    static void printStudentsmarks() 
    { 

     Console.WriteLine("\nStudent Mark List"); 

     for (int i = 0; i < StudentNames.Length; i++) 
     { 
      Console.Write("Name: "); 
      Console.WriteLine(StudentNames[i]); 
      Console.WriteLine("Marks: "); 
      Console.WriteLine(StudentMarks[i]); 
      Console.WriteLine("______________________________"); 
     } 

     Console.WriteLine("Please Press Enter To Continue"); 
     Console.ReadLine(); 
     promptForStudentQuery(); 

    } 
Смежные вопросы