Saturday, April 22, 2023

Multiple selections flowchart and Pascal Program

ICT Past Paper Questions and Answers

Question:

The following flow chart is drawn to calculate average marks (avg) and display the grades when marks (M1, M2, M3) of three subjects are given as input. The grades are decided according to the following table.

Average marks (avg) Grade
Greater than or equal to 80A
Less than 80 and greater than or equal to 65B
Less than 65 and greater than or equal to 50C
OtherwiseNo Grade


Multiple if in Pascal with flowchart

  • Fill the blank indicated by ? according to the given scenario.
  • Convert the flow chart to Pascal Program.


Answer:
1:


Multiple if flowchart and Pascal answer

2:
program Multipleif;
var
m1,m2,m3:integer;
avg:real;
begin
  writeln ('Enter three Marks');
  readln(m1);
  readln(m2);
  readln(m3);
  avg:=(m2+m3+m3)/3;
  if (avg>=80) then
  writeln('A')
  else
  if(avg>=65) then
  writeln('B')
  else
  if (avg>=50) then
  writeln('C')
  else
  writeln('No Grade')
end.

  

Tuesday, July 5, 2022

Exercises to Python GUI Programming

Tkinter - GUI Programming Python

Question 1


Write a Python GUI Program to find the Area of a Rectancle with the following features. Able to enter width and height of a rectangle by the users.

  • Proper Prompted Messages to user for the above input.
  • Button to calculate and display the area of the rectangle for the above input.
  • Font should be Helvetica and size 15

Answer - Sample Python GUI Program

from tkinter import *
from tkinter.font import *

def myclick():
    A=int(W.get())*int(H.get())
    label3.configure(text="Area of the Rectangle :" +str(A))

root = Tk(className='Python Examples - Find Area of a Rectangle')
myfont=Font(family='Helvetica', size=15, weight='bold' )

label1 =Label(text="Enter the Width of a Rectangle", width=40,font=myfont, fg='Red')
label2 = Label(text="Enter the Height of a Rectangle", width=40, font=myfont, fg='Red')
label3 = Label(text=" ", width=40, font=myfont, fg='Green')

W=Entry(font=myfont, width=4)
H=Entry(font=myfont, width=4)

button = Button(text = 'Click me', font=myfont,command = myclick)

label1.grid(row=0, column=0)
W.grid(row=0, column=1)
label2.grid(row=1, column=0)
H.grid(row=1, column=1)
button.grid(row=2, column=0,columnspan=2)
label3.grid(row=5,column=0)

root.geometry("600x500")

mainloop()

Sample Output Screen


Python GUI with Tkinter

Wednesday, February 23, 2022

RDBMS Past Paper Questions and Answers

Relational Database Management System Questions and Answer

Question 1
i) Convert the following ER diagram to table structure in a relational database. The attribute capacity may have values such as captain, vice captain, member etc.

RDBMS Past Paper Questions and Answers

Based on the table Structures obtained above answer the below questions.

ii) Write an SQL statement to get a list of sports that do not have captains.
iii) Write an SQL statement to obtain a list of students (StudentID and Name) who participate in any sport as a captain.


Answer

i)
Student(StudentID, Name)
Sport(SportID, Name)
StudentSport(StudentID, SportID, Year, Capacity)

ii)
Select distinct SportID from StudentSport where capacity <> "captain"

iii) Select Student.ID, Student.Name from Student, StudentSport where Student.StudentID=StudentSport.StudentID and StudentSport.Capacity="captain"


Question 2
The candidates who have been selected for university entrance should register for the given academic year with the university given to them. Candidate who do not register before the Last date announced by each university will lose their university entrance. Once a candidate registers with given university , the candidate becomes a registered student of that university. Registered students can apply for financial support. A student can get many financial support. These financial supports could be either full or partial. All registered students will receive a laptop. However, its ownership cannot be transferred to another student. The user requirements of the above system are listed below. A user shall be able to obtain.
i) a list of students registered for a given academic year with a given university.
ii) information (such as model, serial number, warranty period) about the laptops given to each student.
iii) list of students who applied for financial support.

Draw an entity Relationship(ER) diagram required to design a database to represent the above system description and to satisfy the user requirements. State all your assumptions clearly.

