Download Govt Degree college for boys North Karachi

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Entity–attribute–value model wikipedia , lookup

Clusterpoint wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Database model wikipedia , lookup

Transcript
Pakistan Shipowners Govt. College
Preliminary Examination 2017 ANSWERS
Subject:- Computer Science Paper II(Science General)
Time allowed 2:45 hours
Max. Marks 60
General instructions”Section B : It consist of 18 short answer questions out of which 12 questions to be
answered . Answer should not exceed 3-6 lines.
Section C : It comprises of 3 detailed –answer questions out of which 2 questions
are to be answered .
Section
B
(36 Marks)
2. i) What is case sensitivity as far as c-language programming is concern.
Case sensitivity means same alphabet written in capital letter form and small letters form
will be considered different.
e.g. ‘a’ and ‘A’ will be treated separately.
Similarly “Shipowner” and “shipowner” will be considered different.
Also “variable1” and “Variable1” both will be considered different.
So, one must have to be careful while writing in C-language programming, because a
little change in single alphabet can affect the programming.
ii) What is the purpose of Form in Databases.
Form basically are the organized, secure and standard way of taking input from the user.
They are used in databases to provide the ease of use to the user. Inputting data in tables
directly looks odd and is insecure, so to provide nice looking console in gentle way with
filters to take the input from users, forms are used. One Form can take the input of
several tables, as well.
iii) Write down the structure of C-Language.
Structure of C/C++
Element1
Preprocessor
Directive
Element2
Public/Global
variable/functions
declaration.
Element3
Element4
Main function
Body of main
function
#inlcude <stdio.h>
#include <conio.h>
void hilal(void);
int Ali(void);
void kashif_1(char,int);
char Husain_Gul(int,char);
void main(void) / char main(int)
{
clrscr();
Element5
Definition of
Element2 declared
functions
printf(“Body of main function”);
getch();
}
void hilal(void)
{ clrscr();}
int Ali(void)
{return 957;}
void kashif_1(char c,int i)
{printf(“C= %c, i= %d”,c,i);}
char Husain_Gul(int ii,char cc)
{printf(“C= %c, i= %d”,c,i);
return ‘t’;}
iv) When there is a need of one to many relationship in data base.
In relational databases, a one-to-many relationship occurs when a parent record in one
table can potentially reference several child records in another table. In a one-to-many
relationship, the parent is not required to have child records; therefore, the one-to-many
relationship allows zero child records, a single child record or multiple child records. The
important thing is that the child cannot have more than one parent record.
The opposite of a one-to-many relationship is a many-to-many relationship, in which a
child record can link back to several parent records.
v) Write equivalent C-Statements of any two.
z=(𝑥 + 𝑦)2 +(𝑥 2 -𝑦 2 )
𝑦=
−𝑏±√𝑏 2 −4𝑎𝑐
2𝑎
𝑐 2 = 𝑎 2 + b2
z=pow((x+y),2)+(pow(x,2)-pow(y,2));
y= -b ( abs( sqrt(pow(b,2)-(4*a*c)) ))/(2*a);
pow(c,2)=(pow(a,2)+pow(b,2));
vi) If s=1 b=2 then define the purpose of the following code.
b = s+b;
s = b – s;
b= b – s;
Exchanging(Swapping) values of variable ‘s’ and variable ‘b’.
vii) Write the c-program to print following statements on screen.
This is line no 1
You are watching C language program
And this is the last line.
#include <stdio.h>
#include <conio.h>
void main(void)
{
clrscr();printf(“This is line no 1”);
printf(“\nYou are watching C language program);
printf(“\nAnd this is the last line”);getch();
}
viii) what is the purpose of mathematical operators “ / ” and “ * ” in C-Language.
Operator ‘/’ is called slash and is the representation of division sign of Mathematics. It is
used in C-language to perform mathematical operation of division. Suppose if we want to
divide 10 by 2 then we will write 10/2 is C-language it will produce the result 5.
Operator ‘*’ is called steric and in C-language it is a mathematical operator for
multiplication. Suppose if we want to multiple 5 with 2 then we will write 5*2 is CLanguage it will produce the result 10.
ix) What is primary Key in Database?
Primary Key is a special type of field in a record through which a record can be
identified. Primary key in other words is the attribute that is unique for each and every
record like CNIC, Enrollment No, Passport No., B-Form No. etc.
Primary key cannot be null, it cannot be duplicate. It may be used as foreign key to other
table if needed.
x) What are calculated fields in Database?
Calculated fields are the fields that are evaluated at runtime in database queries. Take an
example of age which increases day by day so to calculate it at runtime with the help of
already existed database field data of birth calculated field is used, where formula for
todate() excluding the dateofbirth() returns the result of age.Similarly,
Total/Percentage/Grade of students are calculated at runtime rather than saving them in
database table. Sum of subjects are calculated to show them as total, with the help of
formula percentage is calculated and then the grade.
xi) Define any four C-Language built-in functions or Statements
printf(); :- It is an output function, used for printing formatted output of all data types
available in C-language. Format specifier %s,%c,%d,%lf,%lf etc are used to get the
desired format of the output.
Example: printf(“%d”,total); , printf(“This is a message in string Format”); etc.
getch(); :- It is an input function, used for taking input of a character without showing it.
Example: char charVariable; charVariable=getch();
getche(); :- It is an input function, used for taking input of a character, on the screen.
Example: char charVariable; charVariable=getche();
scanf(); :- It is an input function, used for taking formatted input of all data types
including char,int,float,double,long etc.
Example:
int subject1, float percentage; char ch;
scanf(“%d”,&subject1); scanf(“%c”,&ch); scanf(“%f”,&percentage);
xii) Write equivalent while loop in C-Langauge.
int num=1;
do{
printf(“%d”,num);
}while(num<=100);
EQUIVALENT CODE:
int num=1;
while(num<=100)
{printf(“%d”,num);}
xiii) Define Switch case statement with example.
Switch case statement is used in C-language programming to check the equality of a
variable. Particular variable is passed to switch block and then its case is checked in the
case block. If equality is matched then that particular block is executed. To avoid
execution of case block after the equality block, “break” statement is used. If no case is
matched then default block is executed.
Example:
switch ( <variable> ) {
case this-value:
Code to execute if <variable> == this-value
break;
case that-value:
Code to execute if <variable> == that-value
break;
...
default:
Code to execute if <variable> does not equal the value following any
of the cases
break;
}
xiv) What is the difference between increment operators prefix “++num” and postfix
“num++”.
“++num” statement actually first increments the variable “num” and then perform any
other operation of variable “num”, whereas “num++” first perform the operation on
variable “num” and then increments the variable “num”.
Example
for(num=1;num<10;++num) printf(“%d”,num); // here initially 2 will be printed.
for(num=1;num<10;num++) printf(“%d”,num); // here initially 1 will be printed.
xv) What is Table in Database?
Table:
Collection of interrelated records is called table. In other words table is a set of data
elements (values) using a model of vertical columns (identifiable by name) and horizontal
rows, the cell being the unit where a row and column intersect. A table has a specified
number of columns, but can have any number of rows.
xvi) Define any four data types used in MS-Access.
Four data types from the data types used in MS-Access are:
1-AutoNumber, 2-Number, 3-Text, 4-Date/Time
1-AutoNumber: This data type generates number automatically for the field. The default
size of the data type is four bytes which is good enough to store the values upto 4 billion.
2-Number: This data type holds the data of numeric type but data is input manually in the
field. By default it range from -2,147,483,648 to +2,147,483,647. Storage capacity is
four bytes.
3-Text: This data type holds the data of alphanumeric type, both numbers and strings like
addresses, car number, numbers not used for calculations can be stored manually in the
field.
4-Date/Time: This data type only holds the data, related to date and time, specific
calculations for evaluation of date and time can be performed on this type of data.
xvii) Define relationship in Database.
A relationship, in the context of databases, is a situation that exists between two relational
database tables when one table has a foreign key that references the primary key of the
other table. Relationships allow relational databases to split and store data in different
tables, while linking disparate data items.
xviii) Write different file opening modes in C-Language.
Mode
Meaning
r+
Reading + Writing
w+
Reading + Writing
Reading +
Appending
a+
r
Reading
w
a
Writing
Appending
fopen Returns if FILEExists
New data is written at the beginning overwriting existing
data
Over write on Existing
New data is appended at the end of file
New data is written at the beginning overwriting existing
data
Over write on Existing
New data is appended at the end of file
SECTION-C
DETAILED-ANSWER QUESTIONS
Marks 24
3.a) Define integer data type used in c-language, how it is declared, what is its size in
bytes, capacity to hold data, which format specifiers are used to display it etc.
Integer data type:
Integer data type is used in c-language for holding data of integer numbers. It is declared
with int <variable name> i.e int number, its size is two bytes withc can hold the data from
-32768 to +32767 in signed category and from 0-65535 in unsigned category. “%d” for
signed and “%u” for the unsigned, are the format specifiers used for displaying the
integer data types.
b. Write a program to display table of seven using any loop.
#include <stdio.h>
#include <conio.h>
void main(void)
{
int multiple;
clrscr();for(multiple=1;multiple<=20;multiple++)
{
Printf(“7 * %d = %d”,multiple,(7*multiple));
}
getch();
}
// wait till any key is pressed
c. What is referential integrity?
Referential integrity is a relational database concept, which states that table relationships
must always be consistent. In other words, any foreign key field must agree with the
primary key that is referenced by the foreign key.
4.a) Define relational Operators used in C-Language
Checks if the values of two operands are equal or not. If yes, then the
==
condition becomes true.
Checks if the values of two operands are equal or not. If values are not
!=
equal then the condition becomes true.
Checks if the value of left operand is greater than the value of right
>
operand. If yes, then the condition becomes true.
Checks if the value of left operand is less than the value of right
<
operand. If yes, then the condition becomes true.
Checks if the value of left operand is greater than or equal to the value
>=
of right operand. If yes, then the condition becomes true.
Checks if the value of left operand is less than or equal to the value of
<=
right operand. If yes, then the condition becomes true.
(A == B) is
not true.
(A != B) is
true.
(A > B) is
not true.
(A < B) is
true.
(A >= B) is
not true.
(A <= B) is
true.
b) Define float data type used in c-language, how it is declared, what is its size in
bytes, capacity to hold data, which format specifiers are used to display it etc.
Float data type is used in c-language for holding data of real numbers. It is declared with
float <variable name> i.e float realnumber, its size is four bytes which can hold the data
from -3.4E+38 to +3.4E+38 about 7 decimal digits accuracy.
“%f” is the format specifiers used for displaying the float data types.
c) Define date data type used in MS-Access.
Date/Time: This data type only holds data, related to date and time, specific calculations
for evaluation of date and time can be performed on this type of data. Calculating age,
length of service, number of years, days of years etc. are pretty much easy using this date
type field.
5.a) Debug the following C-Language Program.
#include <stdio.h>
#include <conio.h>
Void main(void)
// 1.Void ‘V’ is capital
{
clrscr();
printf(“\n\t This is C-Language Program”):///2.‘:’colon is written instead of semi-colon
// ‘;’
getcha();
// 3.getcha(); isnot any function in c-langauge
]
// 4.‘]’ square bracket is used instead of right curly bracket ‘}’
5.b) what will be output of following code segment.
#include <stdio.h>
void main(void)
{
for(int num=2;num<=200;num+=2)
{printf(“%d”,num);}
}
5.c) Define the term “record” in Database.