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 )

Friday, October 28, 2016

3. Programming practice for 9608 ( paper 2)

Computer Science(9608) notes and Resources

           



                                             



Module Module1
  
    Sub main()

        Dim text, tempText, temp As String
        Dim count, counter As Integer

        Console.Write("Enter any word: ")
        text = Console.ReadLine() 
        text = LCASE(text)
               
        tempText = ""

        Do
            temp = Mid(text, 1, 1)
            For counter = 1 To Len(text)
                If temp = Mid(text, counter, 1) Then
                    count = count + 1
                Else
                    tempText = tempText + Mid(text, counter, 1)
                End If
            Next
            Console.WriteLine(temp & " = " & count)
            count = 0
            text = tempText
            tempText = ""

        Loop Until Len(text) = 0
  
      Console.ReadLine()

    End Sub


 End Module

                                                                              - CIE A-LEVEL COMPUTER SCIENCE (  9608 )

Monday, October 24, 2016

2. Programming practice for 9608 ( paper 2)

Computer Science(9608) notes and Resources



















Module Module1

    Sub Main()

        Dim number, counter As Integer         'storing 10 number in a file
        Dim arnumber(10) As Integer
        Dim fwrite As New IO.StreamWriter("d:\number.txt", True)
        Console.WriteLine("Enter any  numbers: ")
        For counter = 1 To 10
            number = Console.ReadLine()
                fwrite.WriteLine(number)
        Next
        fwrite.Close()


        Dim lineoftext As String          'copying number from file to an integer array
        Dim fread As New IO.StreamReader("d:\number.txt")
        For counter = 1 To 10
            lineoftext = fread.ReadLine()
            arnumber(counter) = Val(lineoftext)
        Next
        fread.Close()



        Dim temp, num As Integer                      'bubble sorting
        Dim counter1 As Integer
        num = 9
        For counter = 1 To 9
            For counter1 = 1 To num
                If arnumber(counter1) > arnumber(counter1 + 1) Then
                    temp = arnumber(counter1)
                    arnumber(counter1) = arnumber(counter1 + 1)
                    arnumber(counter1 + 1) = temp
                End If
            Next
            num = num - 1
        Next

        Dim total As Integer = 0                                            'largest value
        Console.WriteLine("The largest  number is " & arnumber(10))
        For counter = 1 To 10
            total = total + arnumber(counter)
        Next

        Console.WriteLine("The mean value is " & total / 10)                   'mean value


        Dim positionformedian As Decimal                              'median value
        Dim medianvalue As Decimal
        Dim tempnum As Integer
        positionformedian = (10 + 1) / 2
        tempnum = Math.Truncate(positionformedian)
        medianvalue = ((arnumber(tempnum) + arnumber(tempnum + 1)) * (positionformedian - tempnum))
        Console.WriteLine("the median value is " & medianvalue)

        Dim flag As Boolean = True     'mode value
        Dim count As Integer = 0
        temp = arnumber(1)
        For counter = 1 To 10
            If flag = False Then
                count = 1
                temp = arnumber(counter)
                flag = True
            End If
            If temp = arnumber(counter) Then
                count = count + 1
            Else
                flag = False

            End If
        Next
        Console.WriteLine("the mode value is " & temp & " and its frequency is " & count)

        Console.ReadLine()
    End Sub

End Module
      

                                          - CIE A-LEVEL COMPUTER SCIENCE (  9608 )