Answer

RDBMS ERD QUESTIONS ANSWERS



Tuesday, February 22, 2022

Combinational circuits Design Questions and Answers

ICT Questions and Answers

Question 1
A digital circuit takes four digits as an input, and produce 'X' as its output. If the decimal value represented by the four binary digit is a prime number. If it is prime output is 1 otherwise 0. Assume that all four binary digit represent positive decimal values.

i) Draw a truth table for the above problem.
ii) Write the Boolean expression in the sum of product form.
iii) Design a logic circuit for the Boolean expression, which is obtained above.
iv) Simplify the expression using Boolean algebra/ Karnaugh map.

Answer
i) Truth Table

ABCDX
00000
00010
00101
00111
01000
01011
01100
01111
10000
10010
10100
10111
11000
11011
11100
11110


ii) X= A'B'CD' + A'B'CD + A'BC'D + A'BCD + AB'CD + ABC'D

iii)
Combinational Circuit to detect prime numbers


iv)
Combinational Circuit Questions and Answers



Question 2
Consider the logic circuit shown here to answer the below questions.

Combinational Circuit Design ICT A/L

i) Write and simplify the Boolean expression for the above circuit using Boolean algebra . Show all the workings and algebraic rules used for the simplification.

ii) Construct the logic circuit using combination of only AND, OR and NOT gates for the simplified Boolean expression obtained above.

Answer
i)
ABC + A'BC + ABC'
BC(A+A') + ABC'
BC + ABC'
B(C+AC')
B(A+C)

ii)

Combinational Past Paper ICT Answer


Friday, January 14, 2022

Python Exercises for ICT Students

Question
Write a Python function to sum all elements in a list which is passed as parameter and return the sum value.

Answer
#function to sum list
def Lsum(L):
    s=0
    for i in L:
        s=s+i
    return s

#call the function
sales=[15000,20000,3000,12000,5000,8900]
print(Lsum(sales))

Question
The factorial of a positive integers n is defined as n x (n-1) x (n-2) x ......x 3 x 2 x1.
Write a python function to return the factorial value of a given integer.

Answer
#function to find factorial value to a given number
def fact(n):
    Fact=n
    while (n>1):
        n=n-1
        Fact=Fact*n        
    return Fact

#call the function
N=int(input("Enter a number?"))
print(fact(N))

Question
Write a Python program to transform the data from in.csv file content to out.csv file. Content of the in.csv file is given below. The out.csv file should have total value as additional data.
 
Peter,80,90
David,100,75
Black,50,60

 Answer
f1=open("in.txt","r")
f2=open("out.csv","w")
for line in f1:
    items=line.strip().split(",")
    tot=int(int(items[1])+int(items[2]))
    print(items[0],items[1],items[2],tot,file=f2)
f1.close()
f2.close() 

Question
  1. Describe how you would determine whether a given positive integer is odd or even
  2. Develop a flowchart to represent an algorithm, based on the method suggested in (i) above, to decide whether a given positive integer is odd or even.
  3. Convert the flowchart you have obtained for the above (ii) into a pseudo code.
  4. Convert the pseudo code obtained in (iii) into a Python program.

Answers
i) 
Divide the given integer by 2 and get the remainder. 
If the remainder is 0 then the number is even otherwise the number is odd. 
(note: if we divide any number by 2 then remainder will be 0 or 1 only)




ii)
Flowchart to find odd or even
iii)
Pseudo code
Start
input N
R=N%2      #divide the number by 2 and get the remainder to R
if (R=1) then
	display  "the number is odd"
else
	display "The number is even"
endif
End




iv)
#Python Program
N=int(input("Enter a positive Integer?"))
R=N %2
if (R==1):
    print("The number is odd")
else:
    print("The number is even")


Sample Output
Enter a positive Integer?101
The number is odd

Enter a positive Integer?27
The number is odd 



Tuesday, November 23, 2021

Function to print whether a number is positive or negative and odd or even

Exercise to Learn selections in programming

Write a function to return a string to print whether a given number is positive or negative and odd or even.

Python Function to print whether a given number is positive or negative and odd or even

