Sunday, October 30, 2016

2. 9608 pre-release material 2016 ( October/November ) #22

Computer Science(9608) notes and Resources









IF YOU NEED QUESTION FILE OF THIS PRE-RELEASE MATERIAL THEN CLICK HERE


Task 3.2 Solution







Program 7


Module Module1

    Sub Main()
        Dim month, year As Integer
        Dim datePart, lineoftext As String
        Dim flag As Boolean = True
        Dim fhandle As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")
        Console.Write("Enter month number: ")
        month = Console.ReadLine()
        Console.Write("Enter year: ")
        year = Console.ReadLine()
        Do
            lineoftext = fhandle.ReadLine()
            datePart = Mid(lineoftext, 7, 10)

            If Not (Val(Mid(datePart, 4, 2)) = month) Then
                flag = False
            End If

            If Not (Val(Right(datePart, 4)) = year) Then
                flag = False
            End If
            If flag = True Then
                Console.WriteLine(lineoftext)
            Else
                flag = True
            End If
        Loop Until fhandle.EndOfStream()


        Console.ReadLine()
    End Sub

End Module










Program 8


Module Module1

    Sub Main()
        Dim linecount As Integer
        Dim lineoftext as string
        Dim SearchcarReg As String
        SearchcarReg = Console.ReadLine()


        Dim fhandle1 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")
        Do
            lineoftext=fhandle.readline()
            linecount = linecount + 1
        Loop Until fhandle1.EndOfStream
        fhandle1.Close()

        Dim lines(linecount - 1) As String
        Dim newNumrepair As Integer
        Dim counter As Integer = 0
        Dim line, carReg As String
        Dim section() As String

        Dim fhandle2 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")
        Do
            lines(counter) = fhandle2.ReadLine()
            counter = counter + 1
        Loop Until fhandle2.EndOfStream
        fhandle2.Close()

        For counter = 0 To lines.Length() - 1
            line = lines(counter)
            section = line.Split(" "c)
            If section.Length() > 2 Then
                carReg = section(0)
                If carReg = SearchcarReg Then
                    newNumrepair = section(2) + 1
                    lines(counter) = String.Format("{0} {1} {2}", section(0), section(1), newNumrepair)
                    IO.File.WriteAllLines("C:\Users\amish\Desktop\CARSALES2.txt", lines)
                End If
            End If
        Next

        Console.ReadLine()
    End Sub

End Module











Program 9



Module Module1

    Sub Main()

        Dim linecount As Integer = 0
        Dim lineoftext As String
        Dim SearchcarReg As String
        SearchcarReg = Console.ReadLine()

        Dim objreader1 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")

        Do
            lineoftext = objreader1.ReadLine()
            linecount = linecount + 1
        Loop Until objreader1.EndOfStream

        objreader1.Close()


        Dim lines(linecount - 1) As String
        Dim newNumrepair As Integer
        Dim counter As Integer = 0
        Dim line, carReg As String
        Dim section() As String

        Dim objreader2 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")

        Do
            lines(counter) = objreader2.ReadLine()
            counter = counter + 1
        Loop Until objreader2.EndOfStream
        objreader2.Close()


        For counter = 0 To lines.Length() - 1
            line = lines(counter)
            section = line.Split(" ")
                carReg = section(0)
                If carReg = SearchcarReg Then
                    newNumrepair = Val(section(2)) + 1
                    lines(counter) = String.Format("{0} {1} {2}", section(0), section(1), newNumrepair)
                    IO.File.WriteAllLines("C:\Users\amish\Desktop\CARSALES2.txt", lines)
                End If
        Next

        Console.ReadLine()
    End Sub

End Module










 Program 10



Module Module1

    Sub Main()

        Dim linecount As Integer = 0
        Dim lineoftext As String
        Dim currentDate As String
        Dim totalcurrentdays As Integer
        Console.Write("Enter todays date ( DD/MM/YY ): ")
        currentDate = Console.ReadLine()
        totalcurrentdays = Val(Left(currentDate, 2)) + Val(Mid(currentDate, 34, 2)) * 30 + Val(Right(currentDate, 2)) * 365
        Dim objreader1 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")

        Do
            lineoftext = objreader1.ReadLine()
            linecount = linecount + 1
        Loop Until objreader1.EndOfStream

        objreader1.Close()


        Dim lines(linecount - 1) As String
        Dim counter As Integer = 0
        Dim objreader2 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")

        Do
            lines(counter) = objreader2.ReadLine()
            counter = counter + 1
        Loop Until objreader2.EndOfStream
        objreader2.Close()

        Dim line, datesection As String
        Dim section() As String
        Dim totaldays As Integer
        For counter = 0 To lines.Length() - 1
            line = lines(counter)
            section = line.Split(" ")
            If section.Length > 2 Then
                datesection = section(1)
                totaldays = Val(Left(datesection, 2)) + Val(Mid(datesection, 34, 2)) * 30 + Val(Right(datesection, 2)) * 365
                If (totalcurrentdays - totaldays) > (2 * 365) Then
                    lines(counter) = String.Format("{0} {1} {2}", "", "", "")
                    IO.File.WriteAllLines("C:\Users\amish\Desktop\CARSALES2.txt", lines)
                End If
            End If
        Next

        Dim temp(linecount - 1) As String
        counter = 0
        Dim objreader3 As New System.IO.StreamReader("C:\Users\amish\Desktop\CARSALES2.txt")

        Do
            lineoftext = objreader3.ReadLine()
            temp(counter) = lineoftext
            counter = counter + 1

        Loop Until objreader3.EndOfStream

        objreader3.Close()
        Dim pointer As Integer
        Dim objwriter1 As New System.IO.StreamWriter("C:\Users\amish\Desktop\CARSALES2.txt")
        For counter = 0 To linecount - 1
            If Len(temp(counter)) = 18 Then
                objwriter1.WriteLine(temp(counter))
                pointer = counter
            End If
        Next
        objwriter1.Close()

        Dim objwriter2 As New System.IO.StreamWriter("C:\Users\amish\Desktop\CARSALES2.txt", True)
        For counter = pointer + 1 To linecount - 1
            objwriter2.WriteLine(temp(counter))
        Next
        objwriter2.Close()

        Console.ReadLine()
    End Sub

End Module




                                                           - CIE A-LEVEL COMPUTER SCIENCE (  9608 )

No comments:

Post a Comment

Comments here....