在班级项目完全卡住,视觉基本介绍课程中途完成

时间:2013-12-11 19:06:52

标签: visual-studio-2010

老师在这堂课上非常强硬和无益。我已经尽力跟上但是落后了并且需要在课堂作业中取得好成绩才能有人帮助我吗?我问了很多问题,并且使用了导师但是我是一个可怕的程序员。只需要传递这个类,因为我在网络中,但它是必需的。正如我们所说的那样工作流程图和psuedo,如果有人甚至可以让我开始这么简单的程序,我只是搞砸了我的基本原理。

构建一个控制台程序,用于请求用户的生日,并从他们出生的那一年输出最畅销的专辑。最畅销的专辑列表如下。

输入文件:final.txt

1956       Calypso               

1957       My Fair Lady      

1958       My Fair Lady      

1959       Music from Peter Gunn               

1960       The Sound of Music       

1961       Camelot              

1962       West Side Story               

1963       West Side Story               

1964       Hello, Dolly!       

1965       Mary Poppins   

1966       Whipped Cream & Other Delights           

1967       More of The Monkees 

1968       Are You Experienced?   

1969       In-A-Gadda-Da-Vida      

1970       Bridge Over Troubled Water       

1971       Jesus Christ Superstar   

1972       Harvest               

1973       The World Is a Ghetto   

1974       Goodbye Yellow Brick Road        

1975       Elton John's Greatest Hits           

1976       Frampton Comes Alive 

1977       Rumours             
 1978       Saturday Night Fever    

1979       52nd Street                       

1980       The Wall              

1981       Hi Infidelity        

1982       Asia       

1983       Thriller 

1984       Thriller 

1985       Born in the U.S.A.           

1986       Whitney Houston           

1987       Slippery When Wet        

1988       Faith     

1989       Don't Be Cruel  

1990       Janet Jackson's Rhythm Nation

1991       Ropin' The Wind              

1992       Some Gave All  

1993       The Bodyguard

1994       The Lion King    

1995       Cracked Rear View         

1996       Jagged Little Pill               

1997       Spice    

1998       Titanic  

1999       Millennium

应使用以下提示。

请输入您的出生日期(MM-DD-YY)“结束”完成:

程序完成后,需要写入输出文件。该文件应包含:执行的搜索次数和搜索年份列表。

压缩项目文件,流程图,伪代码和输出并上传

这是我做了多远。

Sub Main()

    Try
        Dim albums As List(Of String) = New List(Of String)()
        Dim response As String = String.Empty
        Dim searches As List(Of String) = New List(Of String)()
        Dim year As Integer = 0

        Using reader As New System.IO.StreamReader("E:\IntroProgramming\FinalProject\Final.txt")
            While Not reader.EndOfStream
                albums.Add(reader.ReadLine())
            End While
        End Using

        While response.ToUpper() <> "END"
            Console.Write("Please enter your birthdate (MM-DD-YY) ""End"" to finish: ")
            response = Console.ReadLine()
            If (Integer.TryParse(response.Substring(response.Length - 2), year)) Then
                If (year >= 56 And year <= 99) Then
                    searches.Add("19" & response.Substring(response.Length - 2))
                    Console.WriteLine("The best selling album for the year 19" & year.ToString() & " was " & albums(year - 56))
                Else
                    Console.WriteLine("Invalid year! Please try again")
                End If
            End If
        End While

        Using writer As New System.IO.StreamWriter("finaloutput.txt", False)
            writer.WriteLine("There were a total of " & searches.Count.ToString() & " valid searches")
            For Each s As String In searches
                writer.WriteLine(s)
                Console.ReadLine()
            Next



        End Using

    Catch ex As Exception
        Console.WriteLine(ex.ToString())
        Console.ReadLine()
    End Try
End Sub

结束模块

一切正常,除非您输入结束时完成它没有输出搜索次数和搜索年份列表。

2 个答案:

答案 0 :(得分:1)

Sub Main()
    Try
        Dim albums As List(Of String) = New List(Of String)()
        Dim response As String = String.Empty
        Dim searches As List(Of String) = New List(Of String)()
        Dim year As Integer = 0

        Using reader As New System.IO.StreamReader("final.txt")
            While Not reader.EndOfStream
                albums.Add(reader.ReadLine())
            End While
        End Using

        While response.ToUpper() <> "END"
            Console.Write("Please enter your birthdate (MM-DD-YY) ""End"" to finish: ")
            response = Console.ReadLine()
            If (Integer.TryParse(response.Substring(response.Length - 2), year)) Then
                If (year >= 56 And year <= 99) Then
                    searches.Add("19" & response.Substring(response.Length - 2))
                    Console.WriteLine("The best selling album for the year 19" & year.ToString() & " was " & albums(year - 56))
                Else
                    Console.WriteLine("Invalid year! Please try again")
                End If
            End If
        End While

        Using writer As New System.IO.StreamWriter("finaloutput.txt", False)
            writer.WriteLine("There were a total of " & searches.Count.ToString() & " valid searches")
            For Each s As String In searches
                writer.WriteLine(s)
            Next
        End Using

    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    End Try
End Sub

答案 1 :(得分:0)

我真的不太了解VB(C#/ C ++对我来说),但是帮助你这里是一个基本的小程序,可以帮助你入门。我确信这不是最有效的方式,因为通过在互联网上搜索如何做事,每一点都被抛到了一起。但它会让你朝着正确的方向前进。如果你需要写一个文件,你可以查找StreamWriter,那里会有很多东西给你,不能为你做的全部:)

Sub Main()
    'this is the first part for you
    Dim szBirthDate As String
    Console.WriteLine("Please enter your birthdate (MM-DD-YY) ""Enter""to finish:")
    szBirthDate = Console.ReadLine()
    Dim szInputtedDateArray As Array
    Dim szYear As String
    szInputtedDateArray = szBirthDate.Split("-")
    szYear = "19" & szInputtedDateArray(2).ToString()

    'at this point the szYear variable has the year format from your final.txt file

    'now read the file until you find your year
    Try
        ' Create an instance of StreamReader to read from a file. 
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:\appdev\final.txt")
        Dim line As String
        Dim cnt As Integer
        cnt = 0

        ' Read the file until you find the year you need or the end of the file is reached. 
        Do
            cnt += 1
            line = sr.ReadLine()
            line = line.Trim()
            If line.IndexOf(szYear, 0, 4) > -1 Then
                Console.WriteLine("In " + szYear.ToString() + " the best seller was " + line.Substring(5))
                Console.WriteLine(cnt.ToString() + " items searched")
                Exit Do
            End If
        Loop Until line Is Nothing
        sr.Close()
    Catch E As Exception
        ' Let the user know what went wrong.
        Console.WriteLine("The file could not be read:")
        Console.WriteLine(E.Message)
    End Try
End Sub

正如我上面所说的,我不是一个VB人,所以这可能很粗糙,但它有效,熟悉它,你记得互联网是你的朋友。