Program
#function
def PosnegAndOddEven(n):  
    if (n==0):
        x="zero"
    elif((n%2)==1):
        x="integer is odd and "
    else:
        x="integer is even and"
       
    if (n==0):
        x=x
    elif(n>0):
        x=x+ " Positive"
    else:
        x=x + " Negative"
        
    return x

#main
print(PosnegAndOddEven(0))
print(PosnegAndOddEven(2))
print(PosnegAndOddEven(-5))


Output
zero
integer is even and Positive
integer is odd and  Negative


Thursday, November 18, 2021

Learn Internal DOS Command

Learn Frequently Used DOS Internal Commands

DOS Command are used to interact with the operating system. There are many commands available as internal and external to do many tasks/operations. The users who use windows OS can type cmd in the task bar to get command prompt where They can type commands to interact with OS.

C:\>cmd

MS-DOS was the first operating system designed and released by Microsoft for IBM, IBM compatible personal computers during the 1980s. Even today these commands are ease many tasks in Windows Environment too. There are two types of command available. 

  • Internal Command: Internal commands are built-in commands of MS-DOS, stored in the command interpreter "COMMAND.COM". These commands reside in memory if the system is at prompt "C:\>"
  • External Command: External commands are separate program (.com, .exe) files that reside in the DOS directory. eg: format.com, tree.com, attrib.exe etc.

This blog will help to understand some frequently used internal DOS command with examples.

Clear the screen

C:\>CLS
Clears the screen.

Displays or sets the date

C:\>date
The current date is: Wed 11/17/2021
Enter the new date: (mm-dd-yy)
Displays or sets the date.

Displays or sets the Time

C:\>time
The current time is: 23:59:29.08
Enter the new time:

Create new Directory

MD [drive:]path

c:\>md Pascal
create a folder called 'Pascal' in 'C:\'

c:\>md temp
create a folder called 'temp' in 'C:\'

c:\Pascal>md program
create a subfolder 'program' in the folder 'C:\Pascal'

Change the current folder

CD [/D] [drive:][path]

C:\>cd Pascal
The above command will change the current root to Pascal folder
c:\Pascal>cd program
The above command will change the current 'C:\Pascal' folder to subfolder 'C:\Pascal\program'

c:\Pascal\Program>cd..
the above command will change the current subfolder to parent folder Pascal
C:\Pascal>

C:\Pascal\Program>Cd\
the above command will change the current to root of c.
C:\

Remove a folder

RD [/S] [/Q] [drive:]path

c:\Pascal>RD program
The above command will remove the subfolder program in the Pascal folder
(The program folder should be empty and instruction should be given from parent folder of program)

Display Files and Folders

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
Display the list of files and subdirectories in a directory.

C:\>dir /P
Display by page pause

C:\dir /W
Display as wide list format

C:\>dir /OD
Display by date order

C:\>dir /OS
Display by file size

C:\>dir /OE
Display by Extensions

C:\>dir /AR
Display read only files

C:\>dir /AH
Display hidden files

C:\>dir /B
Display as bare format

Using wild card Operators ('*' for all and '?' for unknown character) with DIR command

C:\>dir *.txt
Display all the files with the extension 'txt' in c:\

C:\>dir A*.*
Display all the files which have 'A' as first character of its file name in C:\.

C:\>dir *.p*
Display all the files which have 'p' as first character of the extension in C:\

C:\>dir ?A*.*
Display all the files which have 'A' as second character  its filename in C:\

Create a Text files

c:\>copy con abc.txt
This is the content of this file.

<ctrl>+Z
The above command will create a file called 'abc.txt' and its content will be 'This is the content of this file.'.  <ctrl>+Z will be used to end the input and save the files.

Display the content of a text file

C:\>type abc.txt
The above command will display the content of the text file abc.txt

Rename a file
REN [drive:][path] oldname newname

C:\>ren abc.txt xyz.txt
The above command will rename the abc.txt file as xyz.txt

Delete a file/ files
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

C:\>del xyz.txt
The above command will delete a file xyz.txt

We can use wild card operators with del command too.

C:\>del *.txt
The above command will delete all the files with the extension 'txt'

C:\>del A*.*
The above command will delete all the files which first character of filename is 'A'

