Computer Science(9608) notes and Resources
IF YOU NEED QUESTION FILE OF THIS PRE-RELEASE MATERIAL THEN CLICK HERE
IF YOU NEED QUESTION FILE OF THIS PRE-RELEASE MATERIAL THEN CLICK HERE
Task 2 Solution:
Module Module1
Sub Main()
Dim word, temp As String
Dim length As Integer
Dim counter As Integer
Dim flag As Boolean = False
Dim word2() As String
temp = ""
Console.Write("enter string: ")
word = Console.ReadLine()
length = Len(word)
If Mid(word, 1, 2) = "**" And Mid(word, length - 1, 2) = "**" Then
If Mid(word, 3, 1) = "#" Or Mid(word, length - 2, 1) = "#" Then
Console.WriteLine("invalid")
Else
For counter = 1 To length - 1
If Mid(word, counter, 2) = "##" Then
flag = True
End If
Next
If flag = "true" Then
Console.WriteLine("invalid")
Else
Console.WriteLine("valid")
Console.WriteLine("___________________________")
For counter = 1 To length
If Mid(word, counter, 1) <> "*" Then
temp = temp + Mid(word, counter, 1)
End If
Next
word2 = temp.Split("#")
For counter = 0 To word2.Length() - 1
Console.WriteLine(word2(counter))
Next
End If
End If
Else
Console.WriteLine("invalid")
End If
Console.ReadLine()
End Sub
End Module
Task 3.1 Solution:
Program 1
Module Module1
Sub Main()
Dim carReg, dateSold As String
Dim numofRep, counter1, counter2 As Integer
Dim flag1 As Boolean = False
Dim flag2 As Boolean = True
Dim dateSplit() As String
Dim finput As New IO.StreamWriter("CARSALES1.TXT", True)
For counter2 = 1 To 5
Console.Write("Enter car registration code: ")
Do
flag1 = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag1 = False
End If
Next
If flag1 = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code: ")
Else
finput.writeline(carReg)
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter date sold ( DD/MM/YYYY ) : ")
Do
flag1 = True
flag2 = True
dateSold = Console.ReadLine()
If Len(dateSold) >= 8 And Len(dateSold) <= 10 Then
dateSplit = dateSold.Split("/")
For counter1 = 1 To Len(dateSold)
If UCase(Mid(dateSold, counter1, 1)) >= "A" And UCase(Mid(dateSold, counter1, 1)) <= "Z" Then
flag2 = False
End If
Next
If flag2 = False Then
flag1 = False
Else
If Not (Val(dateSplit(0)) >= 1 And Val(dateSplit(0)) <= 31) Then
flag1 = False
End If
If Not (Val(dateSplit(1)) >= 1 And Val(dateSplit(1)) <= 12) Then
flag1 = False
End If
If Not (Val(dateSplit(2)) >= 1 And Val(dateSplit(2)) <= 9999) Then
flag1 = False
End If
End If
If flag1 = False Then
Console.Clear()
Console.Write("Invalid. enter valid date ( DD/MM/YYYY ) : ")
Else
finput.WriteLine(dateSold)
flag1 = True
End If
Else
Console.Clear()
Console.Write("enter valid date ( DD/MM/YYYY ) : ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter number of repair visit: ")
numofRep = Console.ReadLine()
finput.WriteLine(numofRep)
Next
finput.Close()
Console.ReadLine()
End Sub
End Module
Program 2
Module Module1
Sub Main()
Dim lineoftext As String
Dim finput As New IO.StreamRead("CARSALES1.TXT", True)
Do
lineoftext = finput.ReadLine()
Console.WriteLine(lineoftext)
Loop Until finput.EndOfStream
finput.Close()
Console.ReadLine()
End Sub
End Module
Program 3
Module Module1
Sub Main()
Dim lineoftext As String
Dim carReg As String
Dim counter As Integer
Dim flag As Boolean = False
Dim finput As New IO.StreamReader("C:\Users\amish\Desktop\CARSALES1.TXT", True)
Console.Write("Enter car registration code to search: ")
Do
flag = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag = False
End If
Next
If flag = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code again to search: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code again to search:")
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code again to search: ")
flag = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code again to search: ")
flag = False
End If
Loop Until flag = True
Dim count As Integer = 1
Do
lineoftext = finput.ReadLine()
If lineoftext = carReg Then
Console.WriteLine(lineoftext)
flag = False
For counter = count To count + 1
lineoftext = finput.ReadLine()
Console.WriteLine(lineoftext)
Next
End If
count = count + 1
Loop Until finput.EndOfStream
If Not (flag = False) Then
Console.WriteLine("REGISTRATION NOT FOUND")
End If
finput.Close()
Console.ReadLine()
End Sub
End Module
Program 4
Module Module1
Sub Main()
Dim numofRep As Integer
Dim lineoftext, carReg As String
Dim temp As Integer = 1
Dim flag As Boolean = True
Dim fhandle As New IO.StreamReader("C:\Users\amish\Desktop\CARSALES1.TXT")
carReg = ""
Console.WriteLine("Enter number of repairs visits: ")
numofRep = Console.ReadLine()
Do
lineoftext = fhandle.ReadLine()
If temp = 1 Or temp = 4 Or temp = 7 Or temp = 10 Or temp = 13 Then
carReg = lineoftext
End If
If temp Mod 3 = 0 Then
If numofRep <= Val(lineoftext) Then
Console.WriteLine(carReg)
flag = True
Else
flag = False
End If
End If
temp = temp + 1
Loop Until fhandle.EndOfStream()
If flag = False Then
Console.WriteLine("NO CARS FOUND")
End If
fhandle.Close()
Console.ReadLine()
End Sub
End Module
Program 5
Module Module1
Sub Main()
Dim carReg, dateSold As String
Dim numofRep, counter1, counter2 As Integer
Dim flag1 As Boolean = False
Dim flag2 As Boolean = True
Dim dateSplit() As String
Dim finput As New IO.StreamWriter("C:\Users\amish\Desktop\CARSALES1.TXT", True)
Console.Write("Enter car registration code: ")
Do
flag1 = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag1 = False
End If
Next
If flag1 = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code: ")
Else
finput.writeline(carReg)
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter date sold ( DD/MM/YYYY ) : ")
Do
flag1 = True
flag2 = True
dateSold = Console.ReadLine()
If Len(dateSold) >= 8 And Len(dateSold) <= 10 Then
dateSplit = dateSold.Split("/")
For counter1 = 1 To Len(dateSold)
If UCase(Mid(dateSold, counter1, 1)) >= "A" And UCase(Mid(dateSold, counter1, 1)) <= "Z" Then
flag2 = False
End If
Next
If flag2 = False Then
flag1 = False
Else
If Not (Val(dateSplit(0)) >= 1 And Val(dateSplit(0)) <= 31) Then
flag1 = False
End If
If Not (Val(dateSplit(1)) >= 1 And Val(dateSplit(1)) <= 12) Then
flag1 = False
End If
If Not (Val(dateSplit(2)) >= 1 And Val(dateSplit(2)) <= 9999) Then
flag1 = False
End If
End If
If flag1 = False Then
Console.Clear()
Console.Write("Invalid. enter valid date ( DD/MM/YYYY ) : ")
Else
finput.WriteLine(dateSold)
flag1 = True
End If
Else
Console.Clear()
Console.Write("enter valid date ( DD/MM/YYYY ) : ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter number of repair visit: ")
numofRep = Console.ReadLine()
finput.WriteLine(numofRep)
finput.Close()
Console.ReadLine()
End Sub
End Module
Program 6
Module Module1
Sub Main()
Dim choice As Integer
Do
menu()
Console.Write("Ente choice <1...5> : ")
choice = Console.ReadLine()
Select Case choice
Case 1
Console.Clear()
Console.WriteLine(" Create care sales file ")
Console.WriteLine("_____________________________")
Console.WriteLine()
Console.WriteLine()
Call create()
Case 2
Console.Clear()
Console.WriteLine(" Search by registration ")
Console.WriteLine("_____________________________")
Console.WriteLine()
Console.WriteLine()
Call search()
Case 3
Console.Clear()
Console.WriteLine(" Repairs report ")
Console.WriteLine("_____________________________")
Console.WriteLine()
Console.WriteLine()
Call repair()
Case 4
Console.Clear()
Console.WriteLine(" Add new car sales ")
Console.WriteLine("_____________________________")
Console.WriteLine()
Console.WriteLine()
Call add()
End Select
Console.Clear()
Loop Until choice = 5
End Sub
Sub menu()
Console.WriteLine("1. Create a file")
Console.WriteLine("2. Search by registration")
Console.WriteLine("3. Repairs report")
Console.WriteLine("4. Add new car sale")
Console.WriteLine("5. Exit")
End Sub
Sub create()
Dim carReg, dateSold As String
Dim numofRep, counter1, counter2 As Integer
Dim flag1 As Boolean = False
Dim flag2 As Boolean = True
Dim dateSplit() As String
Dim finput As New IO.StreamWriter("CARSALES1.TXT")
Console.Write("Enter car registration code: ")
Do
flag1 = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag1 = False
End If
Next
If flag1 = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code: ")
Else
finput.WriteLine(carReg)
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter date sold ( DD/MM/YYYY ) : ")
Do
flag1 = True
flag2 = True
dateSold = Console.ReadLine()
If Len(dateSold) >= 8 And Len(dateSold) <= 10 Then
dateSplit = dateSold.Split("/")
For counter1 = 1 To Len(dateSold)
If UCase(Mid(dateSold, counter1, 1)) >= "A" And UCase(Mid(dateSold, counter1, 1)) <= "Z" Then
flag2 = False
End If
Next
If flag2 = False Then
flag1 = False
Else
If Not (Val(dateSplit(0)) >= 1 And Val(dateSplit(0)) <= 31) Then
flag1 = False
End If
If Not (Val(dateSplit(1)) >= 1 And Val(dateSplit(1)) <= 12) Then
flag1 = False
End If
If Not (Val(dateSplit(2)) >= 1 And Val(dateSplit(2)) <= 9999) Then
flag1 = False
End If
End If
If flag1 = False Then
Console.Clear()
Console.Write("Invalid. enter valid date ( DD/MM/YYYY ) : ")
Else
finput.WriteLine(dateSold)
flag1 = True
End If
Else
Console.Clear()
Console.Write("enter valid date ( DD/MM/YYYY ) : ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter number of repair visit: ")
numofRep = Console.ReadLine()
finput.WriteLine(numofRep)
Console.WriteLine()
Console.WriteLine()
finput.Close()
End Sub
Sub search()
Dim lineoftext As String
Dim carReg As String
Dim counter As Integer
Dim flag As Boolean = False
Dim finput As New IO.StreamReader("CARSALES1.TXT", True)
Console.Write("Enter car registration code to search: ")
Do
flag = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag = False
End If
Next
If flag = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code again to search: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code again to search:")
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code again to search: ")
flag = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code again to search: ")
flag = False
End If
Loop Until flag = True
Dim count As Integer = 1
Do
lineoftext = finput.ReadLine()
If lineoftext = carReg Then
Console.WriteLine(lineoftext)
flag = False
For counter = count To count + 1
lineoftext = finput.ReadLine()
Console.WriteLine(lineoftext)
Next
End If
count = count + 1
Loop Until finput.EndOfStream
If Not (flag = False) Then
Console.WriteLine("REGISTRATION NOT FOUND")
End If
finput.Close()
Console.ReadLine()
End Sub
Sub repair()
Dim numofRep As Integer
Dim lineoftext, carReg As String
Dim temp As Integer = 1
Dim flag As Boolean = True
Dim fhandle As New IO.StreamReader("CARSALES1.TXT")
carReg = ""
Console.Write("Enter number of repairs visits: ")
numofRep = Console.ReadLine()
Do
lineoftext = fhandle.ReadLine()
If temp = 1 Or temp = 4 Or temp = 7 Or temp = 10 Or temp = 13 Then
carReg = lineoftext
End If
If temp Mod 3 = 0 Then
If numofRep <= Val(lineoftext) Then
Console.WriteLine(carReg)
flag = True
Else
flag = False
End If
End If
temp = temp + 1
Loop Until fhandle.EndOfStream()
If flag = False Then
Console.WriteLine("NO CARS FOUND")
End If
fhandle.Close()
Console.ReadLine()
End Sub
Sub add()
Dim carReg, dateSold As String
Dim numofRep, counter1, counter2 As Integer
Dim flag1 As Boolean = False
Dim flag2 As Boolean = True
Dim dateSplit() As String
Dim finput As New IO.StreamWriter("CARSALES1.TXT", True)
Console.Write("Enter car registration code: ")
Do
flag1 = True
carReg = Console.ReadLine()
If Len(carReg) = 5 Then
If UCase(Mid(carReg, 1, 1)) >= "A" And UCase(Mid(carReg, 1, 1)) <= "Z" Then
For counter1 = 2 To 5
If UCase(Mid(carReg, counter1, 1)) >= "A" And UCase(Mid(carReg, counter1, 1)) <= "Z" Then
flag1 = False
End If
Next
If flag1 = False Then
Console.Clear()
Console.Write("invalid code. enter valid registration code: ")
Else
If Not (Val(Mid(carReg, 2, 4)) >= 1 And Val(Mid(carReg, 2, 4)) <= 9999) Then
Console.Clear()
Console.Write("invalid code. enter registration code: ")
Else
finput.WriteLine(carReg)
End If
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Else
Console.Clear()
Console.Write("invalid code. enter registration code: ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter date sold ( DD/MM/YYYY ) : ")
Do
flag1 = True
flag2 = True
dateSold = Console.ReadLine()
If Len(dateSold) >= 8 And Len(dateSold) <= 10 Then
dateSplit = dateSold.Split("/")
For counter1 = 1 To Len(dateSold)
If UCase(Mid(dateSold, counter1, 1)) >= "A" And UCase(Mid(dateSold, counter1, 1)) <= "Z" Then
flag2 = False
End If
Next
If flag2 = False Then
flag1 = False
Else
If Not (Val(dateSplit(0)) >= 1 And Val(dateSplit(0)) <= 31) Then
flag1 = False
End If
If Not (Val(dateSplit(1)) >= 1 And Val(dateSplit(1)) <= 12) Then
flag1 = False
End If
If Not (Val(dateSplit(2)) >= 1 And Val(dateSplit(2)) <= 9999) Then
flag1 = False
End If
End If
If flag1 = False Then
Console.Clear()
Console.Write("Invalid. enter valid date ( DD/MM/YYYY ) : ")
Else
finput.WriteLine(dateSold)
flag1 = True
End If
Else
Console.Clear()
Console.Write("enter valid date ( DD/MM/YYYY ) : ")
flag1 = False
End If
Loop Until flag1 = True
Console.Write("Enter number of repair visit: ")
numofRep = Console.ReadLine()
finput.WriteLine(numofRep)
finput.Close()
End Sub
End Module
- CIE A-LEVEL COMPUTER SCIENCE ( 9608 )
No comments:
Post a Comment
Comments here....