2012-05-08 6 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, true가 아님 – Habib

답변

1

다음은 아마도 그것을 수행하는 대략적인 방법 일 것입니다. 먼저 클래스 수준에서 StudentNameStudentMarks을 정의하십시오.

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(); 

    } 
관련 문제