Copy a file/ files
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
     [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

C:\>copy pqr.txt c:\temp
Copy the pqr.txt file from the c:\ to the destination folder c:\temp

C:\>copy *.* c:\temp
Copy all the files form 'c:\' to the folder 'c:\temp'

c:\program>copy *.pas c:\Pascal
Copy all the files from 'c:\program' folder to 'c:\pascal' folder

C:\>

Change Prompt Color

COLOR [--]
-- TWO hex digits, the first corresponds to the background; the second the foreground.

Each Hex digit define below colors.
0 = Black       8 = Gray
1 = Blue        9 = Light Blue
2 = Green       A = Light Green
3 = Aqua        B = Light Aqua
4 = Red         C = Light Red
5 = Purple      D = Light Purple
6 = Yellow      E = Light Yellow

C:\>color 4
Change the prompt with foreground color red.

C:\>color 61
Change the prompt with foreground color yellow and background blue.


DOS Exercise

Question
You have a folder called programs in 'c:\' (root) which contains files of  Java, Pascal programs. Do the below tasks using DOS Commands.

  • Change the Directory to 'c:\programs'
  • List and Check all the files which are available in 'c:\programs' folder
  • Create two separate subfolders called 'Java' and 'Pascal' in the 'Programs' folder
  • Copy all the java program files into 'Java' subfolder
  • Copy all the pascal programs into 'Pascal' subfolder
  • Delete all the files in the programs folder.

Answer

C:\>cd programs

C:\programs>dir
 Volume in drive C is Windows
 Volume Serial Number is 6668-1FA8

 Directory of C:\programs

11/18/2021  12:24 AM    <DIR>          .
11/18/2021  12:24 AM    <DIR>          ..
11/18/2021  12:23 AM                 7 circle.java
11/18/2021  12:23 AM                 4 class.java
11/18/2021  12:23 AM                 4 ex1.java
11/18/2021  12:22 AM                 4 ex1.pas
11/18/2021  12:23 AM                 6 ex2.java
11/18/2021  12:22 AM                 4 ex2.pas
11/18/2021  12:22 AM                 6 ex3.pas
11/18/2021  12:22 AM                 5 main.pas
11/18/2021  12:24 AM                 4 rect.java
11/18/2021  12:22 AM                 7 test.pas
              10 File(s)             51 bytes
               2 Dir(s)  157,863,772,160 bytes free

C:\programs>cd..

C:\>cd programs

C:\programs>md Pascal

C:\programs>md Java

C:\programs>copy *.pas c:\programs\Pascal
ex1.pas
ex2.pas
ex3.pas
main.pas
test.pas
        5 file(s) copied.

C:\programs>copy *.java c:\programs\java
circle.java
class.java
ex1.java
ex2.java
rect.java
        5 file(s) copied.

C:\programs>del *.*
C:\programs\*.*, Are you sure (Y/N)? y

C:\programs>dir
 Volume in drive C is Windows
 Volume Serial Number is 6668-1FA8

 Directory of C:\programs

11/18/2021  12:27 AM    <DIR>          .
11/18/2021  12:27 AM    <DIR>          ..
11/18/2021  12:26 AM    <DIR>          Java
11/18/2021  12:26 AM    <DIR>          Pascal
               0 File(s)              0 bytes
               4 Dir(s)  157,863,612,416 bytes free

C:\programs>cd java

C:\programs\Java>dir
 Volume in drive C is Windows
 Volume Serial Number is 6668-1FA8

 Directory of C:\programs\Java

11/18/2021  12:26 AM    <DIR>          .
11/18/2021  12:26 AM    <DIR>          ..
11/18/2021  12:23 AM                 7 circle.java
11/18/2021  12:23 AM                 4 class.java
11/18/2021  12:23 AM                 4 ex1.java
11/18/2021  12:23 AM                 6 ex2.java
11/18/2021  12:24 AM                 4 rect.java
               5 File(s)             25 bytes
               2 Dir(s)  157,863,612,416 bytes free

C:\programs\Java>cd..

C:\programs>tree
Folder PATH listing for volume Windows
Volume serial number is 6668-1FA8
C:.
├───Java
└───Pascal

C:\programs>